简体   繁体   English

AnimateWindow 不调用 WM_PAINT

[英]AnimateWindow not calling WM_PAINT

I need to animate the display of the rendered window, I have a WM_PRINTCLIENT and WM_PAINT event, but the window is not rendered during the animation, only if RedrawWindow is used after the animation is shown我需要为渲染的 window 的显示设置动画,我有一个 WM_PRINTCLIENT 和 WM_PAINT 事件,但是 window 在 animation 期间没有渲染,只有在显示 animation 之后使用 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);

PAINT:画:

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);
   
}

enter image description here在此处输入图像描述

I have adopted your code, so that I can run it in isolation.我采用了您的代码,以便我可以单独运行它。 I do get debug output WM_PRINTCLIENT during animation.我确实在 animation 期间得到调试 output 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);
}

And here is the window proc I used:这是我使用的 window 过程:

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;
}

NOTE:笔记:

For details, please see WM_PRINTCLIENT message详情请看WM_PRINTCLIENT消息

A window can process this message in much the same manner as WM_PAINT, except that BeginPaint and EndPaint need not be called (a device context is provided), and the window should draw its entire client area rather than just the invalid region. window 可以用与 WM_PAINT 几乎相同的方式处理此消息,只是不需要调用 BeginPaint 和 EndPaint(提供了设备上下文),并且 window 应该绘制其整个客户区域,而不仅仅是无效区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM