User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 5 Oct 2003, 18:55   #1
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Win32: retrieving the size of a Cstring in pixels

Does anyone have an idea of how I can get the size of a string in pixels?
I already found GetTextExtentExPoint but this one takes the HDC's font, which is not the font I'm using.
Structural Integrity is offline   Reply With Quote
Unread 5 Oct 2003, 19:08   #2
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Win32: retrieving the size of a Cstring in pixels

What kind of effect would it have to change the font of the HDC, calculate the size then revert the font have?

Otherwise

http://msdn.microsoft.com/msdnmag/is...c/default.aspx

Has 'an idea'
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 5 Oct 2003, 19:57   #3
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Win32: retrieving the size of a Cstring in pixels

Thanks pab, but I'm not sure if that's going to work the way I want.
The CDC is a MFC component, and the moment I include it it messes up my include structure (conflicting with windows.h).

I did get the GetTextExtentExPoint function to work tho, but now my HDC holds a non-standard font type. I don't know if this is a problem... it still runs.

As for your font-swapping suggestion: it's a rather time-critical piece where I need to get the string width. I'm not sure how this would affect exection speed shall do a few tests).
Structural Integrity is offline   Reply With Quote
Unread 5 Oct 2003, 20:25   #4
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Re: Win32: retrieving the size of a Cstring in pixels

Quote:
Originally Posted by Structural Integrity
The CDC is a MFC component, and the moment I include it it messes up my include structure (conflicting with windows.h).
Last time I checked so was CString... which puts an interesting spin on that statement.
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 5 Oct 2003, 20:30   #5
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Win32: retrieving the size of a Cstring in pixels

Quote:
Originally Posted by Structural Integrity
Thanks pab, but I'm not sure if that's going to work the way I want.
The CDC is a MFC component, and the moment I include it it messes up my include structure (conflicting with windows.h).

I did get the GetTextExtentExPoint function to work tho, but now my HDC holds a non-standard font type. I don't know if this is a problem... it still runs.

As for your font-swapping suggestion: it's a rather time-critical piece where I need to get the string width. I'm not sure how this would affect exection speed shall do a few tests).
Cache the two fonts with CreateFontIndirect i think it's called, then it's really just swapping two addresses when you commit one or the other to the hdc.
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 5 Oct 2003, 21:05   #6
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Win32: retrieving the size of a Cstring in pixels

Quote:
Originally Posted by Raging.Retard
Last time I checked so was CString... which puts an interesting spin on that statement.

CString, C-style string... all the same
OK... I admit it, I use character arrays. My bad.

Pab, the speed is indeed very good. This works good enough!
Structural Integrity is offline   Reply With Quote
Unread 7 Oct 2003, 01:19   #7
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Win32: retrieving the size of a Cstring in pixels

Maybe the thing you want is DrawText? There are some nice Flags. Have a look (I'm sorry, only VB declarations, but I'm sure you'll manage):
Code:
Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long

· uFormat
Specifies the method of formatting the text. It can be any combination of the following

[.. snip ..]

DT_CALCRECT
 Determines the width and height of the rectangle. If there are multiple
 lines of text, DrawText uses the width of the rectangle pointed to by the
 lpRect parameter and extends the base of the rectangle to bound the
 last line of text. If there is only one line of text, DrawText modifies the right
 side of the rectangle so that it bounds the last character in the line. In either
 case, DrawText returns the height of the formatted text but does not draw the text.
Maybe that's what you need? It might be worth a try, for speed reasons... No idea though...
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 02:11.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018