#include
#include
#include
#include"resource.h"
#define BLOCK 100
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM LParam
);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR IpCmdLine, int nCmdShow){
wchar_t szAppClassName[20] = L"TZGuiFoundation";
WNDCLASS wndClass;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WindowProc;
wndClass.lpszClassName = szAppClassName;
wndClass.lpszMenuName = NULL;
wndClass.style = CS_HREDRAW | CS_VREDRAW;
//
RegisterClass(&wndClass);
//
HWND hWnd = CreateWindow(szAppClassName,
L"黑白块游戏",
WS_OVERLAPPEDWINDOW,
500,
100,
BLOCK * 4 + 20,
BLOCK * 4 + 40,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hWnd,
SW_SHOW
);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TRUE;
}
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
PAINTSTRUCT ps;
HDC hDC;
static int bw[4];
switch (uMsg)
{
case WM_CREATE:
{
srand((UINT)time(NULL));
for (int i = 0; i < 4; i++)
{
bw[i] = rand() % 4;
}
SetTimer(hWnd, 1, 10, NULL);
}
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hDC= BeginPaint(hWnd, &ps);
for (int i = 0; i < 4; i++)
{
MoveToEx(hDC, 0, i*BLOCK, NULL);
LineTo(hDC, 4 * BLOCK, i*BLOCK);
MoveToEx(hDC, i*BLOCK, 0, NULL);
LineTo(hDC, 4 * BLOCK, i*BLOCK);
EndPaint(hWnd, &ps);
return TRUE;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}