I am trying to scan a variety of binary resource files (.res files) for dialog box resources that match a certain size restriction in PIXELS. The problem is that the dialog resource structures supply dialog resource sizes in abstracted dialog units which the OS then converts to pixels at run-time depending on certain modes and the font used.
I start out with the following information:
dialog_units_x - dialog width in dialog units
dialog_units_y - dialog height in dialog units
font typeface name (UNICODE string)
font point size
I want to translate this information into the width and height of the dialog in PIXELS. According to MSDN, the conversion factor is like this:
dialog_pixels_x = (dialog_units_x * average_font_character_width_pixels) / 4
dialog_pixels_y = (dialog_units_y * average_font_character_height_pixels) / 8
My problem is determining the average font character width and height in pixels from the font face and point size. I have tried using a CFont and doing something like this:
Unfortunately, the data in the LOGFONT structure is also in abstracted/special units rather than pixels. I think what I probably need is the information in a TEXTMETRIC structure, but I can't tell how to get from a pointsize and typeface name to a TEXTMETRIC structure. Any ideas?
My program is a command-line app using MFC (for data structures and some API encapsulation like CFont, etc) and I plan to run it under Windows 2000, NT, and XP to analyze .res files that are used to build Windows CE images.