Get the App
SLTechnology News&Howtos  ›  Servers  › 

WxWidgets lesson 13 wxMemoryDC uses cached DC rendering

Shulou Source: shulou.com Published: 2022-06-02 09:50:53 10月01日 Update

Description

Using wxMemoryDC rendering, you can reduce flicker, and when the rendering is complete, paste the content onto the target DC, where wxBitmap is needed as the canvas. The effect is equivalent to using wxBufferedPaintDC, but wxBufferedPaintDC is limited to use in OnPaint functions

Code

WxRect rect = GetClientRect ()

Int width = rect.GetWidth ()

Int height = rect.GetHeight ()

WxMemoryDC memDC

WxBitmap bitmap (width, height)

MemDC.SelectObject (bitmap)

MemDC.SetBackground (* wxWHITE_BRUSH)

MemDC.Clear ()

MemDC.SetPen (* wxRED_PEN)

MemDC.SetBrush (* wxRED_BRUSH)

MemDC.DrawRectangle ((wxRect (0,10, width, 100))

WxClientDC destDC (this)

DestDC.Blit (0,0

Bitmap.GetWidth (), bitmap.GetHeight ()

& memDC

0, 0

WxCOPY

True)

MemDC.SelectObject (wxNullBitmap)

A reminder

By default, the memDC background is black

WxScreenDC screen device environment

Description

WxScreenDC supports drawing graphics outside the program window and rendering in other DC, aiming at the client area of the program, not the screen. In order to map points to the screen, you need to use the ClientToScreen function to convert coordinates.

Code

WxPoint pt = ClientToScreen (GetPosition ())

Pt.x = pt.x + GetSize () .GetWidth ()

Pt.y = pt.y + GetSize () .GetHeight ()

WxSize size (100,100)

WxRect rect (pt, size)

WxScreenDC dc

Dc.SetPen (wxPen (* wxLIGHT_GREY, 2, wxSOLID))

/ / dc.SetBrush (* wxTRANSPARENT_BRUSH)

Dc.SetBrush (wxBrush (* wxBLACK))

Dc.DrawRectangle (rect)

WxClientDC wxPaintDC

Description

WxClientDC allows access to the device environment handle in the client area outside the OnPaint event, and you can see from the erase background event that wxPaintDC is in the OnPaint event

Device environment handle for internal access to the client area

Here we need to explain the client area: for a control, the size of the client area is the size of the control itself. If you customize the OnPaint event, it is only rendered within the control area. For windows, the client area does not include the title bar, menu bar, status bar and toolbars, and certainly does not include borders (this is important for dragging borders to zoom in at any time)

Tags: Customer event screen control environment device code function handle size program background border important content area just graphics coordinates that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei vpn Linux Microsoft