fixed more memory and GDI handle leaks

svn path=/trunk/; revision=5791
This commit is contained in:
Martin Fuchs 2003-08-23 10:02:38 +00:00
parent 594afa2f55
commit b457e5103c
6 changed files with 36 additions and 30 deletions

View file

@ -841,28 +841,22 @@ int Pane::Notify(int id, NMHDR* pnmh)
OutputWorker::OutputWorker()
{
HDC hdc = GetDC(0);
_hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Sans Serif"));
ReleaseDC(0, hdc);
_hfont = CreateFont(-MulDiv(8,GetDeviceCaps(WindowCanvas(0),LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Sans Serif"));
}
void OutputWorker::init_output(HWND hwnd)
{
TCHAR b[16];
HFONT old_font;
HDC hdc = GetDC(hwnd);
WindowCanvas canvas(hwnd);
if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
_num_sep = b[1];
else
_num_sep = TEXT('.');
old_font = SelectFont(hdc, _hfont);
GetTextExtentPoint32(hdc, TEXT(" "), 1, &_spaceSize);
SelectFont(hdc, old_font);
ReleaseDC(hwnd, hdc);
FontSelection font(canvas, _hfont);
GetTextExtentPoint32(canvas, TEXT(" "), 1, &_spaceSize);
}

View file

@ -96,7 +96,7 @@ void QuickLaunchBar::AddShortcuts()
_dir->smart_scan();
ShellFolder desktop_folder;
HDC hdc_wnd = GetDC(_hwnd);
WindowCanvas canvas(_hwnd);
TBBUTTON btn = {-2/*I_IMAGENONE*/, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
@ -110,7 +110,7 @@ void QuickLaunchBar::AddShortcuts()
ShellEntry* shell_entry = static_cast<ShellEntry*>(entry);
const String& entry_name = desktop_folder.get_name(shell_entry->_pidl);
HBITMAP hbmp = create_bitmap_from_icon(shell_entry->_hIcon, GetSysColorBrush(COLOR_BTNFACE), hdc_wnd);
HBITMAP hbmp = create_bitmap_from_icon(shell_entry->_hIcon, GetSysColorBrush(COLOR_BTNFACE), canvas);
TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
@ -132,8 +132,6 @@ void QuickLaunchBar::AddShortcuts()
SendMessage(_hwnd, TB_INSERTBUTTON, idx, (LPARAM)&btn);
}
}
ReleaseDC(_hwnd, hdc_wnd);
}
LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)

View file

@ -304,7 +304,7 @@ void StartMenu::AddButton(LPCTSTR title, HICON hIcon, bool hasSubmenu, UINT id,
}
// widen window, if it is too small
int width = StartMenuButton::GetTextWidth(title) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
int width = StartMenuButton::GetTextWidth(title,_hwnd) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
ClientRect clnt(_hwnd);
if (width > clnt.right)
@ -436,15 +436,13 @@ void StartMenu::CloseStartMenu(int id)
}
int StartMenuButton::GetTextWidth(LPCTSTR title)
int StartMenuButton::GetTextWidth(LPCTSTR title, HWND hwnd)
{
HDC hdc = GetDC(0);
FontSelection font(hdc, GetStockFont(DEFAULT_GUI_FONT));
WindowCanvas canvas(hwnd);
FontSelection font(canvas, GetStockFont(DEFAULT_GUI_FONT));
RECT rect = {0, 0, 0, 0};
DrawText(hdc, title, -1, &rect, DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
ReleaseDC(0, hdc);
DrawText(canvas, title, -1, &rect, DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
return rect.right-rect.left;
}

View file

@ -44,7 +44,14 @@
struct StartMenuDirectory
{
StartMenuDirectory(const ShellDirectory& dir, bool subfolders=true)
: _dir(dir), _subfolders(subfolders) {}
: _dir(dir), _subfolders(subfolders)
{
}
~StartMenuDirectory()
{
_dir.free_subentries();
}
ShellDirectory _dir;
bool _subfolders;
@ -72,7 +79,7 @@ struct StartMenuButton : public OwnerdrawnButton
StartMenuButton(HWND hwnd, HICON hIcon, bool hasSubmenu)
: super(hwnd), _hIcon(hIcon), _hasSubmenu(hasSubmenu) {}
static int GetTextWidth(LPCTSTR title);
static int GetTextWidth(LPCTSTR title, HWND hwnd);
protected:
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);

View file

@ -236,9 +236,7 @@ BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam)
found->second._id = pThis->_next_id++;
} else {
HICON hIcon = get_window_icon(hwnd);
HDC hdc_wnd = GetDC(pThis->_htoolbar);
HBITMAP hbmp = create_bitmap_from_icon(hIcon, GetSysColorBrush(COLOR_BTNFACE), hdc_wnd);
ReleaseDC(pThis->_htoolbar, hdc_wnd);
HBITMAP hbmp = create_bitmap_from_icon(hIcon, GetSysColorBrush(COLOR_BTNFACE), WindowCanvas(pThis->_htoolbar));
TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
int bmp_idx = SendMessage(pThis->_htoolbar, TB_ADDBITMAP, 1, (LPARAM)&ab);

View file

@ -186,9 +186,6 @@ protected:
HWND _hwnd;
};
// double buffering classes
struct Canvas
{
Canvas(HDC hdc) : _hdc(hdc) {}
@ -199,6 +196,20 @@ protected:
HDC _hdc;
};
struct WindowCanvas : public Canvas
{
WindowCanvas(HWND hwnd)
: Canvas(GetDC(hwnd)), _hwnd(hwnd) {}
~WindowCanvas() {ReleaseDC(_hwnd, _hdc);}
protected:
HWND _hwnd;
};
// double buffering classes
struct MemCanvas : public Canvas
{
MemCanvas(HDC hdc=0)