mirror of
https://github.com/reactos/reactos.git
synced 2024-08-07 19:58:21 +00:00
fixed GDI handle leaks
svn path=/trunk/; revision=5790
This commit is contained in:
parent
43fa5d1ab2
commit
594afa2f55
|
@ -197,9 +197,8 @@ LRESULT DesktopWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||||
{
|
{
|
||||||
switch(nmsg) {
|
switch(nmsg) {
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
PAINTSTRUCT ps;
|
PaintCanvas canvas(_hwnd);
|
||||||
draw_desktop_background(_hwnd, BeginPaint(_hwnd, &ps));
|
draw_desktop_background(_hwnd, canvas);
|
||||||
EndPaint(_hwnd, &ps);
|
|
||||||
break;}
|
break;}
|
||||||
|
|
||||||
case WM_LBUTTONDBLCLK:
|
case WM_LBUTTONDBLCLK:
|
||||||
|
|
|
@ -64,10 +64,15 @@ DesktopBar::DesktopBar(HWND hwnd)
|
||||||
: super(hwnd),
|
: super(hwnd),
|
||||||
WM_TASKBARCREATED(RegisterWindowMessage(WINMSG_TASKBARCREATED))
|
WM_TASKBARCREATED(RegisterWindowMessage(WINMSG_TASKBARCREATED))
|
||||||
{
|
{
|
||||||
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &_work_area_org, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopBar::~DesktopBar()
|
DesktopBar::~DesktopBar()
|
||||||
{
|
{
|
||||||
|
// restore work area to the previous size
|
||||||
|
SystemParametersInfo(SPI_SETWORKAREA, 0, &_work_area_org, 0);
|
||||||
|
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETWORKAREA, 0);
|
||||||
|
|
||||||
// exit application after destroying desktop window
|
// exit application after destroying desktop window
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +171,7 @@ LRESULT DesktopBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||||
|
|
||||||
WindowRect rect(_hwnd);
|
WindowRect rect(_hwnd);
|
||||||
RECT work_area = {0, 0, GetSystemMetrics(SM_CXSCREEN), rect.top};
|
RECT work_area = {0, 0, GetSystemMetrics(SM_CXSCREEN), rect.top};
|
||||||
SystemParametersInfo(SPI_SETWORKAREA, 0, &work_area, 0);
|
SystemParametersInfo(SPI_SETWORKAREA, 0, &work_area, 0); // don't use SPIF_SENDCHANGE because then we have to wait for any message being delivered
|
||||||
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETWORKAREA, 0);
|
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETWORKAREA, 0);
|
||||||
break;}
|
break;}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ struct DesktopBar : public OwnerDrawParent<Window>
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int WM_TASKBARCREATED;
|
int WM_TASKBARCREATED;
|
||||||
|
RECT _work_area_org;
|
||||||
|
|
||||||
LRESULT Init(LPCREATESTRUCT pcs);
|
LRESULT Init(LPCREATESTRUCT pcs);
|
||||||
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
|
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
|
||||||
|
|
|
@ -220,7 +220,7 @@ void NotifyArea::Refresh()
|
||||||
|
|
||||||
void NotifyArea::Paint()
|
void NotifyArea::Paint()
|
||||||
{
|
{
|
||||||
BufferedPaintCanvas canvas(_hwnd);
|
PaintCanvas canvas(_hwnd);
|
||||||
|
|
||||||
// first fill with the background color
|
// first fill with the background color
|
||||||
FillRect(canvas, &canvas.rcPaint, GetSysColorBrush(COLOR_BTNFACE));
|
FillRect(canvas, &canvas.rcPaint, GetSysColorBrush(COLOR_BTNFACE));
|
||||||
|
@ -324,7 +324,7 @@ bool ClockWindow::FormatTime()
|
||||||
|
|
||||||
if (_tcscmp(buffer, _time)) {
|
if (_tcscmp(buffer, _time)) {
|
||||||
_tcscpy(_time, buffer);
|
_tcscpy(_time, buffer);
|
||||||
return true;
|
return true; // The text to display has changed.
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // no change
|
return false; // no change
|
||||||
|
@ -335,7 +335,7 @@ void ClockWindow::Paint()
|
||||||
PaintCanvas canvas(_hwnd);
|
PaintCanvas canvas(_hwnd);
|
||||||
|
|
||||||
BkMode bkmode(canvas, TRANSPARENT);
|
BkMode bkmode(canvas, TRANSPARENT);
|
||||||
SelectedFont font(canvas, GetStockFont(ANSI_VAR_FONT));
|
FontSelection font(canvas, GetStockFont(ANSI_VAR_FONT));
|
||||||
|
|
||||||
DrawText(canvas, _time, -1, ClientRect(_hwnd), DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
|
DrawText(canvas, _time, -1, ClientRect(_hwnd), DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ struct PaintCanvas : public PAINTSTRUCT
|
||||||
BeginPaint(hwnd, this);
|
BeginPaint(hwnd, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintCanvas()
|
~PaintCanvas()
|
||||||
{
|
{
|
||||||
EndPaint(_hwnd, this);
|
EndPaint(_hwnd, this);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ struct SelectedBitmap
|
||||||
SelectedBitmap(HDC hdc, HBITMAP hbmp)
|
SelectedBitmap(HDC hdc, HBITMAP hbmp)
|
||||||
: _hdc(hdc), _old_hbmp(SelectBitmap(hdc, hbmp)) {}
|
: _hdc(hdc), _old_hbmp(SelectBitmap(hdc, hbmp)) {}
|
||||||
|
|
||||||
~SelectedBitmap() {SelectBitmap(_hdc, _old_hbmp);}
|
~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc, _old_hbmp));}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HDC _hdc;
|
HDC _hdc;
|
||||||
|
@ -253,7 +253,10 @@ struct BufferedCanvas : public BufferCanvas
|
||||||
struct BufferedPaintCanvas : public PaintCanvas, public BufferedCanvas
|
struct BufferedPaintCanvas : public PaintCanvas, public BufferedCanvas
|
||||||
{
|
{
|
||||||
BufferedPaintCanvas(HWND hwnd)
|
BufferedPaintCanvas(HWND hwnd)
|
||||||
: PaintCanvas(hwnd), BufferedCanvas(hdc, 0, 0, rcPaint.right, rcPaint.bottom) {}
|
: PaintCanvas(hwnd),
|
||||||
|
BufferedCanvas(PAINTSTRUCT::hdc, 0, 0, rcPaint.right, rcPaint.bottom)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
operator HDC() {return BufferedCanvas::_hdc;}
|
operator HDC() {return BufferedCanvas::_hdc;}
|
||||||
};
|
};
|
||||||
|
@ -283,12 +286,12 @@ protected:
|
||||||
COLORREF _old_bkmode;
|
COLORREF _old_bkmode;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SelectedFont
|
struct FontSelection
|
||||||
{
|
{
|
||||||
SelectedFont(HDC hdc, HFONT hFont)
|
FontSelection(HDC hdc, HFONT hFont)
|
||||||
: _hdc(hdc), _old_hFont(SelectFont(hdc, hFont)) {}
|
: _hdc(hdc), _old_hFont(SelectFont(hdc, hFont)) {}
|
||||||
|
|
||||||
~SelectedFont() {SelectFont(_hdc, _old_hFont);}
|
~FontSelection() {SelectFont(_hdc, _old_hFont);}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HDC _hdc;
|
HDC _hdc;
|
||||||
|
|
|
@ -264,16 +264,13 @@ LRESULT ChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
|
||||||
{
|
{
|
||||||
switch(nmsg) {
|
switch(nmsg) {
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
PAINTSTRUCT ps;
|
PaintCanvas canvas(_hwnd);
|
||||||
HBRUSH lastBrush;
|
|
||||||
ClientRect rt(_hwnd);
|
ClientRect rt(_hwnd);
|
||||||
BeginPaint(_hwnd, &ps);
|
|
||||||
rt.left = _split_pos-SPLIT_WIDTH/2;
|
rt.left = _split_pos-SPLIT_WIDTH/2;
|
||||||
rt.right = _split_pos+SPLIT_WIDTH/2+1;
|
rt.right = _split_pos+SPLIT_WIDTH/2+1;
|
||||||
lastBrush = SelectBrush(ps.hdc, GetStockBrush(COLOR_SPLITBAR));
|
HBRUSH lastBrush = SelectBrush(canvas, GetStockBrush(COLOR_SPLITBAR));
|
||||||
Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
|
Rectangle(canvas, rt.left, rt.top-1, rt.right, rt.bottom+1);
|
||||||
SelectObject(ps.hdc, lastBrush);
|
SelectObject(canvas, lastBrush);
|
||||||
EndPaint(_hwnd, &ps);
|
|
||||||
break;}
|
break;}
|
||||||
|
|
||||||
case WM_SETCURSOR:
|
case WM_SETCURSOR:
|
||||||
|
|
Loading…
Reference in a new issue