Sorry if this is a really silly question but I am new to all this - how on earth do I determine the font that CMFCButton is using?
I have some CMFCButton, CEdit and CStatic controls on my window (created programatically in my widow OnCreate handler).
The font that the CMFCButton uses is totally different to the other two. It's nice and I want the CEdit and CStatic to look the same - in fact all the CMFCblah controls look nice - it's just the others that have the old plain font.
Anyway at first I thought I could try out setting the font using whatever the CMFCButton is using:
CFont *bf = my_button->GetFont();
Then derive a copy in the usual way (get logfont then create a new cfont and createindirect...)
However the CMFCButton GetFont() method returns NULL- even though I call it after invoking its Create() method - so it should be established proper right???
In any case I should not need to clone the font from a button - I should use the same method that the button itself uses to determine its font.
So - how do I determine the font in the same way that CMFCButton does?
GarethSaturday, March 27, 2010 7:37 PM
I think you could use GetWindowDC() then call GetCurrentFont() to determine the font assigned to a window. Worth a try anyway.
Monday, March 29, 2010 11:16 PM
- Proposed as answer by Yi Feng, Li Thursday, April 01, 2010 2:34 AM
Your question is insteresting. I have tried your way to "getFont" from a CButton object, it returns a "NON-NULL" CFont. The font name I get from my case is "MS Shell Dlg 2", following is the way I used to get it. In the sample code I get the font (font1) from Button1, then I use createPointFont to create another font, font2, and set it to Button2.
LOGFONT lFont; //structure defines the attributes of a font
//get font form Button1
CFont *font1 = GetDlgItem(IDC_BUTTON1)->GetFont();
//get name of font1
//Create font2 using the font1's name
CFont *font2 = new CFont();
CString fName =CString(lFont.lfFaceName);
VERIFY(font2->CreatePointFont(120, fName));// set size =120
//set to Button2
Acctually, I think you can direct set font1 to Button2, if you just want clone the font.
If I misunderstand your questions, please let me know.
CherubimTuesday, March 30, 2010 7:13 AM
In the end I subclassed the CMFCButton (amongst other controls) and passed the font type I needed from an application global.
But is there a way to get the font from the theme? I looked through the api's for theming but don't see anything obvious.Tuesday, April 27, 2010 12:55 PM