我需要对呈现窗口的显示进行动画化,我有一个WM_PRINTCLIENT和WM_PAINT事件,但是只有在动画显示后使用RedrawWindow时,才会在动画期间呈现窗口。
WNDCLASSW Wcc;
MSG Msg;
Wcc.style = CS_HREDRAW | CS_VREDRAW;
Wcc.lpfnWndProc = &this->_ChildWndProc;
Wcc.cbClsExtra = 0;
Wcc.cbWndExtra = 0;
Wcc.hInstance = (HINSTANCE)GetWindowLong(hParent, GWL_HINSTANCE);
hInst_ = (HINSTANCE)GetWindowLong(hParent, GWL_HINSTANCE);
Wcc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
Wcc.hCursor = LoadCursor(NULL, IDC_ARROW);
Wcc.hbrBackground = reinterpret_cast<HBRUSH> (CreateSolidBrush(RGB( 255, 255, 255)));
Wcc.lpszMenuName = NULL;
Wcc.lpszClassName = className;
this->className = className;
this->hParent = hWnd;
this->text = text;
this->title = title;
//this->title = title;
windowW = 450;
windowH = 300;
hChild = CreateWindowExW(0, Wcc.lpszClassName, 0, WS_POPUP | WS_MINIMIZEBOX, x, y,
windowW, windowH, hWnd, NULL, (HINSTANCE)GetWindowLong(hParent, GWL_HINSTANCE), NULL);
loadResources(hChild);
SetWindowLongPtrW(hChild, GWLP_USERDATA, (LONG)this);
//SetTransparency(hChild, 0x0f);
//ShowWindow(hChild, SW_SHOW);
AnimateWindow(hChild, 1000, AW_ACTIVATE | AW_BLEND);油漆:
case WM_PAINT:
{
Paint(hDlg);
break;
}
case WM_PRINTCLIENT:
{
PaintA(hDlg);
break;
}
Paint(HWND hwnd)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
Graphics graphics(hdc);
Image image(L"g:\\_project\\image viewer\\ipcamera.jpg");
graphics.DrawImage(&image, 0, 0);
EndPaint(hwnd, &ps);
}
PaintA(HWND hwnd)
{
HDC hdc = GetDC(hwnd);
Graphics graphics(hdc);
Image image(L"g:\\_project\\image viewer\\ipcamera.jpg");
graphics.DrawImage(&image, 0, 0);
}发布于 2022-03-06 23:17:39
我采用了您的代码,这样我就可以单独运行它了。在动画期间,我确实获得了调试输出WM_PRINTCLIENT。
void foo(HINSTANCE hInst, HWND hParent) {
static const wchar_t* className = L"myClassName";
WNDCLASSW Wcc = {};
MSG Msg;
Wcc.style = CS_HREDRAW | CS_VREDRAW;
Wcc.lpfnWndProc = ChildWndProc;
Wcc.cbClsExtra = 0;
Wcc.cbWndExtra = 0;
Wcc.hInstance = hInst;
Wcc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
Wcc.hCursor = LoadCursor(NULL, IDC_ARROW);
Wcc.hbrBackground = CreateSolidBrush(RGB(255, 0, 255));
Wcc.lpszMenuName = NULL;
Wcc.lpszClassName = className;
RegisterClassW(&Wcc);
HWND hChild = CreateWindowW(className, nullptr, WS_POPUP | WS_MINIMIZEBOX, 100, 200, 300, 400, nullptr, nullptr, hInst, nullptr);
AnimateWindow(hChild, 2000, AW_ACTIVATE | AW_BLEND);
}下面是我使用的窗口程序:
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
::OutputDebugString(L"WM_PAINT\n");
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
case WM_PRINTCLIENT:
{
::OutputDebugString(L"WM_PRINTCLIENT\n");
HDC hdc = (HDC)wParam;
::MoveToEx(hdc, 10, 10, nullptr);
::LineTo(hdc, 100, 100);
}
case WM_ERASEBKGND:
{
::OutputDebugString(L"WM_ERASEBKGND\n");
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}注:
有关详细信息,请参阅WM_PRINTCLIENT消息
窗口可以以与WM_PAINT相同的方式处理此消息,但不需要调用BeginPaint和EndPaint (提供了设备上下文),并且窗口应该绘制其整个工作区,而不仅仅是无效区域。
https://stackoverflow.com/questions/71374433
复制相似问题