fix for releasing the HDC in WM_DRAWITEM handler

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10261 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-05-21 23:10:31 +00:00
parent 5260937e74
commit 7561aacd5e
3 changed files with 29 additions and 17 deletions

View File

@@ -73,8 +73,6 @@
class WXDLLEXPORT wxDC : public wxDCBase class WXDLLEXPORT wxDC : public wxDCBase
{ {
DECLARE_DYNAMIC_CLASS(wxDC)
public: public:
wxDC(); wxDC();
~wxDC(); ~wxDC();
@@ -224,6 +222,20 @@ protected:
WXHBRUSH m_oldBrush; WXHBRUSH m_oldBrush;
WXHFONT m_oldFont; WXHFONT m_oldFont;
WXHPALETTE m_oldPalette; WXHPALETTE m_oldPalette;
DECLARE_DYNAMIC_CLASS(wxDC)
};
// ----------------------------------------------------------------------------
// wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWindows
// only/mainly)
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDCTemp : public wxDC
{
public:
wxDCTemp(WXHDC hdc) { SetHDC(hdc); }
virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); }
}; };
#endif #endif

View File

@@ -773,8 +773,7 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
wxListBoxItem *pItem = (wxListBoxItem *)data; wxListBoxItem *pItem = (wxListBoxItem *)data;
wxDC dc; wxDCTemp dc((WXHDC)pStruct->hDC);
dc.SetHDC((WXHDC)pStruct->hDC, FALSE);
wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top), wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top),
wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom)); wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom));

View File

@@ -2923,16 +2923,17 @@ bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
// prepare to call OnDrawItem() // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
wxDC dc; // the DC from being released
dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE); wxDCTemp dc((WXHDC)pDrawStruct->hDC);
wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
return pMenuItem->OnDrawItem return pMenuItem->OnDrawItem
( (
dc, rect, dc,
rect,
(wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
(wxOwnerDrawn::wxODStatus)pDrawStruct->itemState (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
); );
@@ -3103,9 +3104,8 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
if ( ::IsIconic(GetHwnd()) ) if ( ::IsIconic(GetHwnd()) )
return TRUE; return TRUE;
wxDC dc; wxDCTemp dc(hdc);
dc.SetHDC(hdc);
dc.SetWindow(this); dc.SetWindow(this);
dc.BeginDrawing(); dc.BeginDrawing();
@@ -3114,8 +3114,9 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
bool rc = GetEventHandler()->ProcessEvent(event); bool rc = GetEventHandler()->ProcessEvent(event);
dc.EndDrawing(); dc.EndDrawing();
// must be called manually as ~wxDC doesn't do anything for wxDCTemp
dc.SelectOldObjects(hdc); dc.SelectOldObjects(hdc);
dc.SetHDC((WXHDC) NULL);
return rc; return rc;
} }