Click here to Skip to main content
15,926,290 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
General.Net file format Pin
852y3agnna18-May-05 1:18
852y3agnna18-May-05 1:18 
GeneralRe: .Net file format Pin
Mike Dimmick18-May-05 1:43
Mike Dimmick18-May-05 1:43 
GeneralCustom toolbar control in .Net framework Pin
agrafov17-May-05 9:59
agrafov17-May-05 9:59 
GeneralRe: Custom toolbar control in .Net framework Pin
John Arlen117-May-05 10:23
John Arlen117-May-05 10:23 
GeneralRe: Custom toolbar control in .Net framework Pin
Carl Mercier17-May-05 11:13
Carl Mercier17-May-05 11:13 
GeneralRe: Custom toolbar control in .Net framework Pin
Sebrell22-May-05 15:50
Sebrell22-May-05 15:50 
GeneralDetermining logon provider Pin
Ryan McCauley17-May-05 6:24
Ryan McCauley17-May-05 6:24 
GeneralProblem with GetTextExtentPoint32 Pin
Alsvha17-May-05 1:20
Alsvha17-May-05 1:20 
Greetings all.

I'm trying to meassure the contents of a string in a webapplication, and have problem with the GetTextExtentPoint32 function and how it works. (I'm using VB.NET cause that is what we have to program in at work, so eventhough this is more for my own benefit and interest, I'll still use VB)

I've never used this API before, so please have some compasion for my newbie questions Smile | :)
Most of this information has been put together using msdn and a few webpages (I lack some decent code exampels in VB which I can read from)

So far what I've done is declaring a number of functions, amongst others:

Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" _
(ByVal hDC As Long, ByVal lpsz As String, ByVal cbString As Long, ByRef lpSize As SIZE) As Long


I've created a stucture:

Private Structure SIZE
Dim cx As Long
Dim cy As Long
End Structure


Then in my function I do this:

Dim sz As Size
Dim strTestString As String = ""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz""
Dim hDc as long = GetWindowDC(GetDesktopWindow)
Dim hFont = GetStockObject(ANSI_VAR_FONT)
dim hFontOld = SelectObject(hDc, hFont&)


As far as I understand hDc is the handler to the "screen-area" used for drawing.
I'm by far not sure what hFont of hFontOld does (ANSI_VAR_FONT = 12), but font-buisness is a good guess I hope Big Grin | :-D
(Taken from websites, not my own)

I then call:

GetTextExtentPoint32(hDc, strTestString , 52, sz)

52 I guess is the number of characters in the string. (String and 52 is taken from websites, and not my own)

And then I get a NullReference exception when running the code (and here I'm stuck).....

Does anybody have any information which can guide me further, or have some good code exampels I can use/read?
I'd really like to this work, seeing as if it does I could perhaps implement it at work, but also because it is starting to nag at me, and I hate having to leave it unfinished.

Please help if possible Smile | :)

With regards and hopefullness
"Alsvha"

---------------------------
127.0.0.1 - Sweet 127.0.0.1
GeneralRe: Problem with GetTextExtentPoint32 Pin
John Arlen117-May-05 10:18
John Arlen117-May-05 10:18 
GeneralRe: Problem with GetTextExtentPoint32 Pin
Alsvha17-May-05 18:31
Alsvha17-May-05 18:31 
GeneralRe: Problem with GetTextExtentPoint32 Pin
Dave Kreskowiak17-May-05 19:31
mveDave Kreskowiak17-May-05 19:31 
QuestionA bug in .net debugger??? Pin
anurik16-May-05 21:53
anurik16-May-05 21:53 
AnswerRe: A bug in .net debugger??? Pin
Marc Clifton17-May-05 0:23
mvaMarc Clifton17-May-05 0:23 
QuestionHow to change desktop theme and start menu style in c# Pin
mmsspp16-May-05 17:51
mmsspp16-May-05 17:51 
QuestionHow to reload .Net control (Applet) Pin
Anonymous16-May-05 10:49
Anonymous16-May-05 10:49 
AnswerRe: How to reload .Net control (Applet) Pin
Marc Clifton16-May-05 11:31
mvaMarc Clifton16-May-05 11:31 
GeneralRe: How to reload .Net control (Applet) Pin
Anonymous16-May-05 11:59
Anonymous16-May-05 11:59 
GeneralContinuous Async read Pin
goldoche16-May-05 7:36
goldoche16-May-05 7:36 
GeneralRe: Continuous Async read Pin
Marc Clifton16-May-05 11:34
mvaMarc Clifton16-May-05 11:34 
QuestionIDesignerHost resources? Pin
Dr Herbie16-May-05 1:28
Dr Herbie16-May-05 1:28 
AnswerRe: IDesignerHost resources? Pin
Dr Herbie16-May-05 22:00
Dr Herbie16-May-05 22:00 
GeneralRe: IDesignerHost resources? Pin
Marc Clifton17-May-05 0:24
mvaMarc Clifton17-May-05 0:24 
GeneralAppDomain.AppendPrivatePath Pin
David Wulff15-May-05 10:00
David Wulff15-May-05 10:00 
GeneralRe: AppDomain.AppendPrivatePath Pin
Marc Clifton15-May-05 14:20
mvaMarc Clifton15-May-05 14:20 
GeneralRe: AppDomain.AppendPrivatePath Pin
David Wulff15-May-05 14:25
David Wulff15-May-05 14:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.