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?
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?
[C++]
IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
2nd compiler: g++ (GCC 3.4.3/4.0.0)
3rd compiler: Borland 5.5
[C#]
IDE: Microsoft Visual C# Express 2005
2nd IDE: SharpDevelop
2nd compiler: csc in Command Prompt
.NET Framework: 2.0
[PHP]
Core: 5.1.0 beta 3
IDE: PHPEdit
2nd IDE: Notepad
Favourite extensions: exif,gd2,mysql
Favourite PEAR packages: DB, XML_RSS, ID3
Favourite databases: SQLite, MySQL
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
Last edited by Stack Overflow; 02-12-2005 at 11:28 AM.
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
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); }
[C++]
IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
2nd compiler: g++ (GCC 3.4.3/4.0.0)
3rd compiler: Borland 5.5
[C#]
IDE: Microsoft Visual C# Express 2005
2nd IDE: SharpDevelop
2nd compiler: csc in Command Prompt
.NET Framework: 2.0
[PHP]
Core: 5.1.0 beta 3
IDE: PHPEdit
2nd IDE: Notepad
Favourite extensions: exif,gd2,mysql
Favourite PEAR packages: DB, XML_RSS, ID3
Favourite databases: SQLite, MySQL
char *buf; either needs to be:
orCode:char buf[512];
Code:char *buf=new char[512];
thanks
[C++]
IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
2nd compiler: g++ (GCC 3.4.3/4.0.0)
3rd compiler: Borland 5.5
[C#]
IDE: Microsoft Visual C# Express 2005
2nd IDE: SharpDevelop
2nd compiler: csc in Command Prompt
.NET Framework: 2.0
[PHP]
Core: 5.1.0 beta 3
IDE: PHPEdit
2nd IDE: Notepad
Favourite extensions: exif,gd2,mysql
Favourite PEAR packages: DB, XML_RSS, ID3
Favourite databases: SQLite, MySQL
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.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.