2008-12-16 3 views
13

Ich verwende die Win32 API und C/C++. Ich habe eine HFONT und möchte damit eine neue HFONT erstellen. Die neue Schriftart sollte genau die gleichen Schriftmetriken verwenden, außer dass sie fett dargestellt werden sollte. Etwas wie:Erstellen Sie eine modifizierte HFONT von HFONT

HFONT CreateBoldFont(HFONT hFont) { 
    LOGFONT lf; 
    GetLogicalFont(hFont, &lf); 
    lf.lfWeight = FW_BOLD; 
    return CreateFontIndirect(&lf); 
} 

Die „GetLogicalFont“ ist die fehlende API (soweit ich das sagen kann, sowieso). Gibt es einen anderen Weg, es zu tun? Vorzugsweise etwas, das auf Windows Mobile 5+ funktioniert.

Antwort

8

So etwas - beachten Sie, dass die Fehlerprüfung als Übung für den Leser bleibt. :-)

static HFONT CreateBoldWindowFont(HWND window) 
{ 
    const HFONT font = (HFONT)::SendMessage(window, WM_GETFONT, 0, 0); 
    LOGFONT fontAttributes = { 0 }; 
    ::GetObject(font, sizeof(fontAttributes), &fontAttributes); 
    fontAttributes.lfWeight = FW_BOLD; 

    return ::CreateFontIndirect(&fontAttributes); 
} 

static void PlayWithBoldFont() 
{ 
    const HFONT boldFont = CreateBoldWindowFont(someWindow); 
    . 
    . // Play with it! 
    . 
    ::DeleteObject(boldFont); 
} 
Verwandte Themen