[英]winapi window doesn't refresh after painting
Hi I created a window with this: 嗨,我创建了一个窗口:
WNDCLASSEX WndClass = {0};
if (WndClass.cbSize == 0)
{
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = CS_DBLCLKS;
WndClass.lpfnWndProc = WindowProcedure;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = GetModuleHandle(NULL);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = HBRUSH(COLOR_WINDOW+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = ClassName.c_str();
WndClass.hIconSm = LoadIcon( NULL, IDI_APPLICATION);
}
if (RegisterClassEx(&WndClass))
{
WindowHandle = CreateWindowEx(0, ClassName.c_str(), WindowName.c_str(), WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL, NULL, GetModuleHandle(NULL), NULL);
if(WindowHandle)
{
ShowWindow(WindowHandle, SW_SHOWDEFAULT);
}
}
And try to add a button. 并尝试添加一个按钮。 Use this: 用这个:
HWND child = CreateWindowEx(0, L"BUTTON", NULL, WS_CHILD | WS_VISIBLE, n * CHILDS_OFSET, posY, GetWidth(), h, window, NULL, NULL, NULL);
After code executed my window stays clear, but if I move it or resize it, button becomes visible, what the issue might be? 执行代码后,窗口保持清晰,但是如果我移动窗口或调整窗口大小,则按钮可见,这可能是什么问题?
I tried: 我试过了:
RECT rc;
GetClientRect(window, &rc);
InvalidateRect(window, &rc, TRUE);
Tried if window
is handle to the main window and to the button. 尝试是否window
是主窗口和按钮的句柄。
This could happen if your window procedure does not handle WM_PAINT
properly. 如果您的窗口过程无法正确处理WM_PAINT
则可能会发生这种情况。 The minimum thing you must have is 您必须拥有的最低要求是
...
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint( wnd, &ps );
EndPaint( wnd, &ps );
return 0;
}
我认为您需要在ShowWindow
之后调用UpdateWindow
,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.