Listbox-Element - Doppelklick Message abfangen
-
In der WinMain Function erstelle ich unter anderem eine Listbox:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { //.... clientsCol = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "Liste", WS_DLGFRAME | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_DISABLENOSCROLL | LBS_SORT | LBS_NOTIFY, 0, // x 0, // y 250, // width mainWindow.bottom, // height hWnd, NULL, hInstance, NULL ); //.... }
In WndProc() versuche ich die Message abzufangen, ob ein Listelement einen Doppelklick erfahren hat.
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) { // .... case WM_COMMAND: switch(LOWORD(wParam)) { case ID_LIST: switch (HIWORD(wParam)) { case LBN_DBLCLK: MessageBox(NULL, "Test", "Test", NULL); break; } break; } break; // .... } return DefWindowProc(hWnd,iMsg,wParam,lParam); }
In einer resource.h definiere ich ID_LIST:
#define ID_LIST 50000
Ich weiß nun allerdings nicht, wie ich der Listbox die id ID_LIST übergeben kann, so dass case ID_LIST auch mal zutrifft. Muss ich die ID beim erstellen der Listbox übergeben? Also in der CreateWindowEx() Funktion?
Grüße
Nico
-
T!P-TOP schrieb:
Muss ich die ID beim erstellen der Listbox übergeben? Also in der CreateWindowEx() Funktion?
Ja, die ID als HMENU casten und als drittletzten Parameter übergeben.
-
Lies doch einfach die Doku:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspxDu musst den hMenu Wert dazu verwenden:
hMenu [in, optional]
Type: HMENUA handle to a menu, or specifies a child-window identifier, depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
-
Stehe nun beim nächsten Schritt an
Ich komme nicht an den Wert des ausgewählten Listelements.
case IDC_LIST: switch (HIWORD(wParam)) { case LBN_DBLCLK: { int iLBItem; char value[250]; iLBItem = SendMessage(foo, LB_GETCURSEL, 0, 0); if (iLBItem != LB_ERR) { SendMessage(foo, LB_GETITEMDATA, (WPARAM)iLBItem, 0); MessageBox(NULL, value, "Test", MB_ICONEXCLAMATION | MB_OK); } break; } } break;
Bei LB_GETITEMDATA soll lParam ja Null sein. Wie speicher ich nun den Rückgabewert in einer Variable ab? Folgendes schlägt fehl:
value = SendMessage(foo, LB_GETITEMDATA, (WPARAM)iLBItem, 0);
155 C:\Dev-Cpp\main.c incompatible types in assignment
LB_GETITEMDATA liefert doch nen String - wieso kann ich diesen nicht in einem char Array speichern
-
omfg, so kann man doch kein Array kopieren. Grundlagen dude...
Und was willst du mit LB_GETITEMDATA? "Gets the application-defined value associated with the specified list box item."
Du willst doch den Text der markierten Zeile?!
http://msdn.microsoft.com/en-us/library/windows/desktop/ff485967
LB_GETCURSEL und LB_GETTEXT
-
omfg, so kann man doch kein Array kopieren. Grundlagen dude...
Ich sag nur: ich komm aus der PHP-Welt
Klappt jetzt, danke.
-
T!P-TOP schrieb:
Ich sag nur: ich komm aus der PHP-Welt
Ach!
... und PHP Programmierer können weder Lesen noch Grundlagen lernen?
Vermutet hatte ich das schon manchmal, aber sicher bin ich mir bis heute darin noch nicht...