一个多窗口的问题
程序代码:
#include <windows.h> LRESULT CALLBACK WndPr(HWND,UINT,WPARAM,LPARAM); BOOL Application(HINSTANCE hinstance); BOOL Initinstance(HINSTANCE hinstance,int nCmdShow); HWND hwnd,s_hwnd; MSG msg,s_msg; static TCHAR szAppName[] = TEXT ("HelloWin") ; int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int nCmdShow) { Application(hinstance); Initinstance(hinstance,nCmdShow); while (GetMessage (&msg,NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam; } BOOL Application(HINSTANCE hinstance) { WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndPr ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hinstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName= szAppName ; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return FALSE ; } return TRUE; } BOOL Initinstance(HINSTANCE hinstance,int nCmdShow) { hwnd = CreateWindow( szAppName, // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT,// initial x position CW_USEDEFAULT,// initial y position CW_USEDEFAULT,// initial x size CW_USEDEFAULT,// initial y size NULL, // parent window handle NULL, // window menu handle hinstance, // program instance handle NULL) ; // creation parameters if(!hwnd) return FALSE; ShowWindow (hwnd, nCmdShow) ; UpdateWindow (hwnd) ; s_hwnd = CreateWindow( szAppName, // window class name TEXT ("Hello Mr.chen"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT,// initial x position CW_USEDEFAULT,// initial y position CW_USEDEFAULT,// initial x size CW_USEDEFAULT,// initial y size NULL, // parent window handle NULL, // window menu handle hinstance, // program instance handle NULL) ; // creation parameters if(!s_hwnd) return FALSE; ShowWindow (s_hwnd, nCmdShow) ; //UpdateWindow (s_hwnd) ; return TRUE; } LRESULT CALLBACK WndPr (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; /*if(hwnd==hwnd) MessageBox(NULL,"Oh!NO!","Dialog",MB_YESNO|MB_ICONHAND); PostQuitMessage (0) ;*/ switch (message) { case WM_PAINT: if(hwnd==hwnd){ hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; } else if(s_hwnd==hwnd){ hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; }; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }我想利用同一个窗口类,建立多个窗口并显示出来
为什么对于最大化和最小化窗口,两个窗口是独立的,互不影响。但是点击关闭一个窗口后,两个窗口都关闭了。
这是什么原因???我想显示完全独立的2个窗口