I have small problem...I have a listbox in a dialog, and I managed to control double clicks - but how can I get the value of string that was double-clicked?
Printable View
I have small problem...I have a listbox in a dialog, and I managed to control double clicks - but how can I get the value of string that was double-clicked?
Hello,
Possibly by using SetDlgItemMessage() And LB_GETCURSEL, LB_GETTEXT options. For example:Where IDC_LIST represents your ListBox.Code:int sel;
sel = SendDlgItemMessage( hWnd, IDC_LIST, LB_GETCURSEL, 0, 0 );
SendDlgItemMessage( hWnd, IDC_LIST, LB_GETTEXT, sel, (LPARAM)selection );
- Stack Overflow
It just doesn't work (well, it works but it fills the buffer with some strange text...) :(
Code:
Code:
char *buf;
int sel;
if(HIWORD(wParam) == LBN_DBLCLK)
{
sel = SendDlgItemMessage(hwnd, IDC_LST1, LB_GETCURSEL, 0, 0);
SendDlgItemMessage(hwnd, IDC_LST1, LB_GETTEXT, sel, (LPARAM)buf);
MessageBox(hwnd, buf, "Nekaj", MB_OK | MB_ICONINFORMATION);
}
char *buf; either needs to be:
orCode:char buf[512];
Code:char *buf=new char[512];
thanks ;)
You need to allocate memory for the LB_GETTEXT message to use:If you know the maximum length of any item in the listbox in question then use that value as SOME_SUITABLE_SIZE. If you prefer to dynamically allocate memory for the buffer then LB_GETTEXTLEN will return the length of a listbox item which you can use to new or malloc a suitable sized buffer.Code:char buf[SOME_SUITABLE_SIZE];
int sel;
if(HIWORD(wParam) == LBN_DBLCLK)
{
sel = SendDlgItemMessage(hwnd, IDC_LST1, LB_GETCURSEL, 0, 0);
SendDlgItemMessage(hwnd, IDC_LST1, LB_GETTEXT, sel, (LPARAM)buf);
MessageBox(hwnd, buf, "Nekaj", MB_OK | MB_ICONINFORMATION);
}
edit: well biffed by jverkoey.