Skip to main content
gamedev.net
🔒 Locked

TextOut

Started by Melo 7 replies 450+ views
Original Post
Melo
Melo
HI everybody! I can''t figure out how to get the width (in pixels) of a string that I print to the Screen using the GDI-Function TextOut. Is there a way to do this?? Thanx for your help... Andreas - - - - - - - - - - - - - - Andreas Mähler Wolf359 Interactive
VBMaster
VBMaster
Hi!
You can use the GetTextExtentPoint32 API, which fills a SIZE structure with the dimensions of a string when it will be printed on a DC.

VBMaster
Gladiator
Gladiator
If you wanna word-wrap your string when you draw on a DC, then you might wanna use DrawText() instead of TextOut()
Melo
Melo
I did what you told me to do, but this code crashes my program:


void GUI_OutTextRCT (RECT *lpRect,
char* string,
LPDIRECTDRAWSURFACE lpDDS,
DWORD Color,
HFONT Font)
{
HDC dc;
lpDDS->GetDC (&dc);
SetTextColor (dc, Color);
SetBkMode (dc, TRANSPARENT);
SelectObject (dc, Font);
DrawText (dc, string, strlen (string), lpRect, DT_CENTER);
}



- - - - - - - - - - - - - -
Andreas Mähler
Wolf359 Interactive


Edited by - Melo on July 11, 2000 8:10:59 AM
VBMaster
VBMaster
Although probably this is not the answer to your problem, you must also use the DT_WORDBREAK flag.

VBMaster
Melo
Melo
I am developing a GUI and I have two problems:

1) I try to center the Text to a Button (that''s what the function above is for).

2) The text inside a TextBox should scroll, if the String is larger then the TextBox-Rect.

I''ll keep trying

- - - - - - - - - - - - - -
Andreas Mähler
Wolf359 Interactive
Melo
Melo
OH BOY! I'M SO STUPID!!
I forgot:

lpDDS->ReleaseDC (dc);



Problen #1 is solved now - any suggestions for #2 ?

- - - - - - - - - - - - - -
Andreas Mähler
Wolf359 Interactive


Edited by - Melo on July 11, 2000 9:18:18 AM

Topic Locked

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

Sign in to reply to this topic.