求助, 为什么我在关闭子窗口的时候父窗口自动关闭
程序代码:
// Winnd.cpp : Defines the entry point for the application. // #include "stdafx.h" HINSTANCE g_hInstance; //窗口注册 BOOL _register(LPSTR winname, WNDPROC dealproc) { WNDCLASSEX wce = {0}; wce.cbSize = sizeof(wce); wce.style = CS_HREDRAW | CS_VREDRAW; wce.lpfnWndProc = dealproc; wce.cbClsExtra = 0; wce.cbWndExtra = 0; wce.hInstance = g_hInstance; wce.hIcon = NULL; wce.hIconSm = NULL; wce.hCursor = NULL; wce.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wce.lpszClassName = winname; wce.lpszMenuName = NULL; ATOM nAtom = RegisterClassEx(&wce); if(nAtom == 0) { return FALSE; } return TRUE; } //主窗口实现 HWND dream(LPSTR winname, LPSTR showname) { HWND hWnd = CreateWindowEx(0, winname, showname, WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, g_hInstance, NULL); return hWnd; } //子窗口实现 HWND child(LPSTR winname, LPSTR showname, HWND hWnd) { HWND hChild = CreateWindowEx(0, winname, showname, WS_OVERLAPPEDWINDOW | WS_CHILD | WS_VISIBLE, 0, 0, 200, 200, hWnd, NULL, g_hInstance, NULL); return hChild; } //自定义处理函数 LRESULT CALLBACK dealproc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { switch(nMsg)//关闭程序可以结束进程 { case WM_DESTROY: PostQuitMessage(0);//能够使GetMessage返回0 break; } return DefWindowProc(hWnd, nMsg, wParam, lParam); } //显示窗口 void display(HWND hWnd) { ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); } //设置消息循环 void message() { MSG nMsg = {0}; while(GetMessage(&nMsg, NULL, 0, 0)) { TranslateMessage(&nMsg); DispatchMessage(&nMsg); } } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { g_hInstance = hInstance; _register("main", dealproc); HWND hWnd = dream("main", "主窗口"); _register("_child", dealproc); HWND hChild = child("_child", "子窗口", hWnd); _register("__child", dealproc); HWND hChild2 = child("__child", "子窗口", hWnd); display(hWnd); message(); return 0; }