Skip to content

Commit 61b732c

Browse files
committed
reduce memory leaks on m_hwndRubberBand
1 parent b56e15b commit 61b732c

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Diff for: src/MRadWindow.hpp

+7-13
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class MRadCtrl : public MWindowBase
7070
public:
7171
DWORD m_dwMagic; // magic number to verify the instance
7272
BOOL m_bTopCtrl; // is it a top control?
73-
HWND m_hwndRubberBand; // the rubber band window
73+
MRubberBand m_hwndRubberBand; // the rubber band window
7474
BOOL m_bMoving; // is it moving?
7575
BOOL m_bSizing; // is it resizing?
7676
BOOL m_bLocking; // is it locked?
@@ -79,7 +79,7 @@ class MRadCtrl : public MWindowBase
7979
INT m_nImageType; // the image type
8080

8181
// constructor
82-
MRadCtrl() : m_dwMagic(0xDEADFACE), m_bTopCtrl(FALSE), m_hwndRubberBand(NULL),
82+
MRadCtrl() : m_dwMagic(0xDEADFACE), m_bTopCtrl(FALSE),
8383
m_bMoving(FALSE), m_bSizing(FALSE), m_bLocking(FALSE), m_nIndex(-1)
8484
{
8585
m_pt.x = m_pt.y = -1;
@@ -182,12 +182,7 @@ class MRadCtrl : public MWindowBase
182182
// get the rubber band that is associated to the MRadCtrl
183183
MRubberBand *GetRubberBand()
184184
{
185-
MWindowBase *base = GetUserData(m_hwndRubberBand);
186-
if (base)
187-
{
188-
return static_cast<MRubberBand *>(base);
189-
}
190-
return NULL;
185+
return m_hwndRubberBand.m_hwnd ? &m_hwndRubberBand : NULL;
191186
}
192187

193188
// get the MRadCtrl from a window handle
@@ -224,7 +219,7 @@ class MRadCtrl : public MWindowBase
224219

225220
// destroy the rubber band of the control
226221
DestroyWindow(pCtrl->m_hwndRubberBand);
227-
pCtrl->m_hwndRubberBand = NULL;
222+
pCtrl->m_hwndRubberBand.m_hwnd = NULL;
228223
}
229224
}
230225

@@ -260,7 +255,7 @@ class MRadCtrl : public MWindowBase
260255
MRubberBand *band = GetRubberBand();
261256
if (band)
262257
DestroyWindow(*band);
263-
m_hwndRubberBand = NULL;
258+
m_hwndRubberBand.m_hwnd = NULL;
264259

265260
// remove the control from targets
266261
GetTargets().erase(m_hwnd);
@@ -284,9 +279,8 @@ class MRadCtrl : public MWindowBase
284279
return;
285280

286281
// create the rubber band for the control
287-
auto band = new MRubberBand;
288-
band->CreateDx(GetParent(hwnd), hwnd, TRUE);
289-
pCtrl->m_hwndRubberBand = *band;
282+
::DestroyWindow(pCtrl->m_hwndRubberBand);
283+
pCtrl->m_hwndRubberBand.CreateDx(GetParent(hwnd), hwnd, TRUE);
290284

291285
// if not group box
292286
if (!MRadCtrl::IsGroupBox(hwnd))

0 commit comments

Comments
 (0)