]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tdc.tex
Robert Lang's patch [ 1583183 ] Fixes printing/print preview inconsistencies
[wxWidgets.git] / docs / latex / wx / tdc.tex
CommitLineData
a660d684
KB
1\section{Device context overview}\label{dcoverview}
2
d6af57d4 3Classes: \helpref{wxBufferedDC}{wxbuffereddc}, \helpref{wxBufferedPaintDC}{wxbufferedpaintdc}, \helpref{wxDC}{wxdc}, \helpref{wxPostScriptDC}{wxpostscriptdc},\rtfsp
e2a6f233 4\rtfsp\helpref{wxMetafileDC}{wxmetafiledc}, \helpref{wxMemoryDC}{wxmemorydc}, \helpref{wxPrinterDC}{wxprinterdc},\rtfsp
a660d684
KB
5\helpref{wxScreenDC}{wxscreendc}, \helpref{wxClientDC}{wxclientdc}, \helpref{wxPaintDC}{wxpaintdc},\rtfsp
6\helpref{wxWindowDC}{wxwindowdc}.
7
8A wxDC is a {\it device context} onto which graphics and text can be drawn.
9The device context is intended to represent a number of output devices in a generic way,
10with the same API being used throughout.
11
12Some device contexts are created temporarily in order to draw on a window.
13This is true of \helpref{wxScreenDC}{wxscreendc}, \helpref{wxClientDC}{wxclientdc}, \helpref{wxPaintDC}{wxpaintdc},
14and \helpref{wxWindowDC}{wxwindowdc}. The following describes the differences between
15these device contexts and when you should use them.
16
17\begin{itemize}\itemsep=0pt
18\item {\bf wxScreenDC.} Use this to paint on the screen, as opposed to an individual window.
19\item {\bf wxClientDC.} Use this to paint on the client area of window (the part without
f4fcc291 20borders and other decorations), but do not use it from within an \helpref{wxPaintEvent}{wxpaintevent}.
a660d684 21\item {\bf wxPaintDC.} Use this to paint on the client area of a window, but {\it only} from
f4fcc291 22within a \helpref{wxPaintEvent}{wxpaintevent}.
a660d684
KB
23\item {\bf wxWindowDC.} Use this to paint on the whole area of a window, including decorations.
24This may not be available on non-Windows platforms.
25\end{itemize}
26
27To use a client, paint or window device context, create an object on the stack with
28the window as argument, for example:
29
30\begin{verbatim}
31 void MyWindow::OnMyCmd(wxCommandEvent& event)
32 {
33 wxClientDC dc(window);
34 DrawMyPicture(dc);
35 }
36\end{verbatim}
37
38Try to write code so it is parameterised by wxDC - if you do this, the same piece of code may
39write to a number of different devices, by passing a different device context. This doesn't
40work for everything (for example not all device contexts support bitmap drawing) but
41will work most of the time.
42