cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
Erenford
Enthusiast

[SOLVED] String length to pixel length? Like STW() in GDL

Hello,
Is there a DG function that computes for the length of the string in pixels? Something equivalent of STW(string) in GDL.
I'm trying to make a button that have a width according to its text. I could base it on the widest char like 'W' but it would be too wide for something like char 'i'.

Thanks.
2 Replies 2
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Erenford,

You should use APIAny_GetTextLineLengthID goodie function for this.
Example code:
double	DetermineTextWidth (const char* str, short font, double size) 
{ 
	if (strlen (str) == 0) 
		return (0); 
 
	API_TextLinePars	tlp; 
	double				width = 0.0; 
 
	BNZeroMemory (&tlp, sizeof (API_TextLinePars)); 
	tlp.drvScaleCorr = true;	// Apply drawing scale... 
	tlp.index = 0;				// Get the length of the longest line (there may be only one line...) 
	tlp.lineStr = const_cast<char*> (str); 
	tlp.wFace = APIFace_Plain; 
	tlp.wFont = font; 
	tlp.wSize = size; 
	tlp.wSlant = PI / 2.0;		// Plain text 
	ACAPI_Goodies (APIAny_GetTextLineLengthID, &tlp, &width); 
	return (width); 
}


Regards,
Tibor
Erenford
Enthusiast
oooh so there is one!

So for dialog box with default settings, I'm guessing no drawing style, with size 12. I'm not sure what the default font is so I just set 'wFont' to 1.

Seems it's working fine!
Thanks Tibor.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!