#include<windows.h> #include<stdlib.h> #include<string.h> #include<tchar.h> HINSTANCE hInst; WNDCLASSEX wcex; WNDCLASSEX DesignWindowClass(HINSTANCE); LRESULT CALLBACK WndProc(HWND ,UINT,WPARAM,LPARAM); //------------------------------------------------------------------ //WinMain Windows应用入口函数 //------------------------------------------------------------------ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { wcex = DesignWindowClass(hInstance); //注册窗口 if(!RegisterClassEx(&wcex)) { MessageBox(NULL,_T("Call to RegisterClassEx failed!"),_T("Win32 Guided Tour"),NULL); return 1; } hInst =hInstance; HWND hWnd = CreateWindow( "szWindowClass", "szTitle", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL ); if(!hWnd) { MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Win32 Guided Tour"), NULL); return 1; } //显示窗体,更新窗体 ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); MSG msg; //消息循环 while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } //--------------------------------------------------------------- //WinProc Windows回调函数 //--------------------------------------------------------------- LRESULT CALLBACK WndProc(HWND hWnd,UINT message, WPARAM wParam,LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; TCHAR greeting[] =_T("hello world"); switch(message) { case WM_PAINT: hdc=BeginPaint(hWnd,&ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd,message,wParam,lParam); } return 0; } //------------------------------------------------------------------- //DesignWindowClass 设计窗口 //------------------------------------------------------------------- WNDCLASSEX DesignWindowClass(HINSTANCE hInstance){ WNDCLASSEX wcex; wcex.cbSize =sizeof(WNDCLASSEX); wcex.style =CS_HREDRAW|CS_VREDRAW; wcex.lpfnWndProc =WndProc; wcex.cbClsExtra =0; wcex.cbWndExtra =0; wcex.hInstance =hInstance; wcex.hIcon =LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor =LoadCursor(NULL,IDC_ARROW); wcex.hbrBackground =(HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName =NULL; wcex.lpszClassName ="szWindowClass"; wcex.hIconSm =LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION)); return wcex; }