Skip to main content
gamedev.net
🔒 Locked

string width in pixels

Started by Crispy 2 replies 300+ views
Original Post
Crispy
Crispy
Hi, is there a (WinAPI) function for determining the width of a string in pixels (based on the font)? Can''t seem to be able to find one myself... Better yet - how do you guys calculate the width and height of a tooltip control, when done automatically? Thanks, Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Darrell L
Darrell L
I''ve used GetTextExtentPoint in the past. It will return both the width and the height of a string based upon the currently selected font of a DC.

But, there''s a tooltip window class that you can use as well with CreatWindowEx. You don''t have to size its window at all as the window class proc will handle it for you (it resizes the window to the appropriate size when the tooltip window is displayed). The class is TOOLTIPS_CLASS. Do a search for this in MSDN and you should find a page that''s helpful in setting up such a window. Or, I have code if you''d like?
Crispy
Crispy
quote:
Original post by Darrell L
But, there''s a tooltip window class that you can use as well with CreatWindowEx. You don''t have to size its window at all as the window class proc will handle it for you (it resizes the window to the appropriate size when the tooltip window is displayed). The class is TOOLTIPS_CLASS. Do a search for this in MSDN and you should find a page that''s helpful in setting up such a window. Or, I have code if you''d like?


That I know. The fact is - the rect member in the TOOLINFO struct requires a rect into which the tooltip is accommodated. If the specified rectangle is not big enough, it seems the tooltip is not displayed. Hence - I need to calculate the size of the rectangle from the string passed to the tooltip as the "tool tip".

quote:

I''ve used GetTextExtentPoint in the past. It will return both the width and the height of a string based upon the currently selected font of a DC.



Thanks! Looks like that''s what I''m looking for - gonna try it out soon.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Crispy
Crispy
On closer inspection - my bad. The rect member defines the area in which the tooltip is shown in the bound control. It doesn''t have anything to do with the text size. GetTextExtentPoint(32) - a worthwhile function to know anyway.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.