Source
1#include <Windows.h>2 3 LRESULT CALLBACK Windproc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM);4 5 intWinMain (hinstance hInst, hinstance tmp, LPSTR szcmd,intnshow)6 {7 wndclass wndclass;8tchar* ClassName = TEXT ("MyClass");9 HWND hwnd;Ten msg msg; One AWndclass.cbclsextra =0; -Wndclass.cbwndextra =0; -Wndclass.hbrbackground = (hbrush) (Color_window +1); theWndclass.hcursor =loadcursor (NULL, idc_arrow); -Wndclass.hicon =LoadIcon (NULL, idi_application); -Wndclass.hinstance =HInst; -Wndclass.lpfnwndproc =Windproc; +Wndclass.lpszclassname =ClassName; -Wndclass.lpszmenuname =NULL; +Wndclass.style = Cs_vredraw |Cs_hredraw; A at if(! RegisterClass (&wndclass)) - { -MessageBox (NULL, TEXT ("gegister Class fail!!"), TEXT ("Error"), MB_OK); - return 0; - } - inhwnd = CreateWindow (ClassName, TEXT ("Hello"), Ws_overlappedwindow, Cw_usedefault, Cw_usedefault, -, -, NULL, NULL, HINST, NULL); - if(hwnd = =NULL) to { +MessageBox (NULL, TEXT ("Create Window fail!!"), TEXT ("Error"), MB_OK); - return 0; the } * ShowWindow (hwnd, nshow); $ UpdateWindow (HWND);Panax Notoginseng - while(GetMessage (&msg,null,0,0)) the { +TranslateMessage (&msg); ADispatchMessage (&msg); the } + - return 0; $ } $ - LRESULT CALLBACK Windproc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) - { the Switch(message) - {Wuyi CaseWm_destroy: thePostQuitMessage (0);//Send Wm_quit message - return 0; Wu default: - Break; About } $ - returnDefWindowProc (hwnd, message, WParam, lParam); -}
View Code
Windows Forms programs spend most of their lifetime in the message loop.
Windows Programming--windows Program Framework