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

Finding the actual width of a line of text

1 view
Skip to first unread message

Jim Moe

unread,
Nov 2, 2009, 9:05:05 PM11/2/09
to
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)

Jim Moe

unread,
Nov 6, 2009, 5:33:08 PM11/6/09
to
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.

Peter Flass

unread,
Nov 6, 2009, 6:13:06 PM11/6/09
to

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 new messages