Let’s pay a quick visit to our continuing dictionary project. One of the things you may have noticed is that the Chinese characters are unreadably small. Let’s fix that by making them larger.
class RootWindow : public Window { public: virtual LPCTSTR ClassName() { return TEXT(“Scratch”); } static RootWindow *Create(); RootWindow(); ~RootWindow(); … private: HWND m_hwndLV; HWND m_hwndEdit; HWND m_hwndLastFocus; HFONT m_hfChinese; int m_cyEdit; … }RootWindow::RootWindow() : m_hfChinese(NULL) { }
RootWindow::~RootWindow() { if (m_hfChinese) DeleteObject(m_hfChinese); }
LRESULT RootWindow::OnCreate() { … ListView_SetExtendedListViewStyleEx(m_hwndLV, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
LOGFONT lf; if (!GetObject(GetWindowFont(m_hwndLV), sizeof(lf), &lf)) { return -1; } lf.lfHeight += lf.lfHeight / 2; // 50% bigger m_hfChinese = CreateFontIndirect(&lf); if (!m_hfChinese) return -1; SetWindowFont(m_hwndLV, m_hfChinese, FALSE);
LVCOLUMN lvc; … }
This magnifies the font in the list view by 50% by taking the current font, increasing the height, and creating a new font, which we select into the list view.
This works in that the font is indeed bigger, but it’s bigger even for the English part, and that larger-than-normal English font looks kind of out of place. The English was perfectly fine at its original size, after all. It was only the Chinese we wanted to enlarge. (This will become more important later on when we turn the program into a dynamic translator.)
We’ll look at this problem next time.
[Raymond is currently away; this message was pre-recorded.]
0 comments