{
switch(nmsg) {
case WM_PAINT: {
- PAINTSTRUCT ps;
- draw_desktop_background(_hwnd, BeginPaint(_hwnd, &ps));
- EndPaint(_hwnd, &ps);
+ PaintCanvas canvas(_hwnd);
+ draw_desktop_background(_hwnd, canvas);
break;}
case WM_LBUTTONDBLCLK:
: super(hwnd),
WM_TASKBARCREATED(RegisterWindowMessage(WINMSG_TASKBARCREATED))
{
+ SystemParametersInfo(SPI_GETWORKAREA, 0, &_work_area_org, 0);
}
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
PostQuitMessage(0);
}
WindowRect rect(_hwnd);
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);
break;}
protected:
int WM_TASKBARCREATED;
+ RECT _work_area_org;
LRESULT Init(LPCREATESTRUCT pcs);
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
void NotifyArea::Paint()
{
- BufferedPaintCanvas canvas(_hwnd);
+ PaintCanvas canvas(_hwnd);
// first fill with the background color
FillRect(canvas, &canvas.rcPaint, GetSysColorBrush(COLOR_BTNFACE));
if (_tcscmp(buffer, _time)) {
_tcscpy(_time, buffer);
- return true;
+ return true; // The text to display has changed.
}
return false; // no change
PaintCanvas canvas(_hwnd);
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);
}
BeginPaint(hwnd, this);
}
- PaintCanvas()
+ ~PaintCanvas()
{
EndPaint(_hwnd, this);
}
SelectedBitmap(HDC hdc, HBITMAP hbmp)
: _hdc(hdc), _old_hbmp(SelectBitmap(hdc, hbmp)) {}
- ~SelectedBitmap() {SelectBitmap(_hdc, _old_hbmp);}
+ ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc, _old_hbmp));}
protected:
HDC _hdc;
struct BufferedPaintCanvas : public PaintCanvas, public BufferedCanvas
{
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;}
};
COLORREF _old_bkmode;
};
-struct SelectedFont
+struct FontSelection
{
- SelectedFont(HDC hdc, HFONT hFont)
+ FontSelection(HDC hdc, HFONT hFont)
: _hdc(hdc), _old_hFont(SelectFont(hdc, hFont)) {}
- ~SelectedFont() {SelectFont(_hdc, _old_hFont);}
+ ~FontSelection() {SelectFont(_hdc, _old_hFont);}
protected:
HDC _hdc;
{
switch(nmsg) {
case WM_PAINT: {
- PAINTSTRUCT ps;
- HBRUSH lastBrush;
+ PaintCanvas canvas(_hwnd);
ClientRect rt(_hwnd);
- BeginPaint(_hwnd, &ps);
rt.left = _split_pos-SPLIT_WIDTH/2;
rt.right = _split_pos+SPLIT_WIDTH/2+1;
- lastBrush = SelectBrush(ps.hdc, GetStockBrush(COLOR_SPLITBAR));
- Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
- SelectObject(ps.hdc, lastBrush);
- EndPaint(_hwnd, &ps);
+ HBRUSH lastBrush = SelectBrush(canvas, GetStockBrush(COLOR_SPLITBAR));
+ Rectangle(canvas, rt.left, rt.top-1, rt.right, rt.bottom+1);
+ SelectObject(canvas, lastBrush);
break;}
case WM_SETCURSOR: