簡體   English   中英

AnimateWindow 不調用 WM_PAINT

[英]AnimateWindow not calling WM_PAINT

我需要為渲染的 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);

畫:

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

在此處輸入圖像描述

我采用了您的代碼,以便我可以單獨運行它。 我確實在 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);
}

這是我使用的 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;
}

筆記:

詳情請看WM_PRINTCLIENT消息

window 可以用與 WM_PAINT 幾乎相同的方式處理此消息,只是不需要調用 BeginPaint 和 EndPaint(提供了設備上下文),並且 window 應該繪制其整個客戶區域,而不僅僅是無效區域。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM