diff --git a/list.md b/list.md index ac8b223..8bbf091 100644 --- a/list.md +++ b/list.md @@ -6,7 +6,7 @@ - [x] `_tWinMain` - `src/source/Tetris.cpp` - [x] `MyRegisterClass` - `src/source/Tetris.cpp` -- [ ] `InitInstance` - `src/source/Tetris.cpp` +- [x] `InitInstance` - `src/source/Tetris.cpp` - [ ] `WndProc` - `src/source/Tetris.cpp` - [ ] `About` - `src/source/Tetris.cpp` diff --git a/report/images/Part1/InitInstanceBefore.png b/report/images/Part1/InitInstanceBefore.png new file mode 100644 index 0000000..e7dc555 Binary files /dev/null and b/report/images/Part1/InitInstanceBefore.png differ diff --git a/src/source/Tetris.cpp b/src/source/Tetris.cpp index 956f549..fb56eb4 100644 --- a/src/source/Tetris.cpp +++ b/src/source/Tetris.cpp @@ -71,9 +71,34 @@ ATOM MyRegisterClass(HINSTANCE hInstance) BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { // TODO(作业3): 创建并显示主窗口。 - UNREFERENCED_PARAMETER(hInstance); - UNREFERENCED_PARAMETER(nCmdShow); - return FALSE; + + RECT rect = { 0, 0, GRID * nWidth, GRID * nHeight }; + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, TRUE); + + hInst = hInstance; + + HWND hWnd = CreateWindow( + szWindowClass, + szTitle, + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + 0, + rect.right - rect.left, + rect.bottom - rect.top, + nullptr, + nullptr, + hInstance, + nullptr); + + if (!hWnd) + { + return FALSE; + } + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + + return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)