Allow run-time font changing.

This commit is contained in:
Erik Faye-Lund 2009-01-14 15:30:15 +00:00
parent 60ee9553d4
commit 0ec7daf2c1
2 changed files with 13 additions and 8 deletions

View File

@ -19,8 +19,15 @@ void TrackView::setFont(HFONT font)
{ {
this->font = font; this->font = font;
rowHeight = 16; assert(NULL != hwnd);
fontWidth = 6; HDC hdc = GetDC(hwnd);
SelectObject(hdc, font);
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
rowHeight = tm.tmHeight + tm.tmExternalLeading;
fontWidth = tm.tmAveCharWidth;
trackWidth = fontWidth * 16; trackWidth = fontWidth * 16;
} }
@ -49,11 +56,6 @@ TrackView::TrackView()
this->hwnd = NULL; this->hwnd = NULL;
// setFont((HFONT)GetStockObject(SYSTEM_FONT));
setFont((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
// font = (HFONT)GetStockObject(SYSTEM_FONT);
// font = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
bgBaseBrush = GetSysColorBrush(COLOR_WINDOW); bgBaseBrush = GetSysColorBrush(COLOR_WINDOW);
bgDarkBrush = CreateSolidBrush(darken(GetSysColor(COLOR_WINDOW), 0.9f)); bgDarkBrush = CreateSolidBrush(darken(GetSysColor(COLOR_WINDOW), 0.9f));
@ -99,6 +101,9 @@ int TrackView::getScreenX(size_t track) const
LRESULT TrackView::onCreate() LRESULT TrackView::onCreate()
{ {
// setFont((HFONT)GetStockObject(SYSTEM_FONT));
setFont((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
setupScrollBars(); setupScrollBars();
return FALSE; return FALSE;
} }

View File

@ -155,7 +155,7 @@ private:
int rowHeight; int rowHeight;
int fontWidth; int fontWidth;
int trackWidth; int trackWidth;
HBRUSH bgBaseBrush, bgDarkBrush; HBRUSH bgBaseBrush, bgDarkBrush;
HBRUSH selectBaseBrush, selectDarkBrush; HBRUSH selectBaseBrush, selectDarkBrush;
HPEN rowPen, rowSelectPen; HPEN rowPen, rowSelectPen;