完善样式设计:樱花粉风格

This commit is contained in:
2026-04-24 10:37:30 +08:00
parent 2f477272ab
commit 141405c5f5
5 changed files with 285 additions and 100 deletions
+45 -8
View File
@@ -31,6 +31,19 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
HMODULE user32Module = GetModuleHandle(_T("user32.dll"));
if (user32Module != nullptr)
{
typedef BOOL(WINAPI* SetProcessDPIAwareFunc)();
SetProcessDPIAwareFunc setProcessDPIAware =
(SetProcessDPIAwareFunc)GetProcAddress(user32Module, "SetProcessDPIAware");
if (setProcessDPIAware != nullptr)
{
setProcessDPIAware();
}
}
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_TETRIS, szWindowClass, MAX_LOADSTRING);
lstrcpy(szTitle, _T("俄罗斯方块"));
@@ -97,7 +110,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
*/
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
RECT rect = { 0, 0, GRID * nWidth, GRID * nHeight };
RECT rect = { 0, 0, WINDOW_CLIENT_WIDTH, WINDOW_CLIENT_HEIGHT };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, TRUE);
hInst = hInstance;
@@ -146,7 +159,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
srand((unsigned int)time(nullptr));
Restart();
SetTimer(hWnd, GAME_TIMER_ID, GAME_TIMER_INTERVAL, nullptr);
InvalidateRect(hWnd, nullptr, TRUE);
InvalidateRect(hWnd, nullptr, FALSE);
break;
case WM_COMMAND:
{
@@ -184,28 +197,28 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ComputeTarget();
}
InvalidateRect(hWnd, nullptr, TRUE);
InvalidateRect(hWnd, nullptr, FALSE);
}
break;
case WM_KEYDOWN:
if (wParam == 'R')
{
Restart();
InvalidateRect(hWnd, nullptr, TRUE);
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
if (wParam == 'P')
{
suspendFlag = !suspendFlag;
InvalidateRect(hWnd, nullptr, TRUE);
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
if (wParam == 'G')
{
targetFlag = !targetFlag;
InvalidateRect(hWnd, nullptr, TRUE);
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
@@ -258,13 +271,37 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ComputeTarget();
}
InvalidateRect(hWnd, nullptr, TRUE);
InvalidateRect(hWnd, nullptr, FALSE);
break;
case WM_ERASEBKGND:
return 1;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
TDrawScreen(hdc, hWnd);
RECT clientRect;
GetClientRect(hWnd, &clientRect);
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP memBitmap = CreateCompatibleBitmap(
hdc,
clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top);
HBITMAP oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap);
TDrawScreen(memDC, hWnd);
BitBlt(
hdc,
0, 0,
clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top,
memDC,
0, 0,
SRCCOPY);
SelectObject(memDC, oldBitmap);
DeleteObject(memBitmap);
DeleteDC(memDC);
EndPaint(hWnd, &ps);
}
break;