简体   繁体   English

在 WM_PAINT 外画一条线

[英]Drawing a Line Outside of WM_PAINT

Usually, to draw a line we draw it in WM_PAINT通常,为了画一条线,我们在WM_PAINT 中画它

LRESULT CALLBACK Display::DisplayWindowProc(HWND hWnd,UINT msg,WPARAM wParamm,LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;

    switch(msg)
    {
    case WM_PAINT:
        hdc = BeginPaint(hWnd,&ps);
        MoveToEx(hdc,0,0,0);
        LineTo(hdc,100,100);
        EndPaint(hWnd,&ps);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc( hWnd, msg, wParamm, lParam);
}

But , i want to draw line whenever i want, simple example:但是,我想随时画线,简单的例子:

int WINAPI WinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR cmdLine,
int showCmd
)
{
    //Do Other Things
    Display dislpay;
    display.DrawLine();
    //Do Other Things
}

My Program is Object Oriented and i display things in Display class and i was wondering if i can do a draw line in a function like DrawLine() in Display Class.我的程序是面向对象的,我在 Display 类中显示内容,我想知道是否可以在 Display Class 中的 DrawLine() 等函数中绘制一条线。

You can create an off-screen DC, and select an appropriately sized bitmap, and use that to draw whenever you want.您可以创建一个屏幕外 DC,并选择一个适当大小的位图,然后随时使用它进行绘制。 Then on WM_PAINT you blit from the off-screen DC into the windows DC.然后在WM_PAINT您从屏幕外 DC 进入 Windows DC。

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

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