标签:
#include <Windows.h> HINSTANCE hinst; HWND hwnd; LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) { //定义窗口类 WNDCLASSEX wcx; MSG msg; BOOL fGotMessage; hinst = hinstance; wcx.lpszClassName = "MainWClass"; wcx.cbSize = sizeof(wcx); wcx.style = CS_HREDRAW | CS_VREDRAW; wcx.lpfnWndProc = MainWndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hinstance; wcx.hIcon = LoadIcon(NULL,IDI_APPLICATION); wcx.hCursor = LoadCursor(NULL,IDC_ARROW); wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wcx.lpszMenuName = NULL; wcx.hIconSm = (HICON)LoadImage(hinstance, MAKEINTRESOURCE(5),IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); if(!RegisterClassEx(&wcx)) { return 1; } //使用窗口类创建窗口 hwnd = CreateWindow("MainWClass", "Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL, (HMENU)NULL, hinst, (LPVOID)NULL); if(!hwnd) { return 1; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while((fGotMessage = GetMessage(&msg,(HWND)NULL,0,0))!=0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } // 窗口过程函数,处理消息 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_LBUTTONDOWN: MessageBox(hwnd,"Hello窗口!","hello",MB_OK); return 0; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } }
定义窗口类,注册窗口类,使用窗口类创建窗口
标签:
原文地址:http://www.cnblogs.com/gongyan/p/4338869.html