绘制窗口不起作用,图标显示在任务栏上,但不显示在屏幕上



编写了一个简单的程序,应该显示一个空窗口,但它没有在屏幕上绘制它,图标显示在任务管理器上,它使用 CPU 电源来保持它,但它没有显示在屏幕上,有人知道修复或知道我做错了什么?

这是我的代码:

#include<Windows.h>
#include<d2d1.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
int WINAPI wWinMain(HINSTANCE hinstance, HINSTANCE prevInstance, LPWSTR cmd, int nCmdShow)
{
WNDCLASSEX windowclass;
ZeroMemory(&windowclass, sizeof(WNDCLASSEX));
windowclass.cbSize = sizeof(WNDCLASSEX);
windowclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
windowclass.hInstance = hinstance;
windowclass.lpfnWndProc = WindowProc;
windowclass.lpszClassName = "CrystalWindow";
windowclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&windowclass);
HWND windowHandle = CreateWindow("CrystalWindow", "Crystal Engine", WS_OVERLAPPEDWINDOW,100, 100, 800, 600, NULL, NULL, hinstance, 0);
if (!windowHandle)
{
return -1;
}
ShowWindow(windowHandle,nCmdShow);
MSG message;
while (GetMessage(&message, NULL, 0, 0))
{
DispatchMessage(&message);
}
return 0;
}

你把DefWindowProc(hwnd, uMsg, wParam, lParam);调用放错了放在WindowProc中,以至于它永远不会被调用。将其移动到if的外部

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT result = DefWindowProc(hwnd, uMsg, wParam, lParam); // Call default first!
if (uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
//  DefWindowProc(hwnd, uMsg, wParam, lParam); // Here, it is never called!
}
return result; // Return the result from the DefWindowProc call!
}

最新更新