#include<windows.h> #include<tchar.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,INT nCmdShow) { HWND hMainWnd; MSG msg; WNDCLASS myWC; if(!hPrevInstance) { myWC.style=CS_VREDRAW|CS_HREDRAW; myWC.lpfnWndProc=WndProc; myWC.cbClsExtra=0; myWC.cbWndExtra=0; myWC.hInstance=hInstance; myWC.hIcon=LoadIcon(NULL,IDI_APPLICATION); myWC.hCursor=LoadCursor(NULL,IDC_ARROW); myWC.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); myWC.lpszMenuName=NULL; myWC.lpszClassName=_T("MyWindowClass"); RegisterClass(&myWC); } hMainWnd=CreateWindow(_T("MyWindowClass"),_T("MyWindowAPItitle"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); ShowWindow(hMainWnd,SW_SHOWMAXIMIZED); UpdateWindow(hMainWnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hMainwnd,UINT message,WPARAM wParam,LPARAM lParam) { char messageleft[]="the left button have been pushed"; char messageright[]="the right button have pushed"; switch(message) { case WM_RBUTTONDOWN: { MessageBox(GetFocus(),_T("messageright"),_T("RButtonPushDown"),MB_OK|MB_ICONINFORMATION); break; } case WM_LBUTTONDOWN: { MessageBox(GetFocus(),_T("messageleft"),_T("LButtonPushDown"),MB_OK|MB_ICONINFORMATION); break; } case WM_DESTROY: { PostQuitMessage(0); return 0; } default:break; } return DefWindowProc(hMainwnd,message,wParam,lParam); }
1.注册窗口类
2.创建窗口
3.消息循环
4.编写窗口消息处理函数