[EDITED adds: It turns out that the answer is very boring and has nothing to do with Win32, dialogs, etc. I just had an idiotic bug in my code. Thanks to Hans Passant for noticing.]
(This is quite a long time. Short description: I have a simple Win32 application that creates an icon in the notification area, never shows its main window and has a "about" field that can be displayed by right-clicking on the notification area icon. For no reason I can understand when the "about" window is displayed and then closed, the main application message loop receives an exit message and ends. What could I do wrong to cause this?)
I am writing a small program, which is located in the notification area ("system tray"), and runs various processing bits that are inappropriate here in the background. Its user interface is almost trivial: you can right-click the area icon to get a menu, with the options "Exit" and "About"; the first leaves, the last pops up a little about the modal dialog box of this program.
The application is written in C ++ and uses Win32 directly (without MFC or anything else). I apologize for being stuck in the Stone Age.
The only problem is this: when the "About" dialog is closed, the program ends! What could be the reason for this?
, . .
- Windows "" , .
- proc WM_CTLCOLORBTN
- () WM_ENABLE (TRUE).
- WM_CTLCOLORBTN, WM_IMESETCONTEXT, WM_SETFOCUS, WM_WINDOWPOSCHANGING, WM_WINDOWPOSCHANGED, 3xWM_GETICON, WM_NCACTIVATE, 2xWM_GETICON, WM_ACTIVATE, WM_WINDOWPOSCHANGING.
- ges WM_WINDOWPOSCHANGING, WM_NCACTIVATE, 0x93, 0x93, 0x91, 0x92, 0x92 ( ?), WM_ACTIVATE.
- WM_KILLFOCUS, WM_IME_SETCONTEXT.
- WM_IME_SETCONTEXT.
- WM_IME_NOTIFY; .
- WM_SETFOCUS.
- 0x90, WM_DESTROY, WM_NCDESTROY.
- proc, .
- GetMessage 0 ( WM_QUIT) .
- PostQuitMessage WndProc, , WM_DESTROY, .
, - , - . ( , , ).
WinMain :
WNDCLASSEX wc;
RegisterClassEx(&wc);
HWND w = CreateWindow(...);
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
Shell_NotifyIcon(NIM_ADD, &nid);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
if (TranslateAccelerator(msg,hwnd, accel, &msg)) continue;
TranslateMesage(&msg);
DispatchMessage(&msg);
}
Shell_NotifyIcon(NUM_DELETE, &nid);
return (int)msg.wParam;
WndProc :
switch (message) {
case WM_USER_SHELLICON:
if (LOWORD(lParam) == WM_RBUTTONDOWN)
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_ABOUT:
DialogBox(the_instance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, AboutProc);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
proc :
switch (message) {
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam)==IDOK || LOWORD(wParam)==IDCANCEL) {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;