How do I know which font is used in dialog box
-
I would expect that if I use: CClientDC dc(this); inside the code for a dialog box it would pick up the font used for that dialog box. In fact, it doesn't. I had to add: currFont.CreatePointFont(80, "MS Sans Serif", &dc); oldFont = dc.SelectObject(&currFont); and then it measured the text extent correctly. (I got the font name and size from the dialog template.) Clearly, it won't change unless I change it in the project, but I am curious to know how to pick up the information "automatically". Any suggestions? Thanks, Ilan
-
I would expect that if I use: CClientDC dc(this); inside the code for a dialog box it would pick up the font used for that dialog box. In fact, it doesn't. I had to add: currFont.CreatePointFont(80, "MS Sans Serif", &dc); oldFont = dc.SelectObject(&currFont); and then it measured the text extent correctly. (I got the font name and size from the dialog template.) Clearly, it won't change unless I change it in the project, but I am curious to know how to pick up the information "automatically". Any suggestions? Thanks, Ilan
dc.SelectObject(GetFont()); ? Igor Green http://www.grigsoft.com/ - files and folders comparison tools
-
dc.SelectObject(GetFont()); ? Igor Green http://www.grigsoft.com/ - files and folders comparison tools
-
Thanks. I didn't think it was that simple. It must be internally this.GetFont(), otherwise I don't know how it could figure out which font I want. In any case, it works.... Ilan
You are right - CWnd::GetFont() returns current font for window. This font is not selected automatically in compatible DC on creation. Igor Green http://www.grigsoft.com/ - files and folders comparison tools
-
dc.SelectObject(GetFont()); ? Igor Green http://www.grigsoft.com/ - files and folders comparison tools
As an aside, i ran into this earlier this week in a WinCE (PocketPC 2002) app i was working on. I found that calling CWnd::GetFont() for a CDialog window always returned NULL. Turns out this is expected (from MSDN WM_GETFONT for WinCE): The WM_GETFONT message does not return a font handle if the message is sent to a dialog box created by the DialogBoxParam, DialogBoxIndirectParam, CreateDialogParam, or CreateDialogIndirectParam functions. ...cmk Save the whales - collect the whole set