Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help with pixels and logical units

25 views
Skip to first unread message

mchsi

unread,
Feb 24, 2009, 5:12:57 PM2/24/09
to
writing a Win32 program in MASM32.

it is displayed on several different XP machines with different screen
resolutions.

I created a Font and understand the GetSystemMetric API to retrieve the
dimension of the screen in pixels.
what I am having problems with is occasionally on different machines the
font is too big and doesn't all fit in the
desired static control so it is cut off.

is there an easy way to determine a conversion of pixels to logical units or
simply to return an error if the messge doesn't fit
into the desired control so I can choose a smaller font.

thanks alot

john kloska

Tim Roberts

unread,
Feb 26, 2009, 2:21:47 AM2/26/09
to

Do you mean "dialog units"? If you set the mapping mode to MM_TEXT, all
your coordinates should be in pixels. You can use GetTextExtent to find
the width and height of a string, then GetClientRect to get the width and
height of your static text control.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

mchsi

unread,
Feb 26, 2009, 9:28:15 PM2/26/09
to
thanks for the info. let me playwith that and see if I can get it to work
thanks again
jon
Hello, Tim!
You wrote on Wed, 25 Feb 2009 23:21:47 -0800:

TR> "mchsi" <jkl...@mchsi.com> wrote:

>>writing a Win32 program in MASM32.

>>it is displayed on several different XP machines with different screen
>>resolutions.

>>I created a Font and understand the GetSystemMetric API to retrieve the
>>dimension of the screen in pixels.
>>what I am having problems with is occasionally on different machines
>>the
>>font is too big and doesn't all fit in the
>>desired static control so it is cut off.

>>is there an easy way to determine a conversion of pixels to logical
>>units or
>>simply to return an error if the messge doesn't fit
>>into the desired control so I can choose a smaller font.

TR> Do you mean "dialog units"? If you set the mapping mode to MM_TEXT,
TR> all
TR> your coordinates should be in pixels. You can use GetTextExtent to
TR> find
TR> the width and height of a string, then GetClientRect to get the
TR> width and
TR> height of your static text control.
TR> --
TR> Tim Roberts, ti...@probo.com
TR> Providenza & Boekelheide, Inc.

With best regards, mchsi. E-mail: jkl...@mchsi.com


Jakob Bohm

unread,
May 5, 2009, 11:22:55 AM5/5/09
to

I know this answer is a bit late, but the conversion factor between
pixels (as used in MM_TEXT mode) and "Dialog box units" for any given
dialog box font is given in knowledge base article 165478 as follows:
With the actual font used selected into a screen DC do
GetTextExtentExPointA/W (use A on Win9x, W on NT) on the specific string
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
One y-direction unit is 1/8 the height of this string, one x-direction
unit is 1/(4*52) the width of this string (See the article and do
additional testing to figure out the rounding rules). Once computed,
you only need to redo this calculation if you change the font OR your
top level window receives one of the broadcast notifications
WM_SETTINGSCHANGE (001Ah) or WM_DISPLAYCHANGE (007Eh) OR your program is
stopped OR your programs run without a window for even a brief moment
(because then you may miss a notification).

There are Windows calls that ostensibly do the conversion for you, but
some of those calls assume the default font, not the actual font used
in your dialog box.


--
Jakob Bøhm, M.Sc.Eng. * j...@danware.dk * direct tel:+45-45-90-25-33
Netop Solutions A/S * Bregnerodvej 127 * DK-3460 Birkerod * DENMARK
http://www.netop.com * tel:+45-45-90-25-25 * fax:+45-45-90-25-26
Information in this mail is hasty, not binding and may not be right.
Information in this posting may not be the official position of Netop
Solutions A/S, only the personal opinions of the author.

mchsi

unread,
May 15, 2009, 11:35:55 PM5/15/09
to
thanks
thats what I needed
John Klosak
Hello, Jakob!
You wrote on Tue, 05 May 2009 17:22:55 +0200:

JB> Tim Roberts wrote:
>> "mchsi" <jkl...@mchsi.com> wrote:
>>> writing a Win32 program in MASM32.

>>> it is displayed on several different XP machines with different
>>> screen resolutions.

>>> I created a Font and understand the GetSystemMetric API to retrieve
>>> the dimension of the screen in pixels.
>>> what I am having problems with is occasionally on different machines
>>> the font is too big and doesn't all fit in the
>>> desired static control so it is cut off.

>>> is there an easy way to determine a conversion of pixels to logical
>>> units or simply to return an error if the messge doesn't fit
>>> into the desired control so I can choose a smaller font.

>> Do you mean "dialog units"? If you set the mapping mode to MM_TEXT,
>> all
>> your coordinates should be in pixels. You can use GetTextExtent to
>> find
>> the width and height of a string, then GetClientRect to get the width
>> and
>> height of your static text control.

JB> I know this answer is a bit late, but the conversion factor between
JB> pixels (as used in MM_TEXT mode) and "Dialog box units" for any
JB> given
JB> dialog box font is given in knowledge base article 165478 as
JB> follows:
JB> With the actual font used selected into a screen DC do
JB> GetTextExtentExPointA/W (use A on Win9x, W on NT) on the specific
JB> string
JB> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
JB> One y-direction unit is 1/8 the height of this string, one
JB> x-direction
JB> unit is 1/(4*52) the width of this string (See the article and do
JB> additional testing to figure out the rounding rules). Once
JB> computed,
JB> you only need to redo this calculation if you change the font OR
JB> your
JB> top level window receives one of the broadcast notifications
JB> WM_SETTINGSCHANGE (001Ah) or WM_DISPLAYCHANGE (007Eh) OR your
JB> program is
JB> stopped OR your programs run without a window for even a brief
JB> moment
JB> (because then you may miss a notification).

JB> There are Windows calls that ostensibly do the conversion for you,
JB> but
JB> some of those calls assume the default font, not the actual font
JB> used
JB> in your dialog box.


JB> --
JB> Jakob B�hm, M.Sc.Eng. * j...@danware.dk * direct tel:+45-45-90-25-33
JB> Netop Solutions A/S * Bregnerodvej 127 * DK-3460 Birkerod * DENMARK
JB> http://www.netop.com * tel:+45-45-90-25-25 * fax:+45-45-90-25-26
JB> Information in this mail is hasty, not binding and may not be right.
JB> Information in this posting may not be the official position of
JB> Netop
JB> Solutions A/S, only the personal opinions of the author.

mchsi

unread,
Jun 7, 2009, 6:18:02 PM6/7/09
to
Thanks alot
that corrected the problem. Wish I'd look back sooner would save about 100
hours of trying
John Klosak

Hello, mchsi!
You wrote to Jakob Bohm on Sat, 16 May 2009 03:35:55 GMT:

m> thanks
m> thats what I needed
m> John Klosak
m> Hello, Jakob!


m> With best regards, mchsi. E-mail: jkl...@mchsi.com

0 new messages