diff --git a/list.md b/list.md index 8bbf091..31dd418 100644 --- a/list.md +++ b/list.md @@ -7,7 +7,7 @@ - [x] `_tWinMain` - `src/source/Tetris.cpp` - [x] `MyRegisterClass` - `src/source/Tetris.cpp` - [x] `InitInstance` - `src/source/Tetris.cpp` -- [ ] `WndProc` - `src/source/Tetris.cpp` +- [x] `WndProc` - `src/source/Tetris.cpp` - [ ] `About` - `src/source/Tetris.cpp` ## 第二阶段:游戏区域与状态初始化 diff --git a/report/images/Part1/WndProcAfter.png b/report/images/Part1/WndProcAfter.png new file mode 100644 index 0000000..67b8d3e Binary files /dev/null and b/report/images/Part1/WndProcAfter.png differ diff --git a/report/images/Part1/WndProcBefore.png b/report/images/Part1/WndProcBefore.png new file mode 100644 index 0000000..eb32dfa Binary files /dev/null and b/report/images/Part1/WndProcBefore.png differ diff --git a/src/source/Tetris.cpp b/src/source/Tetris.cpp index fb56eb4..fd3d091 100644 --- a/src/source/Tetris.cpp +++ b/src/source/Tetris.cpp @@ -104,7 +104,41 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { // TODO(作业4): 补全主窗口消息处理函数。 - return DefWindowProc(hWnd, message, wParam, lParam); + switch (message) + { + case WM_COMMAND: + { + int wmId = LOWORD(wParam); + + switch (wmId) + { + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDM_EXIT: + DestroyWindow(hWnd); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + } + break; + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + TDrawScreen(hdc, hWnd); + EndPaint(hWnd, &ps); + } + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + + return 0; } INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)