Frage zu Child Windows.
-
Hallo. Was ich versuche zu machen ist ein Dialog mit 2 Buttons zu erstellen, was auch funktioniert. Jedoch möchte ich jetzt wenn ich eins von den Buttons drücke, dass es ein Child window anzeigt sowas wie tabs halt, dass problem bei der sache ist das es Immer fehlschlägt den IDD_DIALOG2 zu erstellen, es funktioniert mit Popup window prima, aber keine lust darauf, will halt das beide als Child angezeigt werden. Ich hoffe das mir jemand helfen kann, danke schon mal.
#ifndef _INC_STDIO #include <stdio.h> #endif #ifndef _STRING_ #include <string> #endif #ifndef _WINDOWS_ #define _WIN32_WINNT 0x0502 #include <windows.h> #endif #include "resource.h" HWND gHwnd = 0; DWORD threadId = 0; DWORD opThread = 0; HANDLE hThread = 0; HANDLE hOption = 0; HINSTANCE MAIN; HWND Option = 0; HWND checkHwnd = 0; INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgProc2(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //----------------------------------------------------------------------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MAIN = hInstance; HWND hwnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, (LPARAM)hInstance); MSG Msg = {0}; while(GetMessage(&Msg, NULL, 0, 0) > 0) { if(!IsDialogMessage(hwnd, &Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } // Standard return return 0; } DWORD WINAPI OptionsDialog(LPVOID lParam) { gHwnd = CreateDialog(MAIN, MAKEINTRESOURCE(IDD_DIALOG2), NULL, DlgProc1); if(gHwnd == NULL) { MessageBox(NULL, "Window creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } MSG Msg = {0}; while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return 0; } DWORD WINAPI CheckDialog(LPVOID lParam) { checkHwnd = CreateDialog(MAIN, MAKEINTRESOURCE(IDD_DIALOG3), NULL, DlgProc2); if(gHwnd == NULL) { MessageBox(NULL, "Window creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } MSG Msg = {0}; while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return 0; } INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { hThread = CreateThread(0, 0, OptionsDialog, 0, 0, &threadId); hOption = CreateThread(0, 0, CheckDialog, 0, 0, &opThread); } break; case WM_COMMAND: { int button = LOWORD(wParam); switch (button) { // Exit case IDCANCEL: { PostQuitMessage(0); TerminateThread(hThread, 0); TerminateThread(hOption, 0); }break; case btnTest: { if(IsWindowVisible(checkHwnd)) { ShowWindow(checkHwnd, false); ShowWindow(Option, true); } else { ShowWindow(Option, true); } break; } case btnTest2: { if(IsWindowVisible(Option)) { ShowWindow(Option, false); ShowWindow(checkHwnd, true); } else { ShowWindow(checkHwnd, true); } break; } } } break; default: { // Message not handled return FALSE; } } // Message handled return TRUE; } INT_PTR CALLBACK DlgProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Handle the message switch(uMsg) { // Dialog initialize case WM_INITDIALOG: { Option = hWnd; } break; // Commands case WM_COMMAND: { int button = LOWORD(wParam); switch (button) { } } break; default: { // Message not handled return FALSE; } } // Message handled return TRUE; } INT_PTR CALLBACK DlgProc2(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Handle the message switch(uMsg) { // Dialog initialize case WM_INITDIALOG: { checkHwnd = hWnd; } break; // Commands case WM_COMMAND: { int button = LOWORD(wParam); switch (button) { } } break; default: { // Message not handled return FALSE; } } // Message handled return TRUE; }
-
Mit beide meinte ich IDD_DIALOG2 & IDD_DIALOG3, dass sollen die Dialogs für die Child windows werden, grüße.
-
Dann Erzeuge Fenster und keine neuen Threads!
Wie kommst Du darauf, dass Du mit CreateThread/TerminateThread arbeiten musst.
Benutzte direkt CreateDialog, achte darauf das die Tmeplates den Stil WS_CHILD haben.
-
Martin Richter schrieb:
Dann Erzeuge Fenster und keine neuen Threads!
Wie kommst Du darauf, dass Du mit CreateThread/TerminateThread arbeiten musst.
Benutzte direkt CreateDialog, achte darauf das die Tmeplates den Stil WS_CHILD haben.Die Threads erzeugen ja Fenster, von daher :P. Habs aber entfernt und so probiert, aber der fehler kommt immernoch. Hier siehts bei mir so aus, ich glaub nicht das ich was vergessen habe..
http://i44.tinypic.com/ogyq34.jpg IDD_DIALOG1 -> Main Dialog.
http://i44.tinypic.com/ogyq34.jpg IDD_DIALOG3 -> Child dialog. IDD_DIALOG2 Ist gleich.#include <windows.h> #include "resource.h" HWND gHwnd = 0; HINSTANCE MAIN; HWND Option = 0; HWND checkHwnd = 0; INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgProc2(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //----------------------------------------------------------------------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MAIN = hInstance; HWND hwnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, (LPARAM)hInstance); MSG Msg = {0}; while(GetMessage(&Msg, NULL, 0, 0) > 0) { if(!IsDialogMessage(hwnd, &Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } // Standard return return 0; } INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { gHwnd = CreateDialog(MAIN, MAKEINTRESOURCE(IDD_DIALOG2), NULL, DlgProc1); if(gHwnd == NULL) { MessageBox(NULL, "Window creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } checkHwnd = CreateDialog(MAIN, MAKEINTRESOURCE(IDD_DIALOG3), NULL, DlgProc2); if(checkHwnd == NULL) { MessageBox(NULL, "Window creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } } break; case WM_COMMAND: { int button = LOWORD(wParam); switch (button) { // Exit case IDCANCEL: { PostQuitMessage(0); }break; case btnTest: { if(IsWindowVisible(checkHwnd)) { ShowWindow(checkHwnd, false); ShowWindow(Option, true); } else { ShowWindow(Option, true); } break; } case btnTest2: { if(IsWindowVisible(Option)) { ShowWindow(Option, false); ShowWindow(checkHwnd, true); } else { ShowWindow(checkHwnd, true); } break; } } } break; default: { // Message not handled return FALSE; } } // Message handled return TRUE; } INT_PTR CALLBACK DlgProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Handle the message switch(uMsg) { // Dialog initialize case WM_INITDIALOG: { Option = hWnd; } break; // Commands case WM_COMMAND: { int button = LOWORD(wParam); switch (button) { } } break; default: { // Message not handled return FALSE; } } // Message handled return TRUE; } INT_PTR CALLBACK DlgProc2(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Handle the message switch(uMsg) { // Dialog initialize case WM_INITDIALOG: { checkHwnd = hWnd; } break; // Commands case WM_COMMAND: { int button = LOWORD(wParam); switch (button) { } } break; default: { // Message not handled return FALSE; } } // Message handled return TRUE; }
-
Oops. Bild vom IDD_DIALOG1 -> http://i40.tinypic.com/20r5ide.jpg