Dialog funktioniert nicht vernünftig
-
Hallo Community.
Ich bin grade dabei, ein kleinen Dialog zu schreiben.
Nun habe ich eine Resource IDD_MAIN mit einem leeren Dialog. Dort ist
IDD_MAIN DIALOGEX 6,6,194,103 CAPTION "Share Timer" FONT 8,"MS Sans Serif",0,0 STYLE 0x10CF0000 CLASS "ShareTimer" BEGIN ENDNun habe ich die Klasse, in der der Dialog aufgerufen werden soll:
#define _WIN32_WINNT 0x0510 #include <windows.h> #include "MainWnd.h" #include "script.h" CMainWnd::CMainWnd(HINSTANCE hInst) { hInstance = hInst; // As first fill the class structure wcWnd.cbSize = sizeof(WNDCLASSEX); wcWnd.style = CS_HREDRAW | CS_VREDRAW; wcWnd.lpfnWndProc = StaticWndProc; wcWnd.cbClsExtra = 0; wcWnd.cbWndExtra = DLGWINDOWEXTRA; wcWnd.hInstance = hInstance; wcWnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcWnd.hCursor = LoadCursor(NULL, IDC_ARROW); wcWnd.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wcWnd.lpszMenuName = NULL; wcWnd.lpszClassName = "ShareTimer"; wcWnd.hIconSm = wcWnd.hIcon; if (!RegisterClassEx(&wcWnd)) { return; } hWnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, NULL, (LPARAM)this); // Show the window ShowWindow(hWnd, 1); UpdateWindow(hWnd); } CMainWnd::~CMainWnd(void) { } LRESULT CALLBACK CMainWnd::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { HDC hPaintDC; PAINTSTRUCT ps; switch (uMsg) { case WM_CREATE: Beep(440,1000); return 0; case WM_PAINT: hPaintDC = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } LRESULT CALLBACK CMainWnd::StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_CREATE) { SetWindowLong(hWnd,GWL_USERDATA,(LONG)((LPCREATESTRUCT)lParam) -> lpCreateParams); } CMainWnd *pThis = (CMainWnd *) GetWindowLong(hWnd,GWL_USERDATA); if (pThis == 0) { return DefWindowProc(hWnd,uMsg,wParam,lParam); } else { return pThis->WndProc(hWnd,uMsg,wParam,lParam); } }Das wird auch ohne Mucken kompiliert, aber sobald ich den Debug starte, treten folgende Probleme auf:
1. Der Dialog hat eine weiße hintergrundfarbe, ich will aber die Farben vom Windows-Theme haben!
2. Wenn ich auf schließen klicke, geht der Prozess nicht aus, die Message-Schleife ist die eines standard Windowsfenster.
Das liegt daran, habe ich schon herausgefunden, dass der garnicht bis zur WndProc sondern nur WndProcStatic kommt.
Könnt ihr mir mal daran behilflich sein?
Danke.

-
Du darfst eine "DialogProc" nicht mit einer "WndProc" verwechseln :
BOOL CALLBACK DialogProc( HWND hwndDlg, // handle to dialog box UINT uMsg, // message WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );DialogProc schrieb:
Return Values
...the dialog box procedure should return nonzero if it processes the message, and zero if it does not.Sie verhält sich gewissermassen "um 180 Grad verkehrt".
-
Ooooh! Na gut, dann werde ich halt eine DlgProc verwenden.
Aber in der WNDCLASSEX ist doch noch ein WHITE_BRUSH. Was mach ich mit dem?
Und wie bekomme ich die DlgProc nicht "static"? Eigentlich wollte ich dafür CreateDialogParam verwenden.
Bis spädda.

-
Sorry für den DoppelPost, aber ich habe einen neuen Versuch gestartet.
#define _WIN32_WINNT 0x0510 #include <windows.h> #include "MainWnd.h" #include "script.h" CMainWnd::CMainWnd(HINSTANCE hInst) { hInstance = hInst; DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, StaticProc, (long)this); } CMainWnd::~CMainWnd(void) { } INT_PTR CALLBACK CMainWnd::DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return 0; case WM_CLOSE: EndDialog(hDlg, IDOK); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog(hDlg, IDOK); return 0; } return 0; } return 0; } INT_PTR CALLBACK CMainWnd::StaticProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static CMainWnd *pThis; if (message = WM_INITDIALOG) { pThis = (CMainWnd*)lParam; } if (pThis) return pThis->DialogProc(hDlg, message, wParam, lParam); else return 0; }Jedoch lässt sich das Fenster nicht schließen. ich weiß auch nicht warum, aber die Messages kommen in der "unstatic" an.
Danke.

-
Ein Klick auf das Dialog-X sendet eine WM_COMMAND-Message an den Dialog mit HIWORD(wParam)==IDCANCEL

-
:push:
keiner ne idee?
-
(LOWORD(wParam)==IDCANCEL natürlich)
-
es liegt an der Static Proc.
Denn wenn ich den Inhalt der DlgProc in die StaticProc packe, funktionierts.
komisch. liegt es an dem Static der Variable im StaticProc?
-
Naja, nach ein bisschen probben gehts.
ich habe jetzt zwei methoden, wie man es machen könnte.
Welche ist besser?
// Set/Get
{ CMainWnd *pThis; if (message == WM_INITDIALOG) { SetWindowLong(hDlg, GWL_USERDATA, (LONG)((LPCREATESTRUCT)lParam) -> lpCreateParams); } pThis = (CMainWnd *) GetWindowLong(hDlg, GWL_USERDATA); if (pThis == 0) return 0,; else return pThis->DialogProc(hDlg, message, wParam, lParam); }// Static in static
{ static CMainWnd *pThis; if (message == WM_INITDIALOG) { // Fill static pThis = (CMainWnd *) (LONG)((LPCREATESTRUCT)lParam) -> lpCreateParams; } if (pThis == 0) return 0; else return pThis->DialogProc(hDlg, message, wParam, lParam); }Sind beide gut? hat die Static eine bessere performance, da weniger Funktionsaufruf?
Danke.
-
Bitte ankreuzen :
"return 0" in einer DialogProc bedeutet, dass die Botschaft
-
merker schrieb:
Bitte ankreuzen :
"return 0" in einer DialogProc bedeutet, dass die Botschaft
[ X ] selbst behandelt wurde und das Betriebssystem keine DefaultProc aufrufen soll.
Dann eben DefDlgProc...
Abner was ist denn besser?
[] Static variante
[] Get/Set WindowLong methodeTja.
Back to topic:
Der Dialog in Klasse funzt super.
Wenn ich ihn in der WinMain aufrufe.
Aber wenn ich ihn in der DialogProc des Main-Dialogs aufrufe, kommt er nicht.
Woran kann das liegen? Also ich weiß sicher, dass Die Funktion aufgerufen wird, aber der Dialog kommt nicht.