Added (and applied) standard Windows fonts.

This commit is contained in:
Pietro Gagliardi 2014-07-18 11:20:18 -04:00
parent 489ce0a053
commit f64f2781ce
5 changed files with 38 additions and 3 deletions

View File

@ -31,6 +31,11 @@ void controlSetParent(HWND control, HWND parent)
xpanic("error changing control parent", GetLastError());
}
void controlSetControlFont(HWND which)
{
SendMessageW(which, WM_SETFONT, (WPARAM) controlFont, TRUE);
}
/*
all controls that have events receive the events themselves through subclasses
to do this, all windows (including the message-only window; see http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q104069) forward WM_COMMAND to each control with this function

View File

@ -67,6 +67,7 @@ func newButton(text string) *Request {
C.BS_PUSHBUTTON | C.WS_TABSTOP,
0)
C.setWindowText(w.hwnd, toUTF16(text))
C.controlSetControlFont(w.hwnd)
b := &button{
widgetbase: w,
clicked: newEvent(),

View File

@ -8,9 +8,16 @@ int nCmdShow;
HICON hDefaultIcon;
HCURSOR hArrowCursor;
HFONT controlFont;
HFONT titleFont;
HFONT smallTitleFont;
HFONT menubarFont;
HFONT statusbarFont;
DWORD initWindows(char **errmsg)
{
STARTUPINFOW si;
NONCLIENTMETRICSW ncm;
/* WinMain() parameters */
hInstance = GetModuleHandleW(NULL);
@ -35,5 +42,24 @@ DWORD initWindows(char **errmsg)
return GetLastError();
}
/* standard fonts */
#define GETFONT(l, f, n) l = CreateFontIndirectW(&ncm.f); \
if (l == NULL) { \
*errmsg = "error loading " n " font"; \
return GetLastError(); \
}
ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW));
ncm.cbSize = sizeof (NONCLIENTMETRICSW);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) {
*errmsg = "error getting non-client metrics parameters";
return GetLastError();
}
GETFONT(controlFont, lfMessageFont, "control");
GETFONT(titleFont, lfCaptionFont, "titlebar");
GETFONT(smallTitleFont, lfSmCaptionFont, "small title bar");
GETFONT(menubarFont, lfMenuFont, "menu bar");
GETFONT(statusbarFont, lfStatusFont, "status bar");
return 0;
}

View File

@ -10,12 +10,9 @@ HDC getDC(HWND hwnd)
dc = GetDC(hwnd);
if (dc == NULL)
xpanic("error getting DC for preferred size calculations", GetLastError());
/* TODO */
/* TODO save for restoring later */
/*
if (SelectObject(dc, controlFont) == NULL)
xpanic("error loading control font into device context for preferred size calculation", GetLastError());
*/
return dc;
}

View File

@ -40,6 +40,7 @@ extern LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM);
/* controls_windows.c */
extern HWND newWidget(LPCWSTR, DWORD, DWORD);
extern void controlSetParent(HWND, HWND);
extern void controlSetControlFont(HWND);
extern LRESULT forwardCommand(HWND, UINT, WPARAM, LPARAM);
extern void setButtonSubclass(HWND, void *);
@ -48,6 +49,11 @@ extern HINSTANCE hInstance;
extern int nCmdShow;
extern HICON hDefaultIcon;
extern HCURSOR hArrowCursor;
extern HFONT controlFont;
extern HFONT titleFont;
extern HFONT smallTitleFont;
extern HFONT menubarFont;
extern HFONT statusbarFont;
extern DWORD initWindows(char **);
/* sizing_windows.c */