Drop-down list verschwindet nicht
-
Ich hab das Problem, dass ich für eine Anwendung eine Drop-down list (Combo Box mit nicht editierbaren Einträgen) verwenden möchte (Auswählen einer Mglk. aus vielen) diese aber beim Versuch einen Eintrag auszuwählen die weitere Abarbeitung des Programmes blockiert.
* Das Hauptfenster wird erzeugt und richtig dargestellt -> OK
* Die Controls werden richtig dargestellt und initialisiert -> OK
* Die Window Procedure wird bei Interaktion mit den Childs angesprungen -> OK
* Die richtige Funktion wird je nach angesprochenem Child aufgerufen (Wenn die WM_COMMAND Sektion wieder aktiviert wird)
* Alle Childs reagieren wie gewollt, bis auf die drop-down list
* Es werden nur Standard Controls verwendet daher keine WM_PAINT Verarbeitung -> OK?Der grundsätzliche Ablauf wurde einem Code Export von ResEdit (Windows) entnommen und dann modifiziert.
Hier die relevanten Programmteile:
1.) Initialisierung des Hautfensters:
WNDCLASSEX wcex; //ZeroMemory(&wcex, sizeof wcex); wcex.cbSize = sizeof wcex; wcex.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); wcex.lpszMenuName = NULL; wcex.style = 0;//CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc;//DefWindowProc;// /* Die WndProc, hInstance, g_szClassName, werden bei der Erstellung des Klassenobjektes für dieses Fenster initialisiert*/ wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(0, (LPCTSTR)IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.lpszClassName = g_szClassName; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if (!RegisterClassEx(&wcex)){ MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } try{ CreateFont(-11, 0, 0, 0, 0, FALSE, FALSE, FALSE, 1, 0, 0, 0, 0, ("MS Shell Dlg")); hWndInputSett = SaveCreateWindowEx(0,//WS_EX_CLIENTEDGE, g_szClassName, "Input Settings", WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 450, 392, HWND_DESKTOP, NULL, hInstance, NULL ); } catch(LPCTSTR strWin){ MessageBox(NULL, "Window Creation Failed!", strWin, MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hWndInputSett, SW_SHOWNORMAL); UpdateWindow(hWndInputSett);
2.) SaveCreateWindowEx:
HWND WINAPI SaveCreateWindowEx( DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam ){ HWND hwnd = CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); if(NULL == hwnd) { throw(lpWindowName); } return hwnd; }
3.)Message Loop
MSG msg; HWND hwnd ; while(GetMessage(&msg, hwnd = DiffusionFitDialogLoc.getHWNDInputSett(), 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); }
4.) Callback Function
(Wrapper)LRESULT CALLBACK WrapHandleMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return DiffusionFitDialogPtr->HandleMessages(hwnd, uMsg, wParam, lParam); }
(eigentliche wndproc)
LRESULT CALLBACK DiffusionFitDialogT::HandleMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { //assert(hwnd == hInstance); //hWnd = hwnd; //Handle messages //if (hwnd == hWndInputSett){ switch(uMsg) { case WM_CREATE: //hWndInputSett = hwnd; try { CreateChildWindows(hwnd); } catch(LPCTSTR strWin){ MessageBox(NULL, "Window Creation Failed!", strWin, MB_ICONEXCLAMATION | MB_OK); PostQuitMessage(0); return 0; } InitValuesOfControls(hwnd); return 0; case WM_COMMAND: /** * * Get Destination Object for Message * */ //ReactOnControls(hwnd, wParam, lParam); //return 0; break; case WM_DESTROY: { PostQuitMessage(0); return 0; } default: return DefWindowProc (hwnd, uMsg, wParam, lParam); } //} return DefWindowProc (hwnd, uMsg, wParam, lParam);//return TRUE; }
5.) Die Initialisierung der Controls
int DiffusionFitDialogT::CreateChildWindows(HWND hWndInputSett){ SaveCreateWindowEx(0, WC_BUTTON, ("Input Parameters for Diffusion Fit"), WS_VISIBLE | WS_CHILD | 0x00000007, 9, 16, 405, 284, hWndInputSett, (HMENU)1, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL, 345, 33, 38, 24, hWndInputSett, (HMENU)IDEB_MUAINIT, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_COMBOBOX, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, 186, 167, 197, 114, hWndInputSett, (HMENU)IDCB_DIFFMETHOD, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_STATIC, ("Start Value for µa in 1/mm"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 53, 41, 144, 13, hWndInputSett, (HMENU)4, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_STATIC, ("Diffusion Method"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 53, 172, 116, 18, hWndInputSett, (HMENU)5, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_BUTTON, ("OK"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 30, 325, 98, 23, hWndInputSett, (HMENU)IDB_OK, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_BUTTON, ("Cancel"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 147, 325, 105, 23, hWndInputSett, (HMENU)IDB_CANCEL, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_STATIC, ("Start Value for µs' in 1/mm"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 53, 73, 126, 13, hWndInputSett, (HMENU)6, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL, 345, 65, 38, 24, hWndInputSett, (HMENU)IDEB_MUSPINIT, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_STATIC, ("Refractive Index"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 53, 106, 80, 13, hWndInputSett, (HMENU)8, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL, 345, 98, 38, 24, hWndInputSett, (HMENU)IDEB_REFRACTIVEINDEX, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_STATIC, ("Integration Method"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 53, 219, 90, 13, hWndInputSett, (HMENU)2, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_COMBOBOX, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, 186, 215, 197, 114, hWndInputSett, (HMENU)IDCB_INTEGRATIONMETHOD, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_STATIC, ("Variable Refractive Index"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 53, 138, 120, 13, hWndInputSett, (HMENU)3, DiffusionFitDialogT::hInstance, 0); SaveCreateWindowEx(0, WC_BUTTON, (""), WS_VISIBLE | WS_CHILD | WS_TABSTOP | 0x00000003, 368, 138, 15, 13, hWndInputSett, (HMENU)IDC_VARREFRACTIVEINDEX, DiffusionFitDialogT::hInstance, 0); return 0;
}
-
Versuch mal das:
MSG msg; HWND hwnd ; while(GetMessage(&msg, 0, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); }
So müsste es klappen.
-
Super, vielen Dank! Es geht.
Ist mir zwar auch nach Lesen von
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644936(v=vs.85).aspx
nicht klar warum, aber Hauptsache erstmal dass es geht.Ich hatte das so verstanden, dass HWND das Handle zu meinem Hauptfenster sein muss, also das Fenster welches die ganzen Controls enthält.
-
Nein. Ganz und gar nicht. Aber das steht doch in der Doku und in jedem Tutorial im Netz.
Es liest dann nur die Nachrichten zu diesem Fenster.
D.h. auch Nachrichten an Kindfenster werden nicht übertragen. (D.h. nicht, dass SendMessage nicht funktioniert, nicht jede Nachricht geht ja durch die Nachrichtenschleife).
Da die Combobox aber ein Popup Fenster hat, dass nicht mal ein Kind Deines Elternfensters ist, bekommt dieses niemals die Nachrichten, die es z.B. per PostMessage bekommt.