非模式对话框下 点击按钮,弹出模式对话框
非模式对话框上 点击按钮,弹出模式对话框
结果模式对话框关闭不了
主窗口---------------非模式
子窗口--------------模式
结果模式对话框上的 按钮不响应,且也关闭不了
郁闷
------解决方案--------------------
IsDialogMessage(hwnd,MainDlgProc)) 逻辑不太对吧
应该是 !IsDialogMessage(hwnd,MainDlgProc)) 。
结果模式对话框关闭不了
主窗口---------------非模式
子窗口--------------模式
结果模式对话框上的 按钮不响应,且也关闭不了
郁闷
- C/C++ code
/*------------------------------------------ ABOUT1.C -- About Box Demo Program No. 1 (c) Charles Petzold, 1998 ------------------------------------------*/ #include <windows.h> #include "resource.h" static HINSTANCE g_hInst=NULL; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; BOOL CALLBACK MainDlgProc (HWND, UINT, WPARAM, LPARAM) ; //主对话框 BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ; //关于对话框 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { // static TCHAR szAppName[] = TEXT ("About1") ; // MSG msg ; // HWND hwnd ; // WNDCLASS wndclass ; // // wndclass.style = CS_HREDRAW | CS_VREDRAW ; // wndclass.lpfnWndProc = WndProc ; // wndclass.cbClsExtra = 0 ; // wndclass.cbWndExtra = 0 ; // wndclass.hInstance = hInstance ; // wndclass.hIcon = LoadIcon (hInstance, szAppName) ; // wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; // wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; // wndclass.lpszMenuName = szAppName ; // wndclass.lpszClassName = szAppName ; // // if (!RegisterClass (&wndclass)) // { // MessageBox (NULL, TEXT ("This program requires Windows NT!"), // szAppName, MB_ICONERROR) ; // return 0 ; // } // // hwnd = CreateWindow (szAppName, TEXT ("About Box Demo Program"), // WS_OVERLAPPEDWINDOW, // CW_USEDEFAULT, CW_USEDEFAULT, // CW_USEDEFAULT, CW_USEDEFAULT, // NULL, NULL, hInstance, NULL) ; // // ShowWindow (hwnd, iCmdShow) ; // UpdateWindow (hwnd) ; HWND g_Dlghwnd; MSG msg; g_hInst=hInstance; g_Dlghwnd=CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_MAIN_DIALOG),NULL,MainDlgProc); while (GetMessage (&msg, NULL, 0, 0)) { if(g_Dlghwnd==NULL || IsDialogMessage(g_Dlghwnd,&msg)) TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; //DialogBox(g_hInst,MAKEINTRESOURCE(IDD_MAIN_DIALOG),NULL,MainDlgProc); } BOOL CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND : switch (LOWORD (wParam)) { case IDOK : case IDCANCEL : // EndDialog (hDlg, 0) ; DestroyWindow(hDlg); return TRUE ; case IDC_BUTTON1: //关于对话框的id DialogBox (g_hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hDlg, AboutDlgProc) ; } break ; case WM_CLOSE: DestroyWindow(hDlg); break; default: return DefWindowProc(hDlg,message,wParam,lParam); } return FALSE ; } BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND : switch (LOWORD (wParam)) { case IDOK : case IDCANCEL : EndDialog (hDlg, 0) ; return TRUE ; } break ; case WM_CLOSE: EndDialog(hDlg,0); default: return DefWindowProc(hDlg,message, wParam,lParam); } return FALSE ; }
------解决方案--------------------
IsDialogMessage(hwnd,MainDlgProc)) 逻辑不太对吧
应该是 !IsDialogMessage(hwnd,MainDlgProc)) 。