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
{
DECLARE_DYNAMIC_CLASS(wxDC)
public:
wxDC();
~wxDC();
@@ -224,6 +222,20 @@ protected:
WXHBRUSH m_oldBrush;
WXHFONT m_oldFont;
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

View File

@@ -773,8 +773,7 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
wxListBoxItem *pItem = (wxListBoxItem *)data;
wxDC dc;
dc.SetHDC((WXHDC)pStruct->hDC, FALSE);
wxDCTemp dc((WXHDC)pStruct->hDC);
wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top),
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 );
// prepare to call OnDrawItem()
wxDC dc;
dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
// prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
// the DC from being released
wxDCTemp dc((WXHDC)pDrawStruct->hDC);
wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
return pMenuItem->OnDrawItem
(
dc, rect,
dc,
rect,
(wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
(wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
);
@@ -3103,9 +3104,8 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
if ( ::IsIconic(GetHwnd()) )
return TRUE;
wxDC dc;
wxDCTemp dc(hdc);
dc.SetHDC(hdc);
dc.SetWindow(this);
dc.BeginDrawing();
@@ -3114,8 +3114,9 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
bool rc = GetEventHandler()->ProcessEvent(event);
dc.EndDrawing();
// must be called manually as ~wxDC doesn't do anything for wxDCTemp
dc.SelectOldObjects(hdc);
dc.SetHDC((WXHDC) NULL);
return rc;
}