HFONT

2008-12-16 9 views
13

Win32 API ve C/C++ kullanmasını HFONT modifiye oluşturun. Bir HFONT var ve yeni bir HFONT oluşturmak için kullanmak istiyorum. Yeni yazı o cesur olması gerektiğini haricinde tam aynı yazı tipi ölçülerine kullanmalıdır. Bir şey gibi:HFONT

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

"GetLogicalFont" eksik API'sıdır (bildiğim kadarıyla zaten söyleyebilirim gibi). Bunu yapmanın başka yolu var mı? Tercihen, Windows Mobile 5+ üzerinde çalışan bir şey.

cevap

8

Böyle bir şey - hata denetimi okuyucu için bir egzersiz olarak bırakıldığını unutmayın. :-)

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); 
}