본문 바로가기

Windows/MFC

윈도우 기본 폰트 가져오기 GetStockObject(DEFAULT_GUI_FONT)

Link : http://www.winprog.org/tutorial/fonts.html

Choosing Fonts
In general, any program that deals with fonts will want to let the user choose their own font, as well as the colour and style attribute to use when displaying it.
Like the common dialogs for getting open and save file names, there is a common dialog for choosing a font. This is, oddly enough, called ChooseFont() and it works with the CHOOSEFONT structure for you to set the defaults it should start with as well as returning the final result of the users selection.

HFONT g_hfFont = GetStockObject(DEFAULT_GUI_FONT);
COLORREF g_rgbText = RGB(0, 0, 0);

void DoSelectFont(HWND hwnd)
{
    CHOOSEFONT cf = {sizeof(CHOOSEFONT)};
    LOGFONT lf;

    GetObject(g_hfFont, sizeof(LOGFONT), &lf);

    cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
    cf.hwndOwner = hwnd;
    cf.lpLogFont = &lf;
    cf.rgbColors = g_rgbText;

    if(ChooseFont(&cf))
    {
        HFONT hf = CreateFontIndirect(&lf);
        if(hf)
        {
            g_hfFont = hf;
        }
        else
        {
            MessageBox(hwnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
        }

        g_rgbText = cf.rgbColors;
    }
}

'Windows > MFC' 카테고리의 다른 글

GDI+ (Font Class Unit)  (0) 2013.10.02
GDI+ (Font Class FontStyle)  (0) 2013.10.02
GDI+ 용 Double Buffering (더블 버퍼링)  (0) 2013.10.02
Double buffering (더블 버퍼링)  (0) 2013.10.02
SWFLIB - a free Flash authoring library  (0) 2013.10.02