]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{Device context overview}\label{dcoverview} |
2 | ||
3 | Classes: \helpref{wxDC}{wxdc}, \helpref{wxPostScriptDC}{wxpostscriptdc},\rtfsp | |
4 | \rtfsp\helpref{wxMetaFileDC}{wxmetafiledc}, \helpref{wxMemoryDC}{wxmemorydc}, \helpref{wxPrinterDC}{wxprinterdc},\rtfsp | |
5 | \helpref{wxScreenDC}{wxscreendc}, \helpref{wxClientDC}{wxclientdc}, \helpref{wxPaintDC}{wxpaintdc},\rtfsp | |
6 | \helpref{wxWindowDC}{wxwindowdc}. | |
7 | ||
8 | A wxDC is a {\it device context} onto which graphics and text can be drawn. | |
9 | The device context is intended to represent a number of output devices in a generic way, | |
10 | with the same API being used throughout. | |
11 | ||
12 | Some device contexts are created temporarily in order to draw on a window. | |
13 | This is true of \helpref{wxScreenDC}{wxscreendc}, \helpref{wxClientDC}{wxclientdc}, \helpref{wxPaintDC}{wxpaintdc}, | |
14 | and \helpref{wxWindowDC}{wxwindowdc}. The following describes the differences between | |
15 | these 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 | |
20 | borders and other decorations), but do not use it from within an \helpref{wxWindow::OnPaint}{wxwindowonpaint} event. | |
21 | \item {\bf wxPaintDC.} Use this to paint on the client area of a window, but {\it only} from | |
22 | within an \helpref{wxWindow::OnPaint}{wxwindowonpaint} event. | |
23 | \item {\bf wxWindowDC.} Use this to paint on the whole area of a window, including decorations. | |
24 | This may not be available on non-Windows platforms. | |
25 | \end{itemize} | |
26 | ||
27 | To use a client, paint or window device context, create an object on the stack with | |
28 | the 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 | ||
38 | Try to write code so it is parameterised by wxDC - if you do this, the same piece of code may | |
39 | write to a number of different devices, by passing a different device context. This doesn't | |
40 | work for everything (for example not all device contexts support bitmap drawing) but | |
41 | will work most of the time. | |
42 |