f



Finding the actual width of a line of text

Hello,
  I have used GpiQueryFontMetrics() to get the pixel width of a line of
text in a control, like a radio button or checkbox. For controls that are
defined in a resource file, this works fine; it allows me to adjust the
horizontal layout to accommodate different font widths.
  However. There is a search function that does not use a resource file;
rather, it creates all of the controls on the fly. (I inherited it this
way.) GpiQueryTextBox() does not work on these controls. There does not
seem to be any reason for the failure. Regardless of the font
specification, the average font width from GpiQueryFontMetrics() always
returns as 7, and a string is the same width despite being rendered in
different fonts. For instance, "Simple" has a width of 41 whether the font
is Workplace Sans or Verdana. That is clearly inaccurate since Verdana is
a much wider font than Workplace Sans.
  Neither GPI function reports an error.
  Can anyone suggest what might be happening here?

-- 
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
0
Jim
11/3/2009 2:05:05 AM
comp.os.os2.programmer.misc 1326 articles. 0 followers. Post Follow

2 Replies
308 Views

Similar Articles

[PageSpeed] 55

On 11/02/09 07:05 pm, Jim Moe wrote:
> Hello,
>   I have used GpiQueryFontMetrics() to get the pixel width of a line of
> text in a control, like a radio button or checkbox. For controls that are
> defined in a resource file, this works fine; it allows me to adjust the
> horizontal layout to accommodate different font widths.
>   [...]
>   Can anyone suggest what might be happening here?
> 
  The problem was that I could only get a Presentation Space for the main
client window, not each of the child control windows. WinGetPS() returned
an "invalid handle" error when attempting to get the PS for a control window.
  GpiQueryFontMetrics() therefore only returned values for the client
window. Since all of the controls received that same font, I also set the
client window for that font as well and now I can get appropriate values
for the string widths.

-- 
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
0
Jim
11/6/2009 10:33:08 PM
Jim Moe wrote:
> On 11/02/09 07:05 pm, Jim Moe wrote:
>> Hello,
>>   I have used GpiQueryFontMetrics() to get the pixel width of a line of
>> text in a control, like a radio button or checkbox. For controls that are
>> defined in a resource file, this works fine; it allows me to adjust the
>> horizontal layout to accommodate different font widths.
>>   [...]
>>   Can anyone suggest what might be happening here?
>>
>   The problem was that I could only get a Presentation Space for the main
> client window, not each of the child control windows. WinGetPS() returned
> an "invalid handle" error when attempting to get the PS for a control window.
>   GpiQueryFontMetrics() therefore only returned values for the client
> window. Since all of the controls received that same font, I also set the
> client window for that font as well and now I can get appropriate values
> for the string widths.
> 

Even if you didn't want to use that font, you could probably create a 
hidden or an object window to determine the metrics.
0
Peter
11/6/2009 11:13:06 PM
Reply: