List Box & Rich Edit box [modified]
-
Hello all, I have List Box and rich edit box in my Dialog IDC_SLIST & IDC_FILECONT List Box contains the text file names , When the user double click on the list box that file content should be displayed in the rich edit box. Can u please tell me what all the changes I have to make and how to do the double click event in Api application ??
case WM_COMMAND: switch(LOWORD(wParam)) { case LBN_DBLCLK: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); int iCurSel =::SendMessage(hwndListBox,LB_GETCURSEL,0,0); TCHAR FName[25]; SendMessage(hwndListBox,LB_GETTEXT,(WPARAM)iCurSel,(LPARAM)FName); CStdioFile file(FName, CFile::modeRead); DWORD dwSize = file.GetLength(); char *pBuffer = new char[dwSize + 1]; UINT uRead = file.Read(pBuffer, dwSize); pBuffer[uRead] = '\0'; file.Close(); HWND hwndRichEdit = GetDlgItem(hwnd, IDC_FILECONT); SendMessage(hwndRichEdit,EM_SETTEXTMODE, pBuffer,0); delete [] pBuffer; } Thanking you, Suresh HC
-- modified at 5:37 Friday 16th February, 2007 -
Hello all, I have List Box and rich edit box in my Dialog IDC_SLIST & IDC_FILECONT List Box contains the text file names , When the user double click on the list box that file content should be displayed in the rich edit box. Can u please tell me what all the changes I have to make and how to do the double click event in Api application ??
case WM_COMMAND: switch(LOWORD(wParam)) { case LBN_DBLCLK: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); int iCurSel =::SendMessage(hwndListBox,LB_GETCURSEL,0,0); TCHAR FName[25]; SendMessage(hwndListBox,LB_GETTEXT,(WPARAM)iCurSel,(LPARAM)FName); CStdioFile file(FName, CFile::modeRead); DWORD dwSize = file.GetLength(); char *pBuffer = new char[dwSize + 1]; UINT uRead = file.Read(pBuffer, dwSize); pBuffer[uRead] = '\0'; file.Close(); HWND hwndRichEdit = GetDlgItem(hwnd, IDC_FILECONT); SendMessage(hwndRichEdit,EM_SETTEXTMODE, pBuffer,0); delete [] pBuffer; } Thanking you, Suresh HC
-- modified at 5:37 Friday 16th February, 2007Suresh H wrote:
SendMessage(hwndRichEdit,EM_SETTEXTMODE, pBuffer,0);
Use ,
::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)pBuffer);
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Suresh H wrote:
SendMessage(hwndRichEdit,EM_SETTEXTMODE, pBuffer,0);
Use ,
::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)pBuffer);
Prasad Notifier using ATL | Operator new[],delete[][^]
Hi Prasad, Thank you very much for the response. I tried with this code but no response list box double click event is not working.
case LBN_DBLCLK: { MessageBox(hwnd, "DB click!","DB click event", MB_ICONEXCLAMATION | MB_OK); } break;
and also I am not able to use CFile , this works in MFC but I am using win 32 api, what changes I have to make ???CStdioFile file(FName, CFile::modeRead); DWORD dwSize = file.GetLength(); char *pBuffer = new char[dwSize + 1]; UINT uRead = file.Read(pBuffer, dwSize); pBuffer[uRead] = '\0'; file.Close();
-
Hi Prasad, Thank you very much for the response. I tried with this code but no response list box double click event is not working.
case LBN_DBLCLK: { MessageBox(hwnd, "DB click!","DB click event", MB_ICONEXCLAMATION | MB_OK); } break;
and also I am not able to use CFile , this works in MFC but I am using win 32 api, what changes I have to make ???CStdioFile file(FName, CFile::modeRead); DWORD dwSize = file.GetLength(); char *pBuffer = new char[dwSize + 1]; UINT uRead = file.Read(pBuffer, dwSize); pBuffer[uRead] = '\0'; file.Close();
Do you have LBS_NOTIFY on your listbox? From the MSDN Only a list box that has the LBS_NOTIFY style will send this message.
WhiteSky
-
Do you have LBS_NOTIFY on your listbox? From the MSDN Only a list box that has the LBS_NOTIFY style will send this message.
WhiteSky
-
Insert
LBS_NOTIFY
when create listboxhList=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hWnd,(HMENU)IDC_SLIST,hInst,0);
WhiteSky
-
Insert
LBS_NOTIFY
when create listboxhList=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hWnd,(HMENU)IDC_SLIST,hInst,0);
WhiteSky
Hi whiteSky, I did that in the
BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
i am getting error error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [8]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. -
Hi whiteSky, I did that in the
BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
i am getting error error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [8]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.I wanted to said insert LBS_NOTIFY when create your listbox
WhiteSky
-
I wanted to said insert LBS_NOTIFY when create your listbox
WhiteSky
-
Hi whiteSky, I did that in the
BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
i am getting error error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [8]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.Suresh H wrote:
hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Use
CreateWindow
instead ofCreateWindowW
. You are trying to useUNICODE
version in Non -UNICODE application.Prasad Notifier using ATL | Operator new[],delete[][^]
-
I wanted to said insert LBS_NOTIFY when create your listbox
WhiteSky
He has created list box, shown in above post.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Suresh H wrote:
hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Use
CreateWindow
instead ofCreateWindowW
. You are trying to useUNICODE
version in Non -UNICODE application.Prasad Notifier using ATL | Operator new[],delete[][^]
Hi prasad, again i am getting error..
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
error :- rror C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. -
Suresh H wrote:
hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Use
CreateWindow
instead ofCreateWindowW
. You are trying to useUNICODE
version in Non -UNICODE application.Prasad Notifier using ATL | Operator new[],delete[][^]
-
Hi prasad, again i am getting error..
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
error :- rror C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.One question
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST);
what is it? before CreateWindow
WhiteSky
-
Hi prasad, again i am getting error..
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
error :- rror C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.Suresh H wrote:
hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Here, instead of handle you need to pass handle to instance. Pass instance that you will get through
WinMain
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
One question
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST);
what is it? before CreateWindow
WhiteSky
-
Suresh H wrote:
hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Here, instead of handle you need to pass handle to instance. Pass instance that you will get through
WinMain
.Prasad Notifier using ATL | Operator new[],delete[][^]
BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { // HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwnd=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwnd,0); again error :- error C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.
-
So do you have two listbox on your project?
WhiteSky
-
BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { // HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwnd=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwnd,0); again error :- error C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.
You have two hwnds on CreateWindow? wheres HINSTANCE
WhiteSky
-
Prasad what I am trying to do is List box contains a list of file names , when we select any item in the list box that file contains should get added to rich edit box. So is there any way I can do that ??? without double click trouble ???
Suresh H wrote:
List box contains a list of file names , when we select any item in the list box that file contains should get added to rich edit box.
You can handle list box double click in following way,
case WM_COMMAND:
switch(LOWORD(wParam))
case IDC_LIST1:
if (HIWORD(wParam) == LBN_DBLCLK)
{
//double clicked
}
break;Prasad Notifier using ATL | Operator new[],delete[][^]