C++实例 窗口和消息 处理关闭窗口消息 是否关闭

来源:互联网 发布:ipad 软件不能上网 编辑:程序博客网 时间:2024/05/16 02:03
#include <windows.h>LRESULT CALLBACK WindowProc(  HWND hwnd,      // handle to window  UINT uMsg,      // message identifier  WPARAM wParam,  // first message parameter  LPARAM lParam   // second message parameter);int WINAPI WinMain(  HINSTANCE hInstance,      // handle to current instance  HINSTANCE hPrevInstance,  // handle to previous instance  LPSTR lpCmdLine,          // command line  int nCmdShow              // show state  ){static LPCTSTR lpszClassName = TEXT("HelloWin");LPCTSTR lpWindowName = TEXT("MyApp");HWND hwnd;MSG msg;//http://www.pythonschool.com/ WNDCLASS wndclass = {     CS_HREDRAW|CS_VREDRAW,    WindowProc,    0,    0,     hInstance,    LoadIcon(hInstance, IDI_ERROR),    LoadCursor(hInstance, IDC_CROSS),    (HBRUSH)GetStockObject(WHITE_PEN),    (LPCTSTR)NULL,    lpszClassName} ;  if(!RegisterClass(&wndclass)) return FALSE; hwnd = CreateWindow(  lpszClassName,  // registered class name  lpWindowName, // window name  WS_OVERLAPPEDWINDOW,        // window style  CW_USEDEFAULT,                // horizontal position of window  CW_USEDEFAULT,                // vertical position of window  CW_USEDEFAULT,           // window width  CW_USEDEFAULT,          // window height  NULL,      // handle to parent or owner window  NULL,          // menu handle or child identifier  hInstance,  // handle to application instance  NULL        // window-creation data);ShowWindow(hwnd, nCmdShow);UpdateWindow(hwnd);while(GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK WindowProc(  HWND hwnd,      // handle to window  UINT uMsg,      // message identifier  WPARAM wParam,  // first message parameter  LPARAM lParam   // second message parameter  ){switch( uMsg ){case WM_CLOSE:if(MessageBox(hwnd, "Hello", "World!", MB_YESNO) == IDYES)PostQuitMessage(0); elsereturn 0;}return DefWindowProc(hwnd, uMsg, wParam, lParam);}
http://www.pythonschool.com/