forked from mrwid/Snake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snake.c
60 lines (48 loc) · 1.61 KB
/
Snake.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <windows.h>
#include "GameWndProc.h"
#include "resource.h"
//////////////////////////////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
{
static TCHAR szGameName[] = TEXT( "Snake" );
HWND hwnd;
RECT rect;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndclass.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_ICON_GAME) );
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szGameName;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
if( !RegisterClass(&wndclass) )
{
MessageBox( NULL, TEXT("窗口类注册失败!"), TEXT("应用程序错误"), MB_OK | MB_ICONERROR );
return 0;
}
rect.left = 0; rect.top = 0;
rect.right = 800 + GetSystemMetrics(SM_CXFRAME);
rect.bottom = 600 + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXFRAME);
AdjustWindowRect( &rect, WS_CAPTION, FALSE );
hwnd = CreateWindow(
szGameName, TEXT("贪吃蛇"),
WS_CAPTION | WS_SYSMENU,
(int)((GetSystemMetrics(SM_CXSCREEN)-rect.right) /2),
(int)((GetSystemMetrics(SM_CYSCREEN)-rect.bottom)/2),
rect.right, rect.bottom,
NULL, NULL, hInstance, NULL
);
ShowWindow( hwnd, iCmdShow );
UpdateWindow( hwnd );
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
//////////////////////////////////////////////////////////////////////////