VC练习一

 1 #include<windows.h>
 2 #include<stdio.h>
 3 LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
 4 int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdLine)
 5 {
 6     WNDCLASS wndcls;
 7     wndcls.cbClsExtra=0;
 8     wndcls.cbWndExtra=0;
 9     wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
10     wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
11     wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
12     wndcls.hInstance=hInstance;
13     wndcls.lpfnWndProc=WinSunProc;
14     wndcls.lpszClassName="Visual C++ Game";
15     wndcls.lpszMenuName=NULL;
16     wndcls.style=CS_HREDRAW|CS_VREDRAW;
17     RegisterClass(&wndcls);
18     HWND hwnd;
19     hwnd=CreateWindow("Visual C++ Game","Visual C++游戏开发",WS_OVERLAPPEDWINDOW,200,200,600,400,NULL,NULL,hInstance,NULL);
20     ShowWindow(hwnd,SW_SHOWNORMAL);
21     UpdateWindow(hwnd);
22     MSG msg;
23     while(GetMessage(&msg,NULL,0,0))
24     {
25         TranslateMessage(&msg);
26         DispatchMessage(&msg);
27     }
28     return 0;
29 }
30 LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
31 {
32     switch(uMsg)
33     {
34     case WM_PAINT:
35         HDC hDC;
36         PAINTSTRUCT ps;
37         hDC=BeginPaint(hwnd,&ps);
38         TextOut(hDC,200,0,"Visual C++ 游戏开发",strlen("Visual C++游戏开发"));
39         EndPaint(hwnd,&ps);
40         break;
41     case WM_CLOSE:
42         if(IDYES==MessageBox(hwnd,"是否真的结束?","游戏开发",MB_YESNO))
43         {
44             DestroyWindow(hwnd);
45         }
46         break;
47     case WM_DESTROY:
48         PostQuitMessage(0);
49         break;
50     default:
51         return DefWindowProc(hwnd,uMsg,wParam,lParam);
52     }
53     return 0;
54 }

 

posted @ 2014-03-11 11:06  zhangyongjian  阅读(153)  评论(0编辑  收藏  举报