1 #include2 LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM); 3 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow) 4 { 5 TCHAR szname[]=TEXT("classname"); 6 HWND hwnd; 7 MSG msg; 8 ZeroMemory(&msg,sizeof(msg)); 9 WNDCLASS wndclass;10 wndclass.style=CS_HREDRAW | CS_VREDRAW;11 wndclass.lpfnWndProc=WinProc;12 wndclass.cbClsExtra=0;13 wndclass.cbWndExtra=0;14 wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);15 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);16 wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);17 wndclass.hInstance=hInstance;18 wndclass.lpszClassName=szname;19 wndclass.lpszMenuName=NULL;20 RegisterClass(&wndclass);21 hwnd=CreateWindow(szname,TEXT("windowsnametest"),WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);22 if(hwnd)23 ShowWindow(hwnd,SW_SHOW);24 else25 {26 MessageBox(NULL,TEXT("创建窗口失败!"),TEXT("提示"),MB_OK);27 UnregisterClass(szname,hInstance);28 return 1;29 }30 UpdateWindow(hwnd);31 32 while(GetMessage(&msg,hwnd,0,0)>0)33 {34 TranslateMessage(&msg);35 DispatchMessage(&msg);36 }37 UnregisterClass(szname,hInstance);38 return msg.wParam;39 }40 LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)41 {42 switch(message)43 {44 case WM_CLOSE:45 DestroyWindow(hwnd);46 PostQuitMessage(0);47 break;48 default:49 return DefWindowProc(hwnd,message,wParam,lParam);50 }51 return 0;52 }
GetStockObject在库#pragma comment(lib, "gdi32.lib") 中。