Skip to main content
gamedev.net
🔒 Locked

Problem with GetTextExtentPoint32

Started by JackRabbit Aug 1, 2002 at 7:58 AM 0 replies 2.3k views
Original Post
JackRabbit
JackRabbit
Hi all! I've been playing around with creating my own window controls,you know like custom made imageboxes and that sort of thing. Now, i have made a little control thats much like the static label control. I made it so that the background is transparent so i can see background images and such of the parent window. I also created some methods so specify which font the controls should use to draw the text. Now heres the problem: I want the control to automatically adjust its size to fit the text which it displays. After a few hours of going through the Windows API reference at MSDN, and banging my head against the wall , i came across this little function: GetTextExtentPoint32() This function takes as parameters a device context, a string, the length of the string, and a SIZE structure to hold the results. The SIZE structure has to fields: cx and cy, WIDTH and HEIGHT accoringly. The function uses the currently selected font to calculate the width and height of the rectangle area that would enclose the text string. Well, i call this function every time the text inside the control is changed, and sizes the control accordingly, and it works just fine and dandy. Except for one small detail. In my program i use this string to test the control: "HelloWorld! HelloWorld!" The thing is that the size of the control miss alot of pixels in the end of both the width and height. Well, i went through MSDN again, and looked at the description of the SIZE structure. And it said that the values of the 'cx' and 'cy' members of the structure are in logical units. My question is... What the hell does that mean ??!?? How many pixels are in a logical unit ? Well, ive been going through the MSDN and some other tutorials sites, but i cant find any explanation to what a logical unit is or how many pixels per logical unit there are. Can any give my an explanation of logical units and how to convert them to pixels, or point me to a site that does this. Perhaps i missed something on MSDN. Anyway, any help and advice on this would be greatly appriciated! Thanks! EDIT: I use MoveWindow() to update the size of the control window. Though you might want to know that. [edited by - jackrabbit on August 1, 2002 9:16:39 AM]
Colin Jeanne
Colin Jeanne
quote:

MSDN - GetDeviceCaps()

LOGPIXELSX Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for all monitors.
LOGPIXELSY Number of pixels per logical inch along the screen height. In a system with multiple display monitors, this value is the same for all monitors.





I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm

Topic Locked

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

Sign in to reply to this topic.