1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxClientDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcclient.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dcclient.h"
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
33 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
34 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
41 wxWindowDC::wxWindowDC(void)
46 wxWindowDC::wxWindowDC(wxWindow
*the_canvas
)
48 m_canvas
= the_canvas
;
49 // m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW);
50 m_hDC
= (WXHDC
) ::GetWindowDC((HWND
) the_canvas
->GetHWND() );
53 SetBackground(wxBrush(m_canvas
->GetBackgroundColour(), wxSOLID
));
56 wxWindowDC::~wxWindowDC(void)
58 if (m_canvas
&& m_hDC
)
60 SelectOldObjects(m_hDC
);
62 ::ReleaseDC((HWND
) m_canvas
->GetHWND(), (HDC
) m_hDC
);
72 wxClientDC::wxClientDC(void)
77 wxClientDC::wxClientDC(wxWindow
*the_canvas
)
79 m_canvas
= the_canvas
;
81 m_hDC
= (WXHDC
) ::GetDC((HWND
) the_canvas
->GetHWND());
83 SetBackground(wxBrush(m_canvas
->GetBackgroundColour(), wxSOLID
));
86 wxClientDC::~wxClientDC(void)
90 if (m_canvas
&& (HDC
) m_hDC
)
92 SelectOldObjects(m_hDC
);
94 ::ReleaseDC((HWND
) m_canvas
->GetHWND(), (HDC
) m_hDC
);
103 wxPaintDC::wxPaintDC(void)
108 static PAINTSTRUCT g_paintStruct
;
110 // Don't call Begin/EndPaint if it's already been called:
111 // for example, if calling a base class OnPaint.
113 WXHDC
wxPaintDC::ms_PaintHDC
= 0;
114 size_t wxPaintDC::ms_PaintCount
= 0; // count of ms_PaintHDC usage
116 wxPaintDC::wxPaintDC(wxWindow
*canvas
)
118 wxCHECK_RET( canvas
, "NULL canvas in wxPaintDC ctor" );
121 if ( ms_PaintCount
> 0 ) {
122 // it means that we've already called BeginPaint and so we must just
123 // reuse the same HDC (BeginPaint shouldn't be called more than once)
124 wxASSERT( ms_PaintHDC
);
131 m_hDC
= (WXHDC
)::BeginPaint((HWND
)m_canvas
->GetHWND(), &g_paintStruct
);
136 SetBackground(wxBrush(m_canvas
->GetBackgroundColour(), wxSOLID
));
139 wxPaintDC::~wxPaintDC()
142 if ( !--ms_PaintCount
) {
143 ::EndPaint((HWND
)m_canvas
->GetHWND(), &g_paintStruct
);
145 m_hDC
= (WXHDC
) NULL
;
146 ms_PaintHDC
= (WXHDC
) NULL
;
148 else { }//: ms_PaintHDC still in use