Question on use of TextMetricsW

James McKenzie jjmckenzie51 at earthlink.net
Sun Oct 3 15:10:12 CDT 2010


  On 10/3/10 11:55 AM, Paul Vriens wrote:
> On 10/03/2010 08:44 PM, James McKenzie wrote:
>> All:
>>
>> I am running code like the following in a richedit control to set the
>> font to Courier 12 point font:
>>
>>
>> + static const WCHAR courier[] = {'C','o','u','r','i','e','r',0};
>> + testFont1 = CreateFontW (12,0,0,0,FW_LIGHT, 0, 0, 0, ANSI_CHARSET,
>> + OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
>> DEFAULT_PITCH |
>> + FF_DONTCARE, courier);
>> +
>> + /*Set test font to be Courier font */
>> + SendMessageW(hwndRichEdit, WM_SETFONT, (WPARAM)testFont1,
>> MAKELPARAM(TRUE, 0));
>> + /*Verify font is set */
>> + SendMessageW(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)
>> &CharFont1Unicode);
>> + GetObjectW(testFont1, sizeof(LOGFONTW), &sentLogFont);
>> + ok (!lstrcmpW(sentLogFont.lfFaceName, CharFont1Unicode.szFaceName),
>> "WM_SETFONT set wrong font. " \
>> + "Font was set to %s or %s, was supposed to be \"Courier\".\n",
>> wine_dbgstr_w(CharFont1Unicode.szFaceName),
>> wine_dbgstr_w(sentLogFont.lfFaceName));
>> +
>> + ret = GetTextMetricsW (hdc, &tmw);
>> + ok (ret, "GetTextMetricsW failed\n");
>> +
>> + ok (7 == tmw.tmAveCharWidth, "Average Character Width for Courier 12
>> is %d\n", tmw.tmAveCharWidth);
>>
>> I also set the font to MS Sans Serif, and two different font sizes for
>> Arial. However, the tmAveCharWidth value remains at 7 and I am of the
>> opinion that this should change for each font change and also for the
>> font size change. Am I doing something improper? Should I clear the tmw
>> structure between calls to GetTextMetricsW?
>>
>> When I run this on native WindowsXP (which I have access to) the average
>> character width changes to 9, but remains the same for all four font 
>> types.
>> TTIA.
>>
>> James McKenzie
>>
>>
>>
> Hi James,
>
> Doesn't the WM_SETFONT only set it for the control? You are retrieving 
> the font characteristics from the DC though.
>
Even if I am retrieving the DC for the control through:

hdc = GetDC(hwndRichEdit) and hwndRichEdit is the handle to the control?

Just trying to get a grasp on where GetTextMetricsW is getting its 
information from.

James McKenzie




More information about the wine-devel mailing list