Device context overview
Classes: wxBufferedDC, wxBufferedPaintDC, wxDC, wxPostScriptDC, wxMetafileDC, wxMemoryDC, wxPrinterDC, wxScreenDC, wxClientDC, wxPaintDC, wxWindowDC.
A wxDC is a device context onto which graphics and text can be drawn.The device context is intended to represent a number of output devices in a generic way,with the same API being used throughout.
Some device contexts are created temporarily in order to draw on a window.This is true of wxScreenDC, wxClientDC, wxPaintDC,and wxWindowDC. The following describes the differences betweenthese device contexts and when you should use them.
- wxScreenDC. Use this to paint on the screen, as opposed to an individual window.
- wxClientDC. Use this to paint on the client area of window (the part withoutborders and other decorations), but do not use it from within an wxPaintEvent.
- wxPaintDC. Use this to paint on the client area of a window, but only fromwithin a wxPaintEvent.
- wxWindowDC. Use this to paint on the whole area of a window, including decorations.This may not be available on non-Windows platforms.
To use a client, paint or window device context, create an object on the stack withthe window as argument, for example:
void MyWindow::OnMyCmd(wxCommandEvent& event) { wxClientDC dc(window); DrawMyPicture(dc); }
Try to write code so it is parameterised by wxDC - if you do this, the same piece of code maywrite to a number of different devices, by passing a different device context. This doesn'twork for everything (for example not all device contexts support bitmap drawing) butwill work most of the time.