Handles

sharpe

New member
Joined
Feb 12, 2003
Messages
2
Location
Copenhagen, DK
I would like to learn about handles (hWnd) I know nothing about it and would like to hear if anyone knows of any papers that would help me get started.

Thanks.
 
The object doesnt necessarily need to be on the screen. Its the
pointer to an object that is loaded into memory; it can be a button,
a form; anything that Windows classifies as a "window" will have
an hWnd (a Window Handle, the Handle property in .NET).

There isnt as much need to use it in .NET, but it is still required for
many APIs for which there are no .NET replacements.
 
Ok, thanks for your help.

>> Heiko: glad you lot arent supporting that bloody war. Its nice to see that someone has the balls to stand up to the US.
 
VolteFace - thats what I thought, but when I try to use the GetWindow API call to get the child windows of a form I get nothing returned, even though that form has buttons and textboxes on it.
 
I believe the API you want is [api]EnumChildWindows[/api]. However,
I dont know how to make API callbacks work in .NET, if they are not
the same way as in VB6. You should be able to get the information
you need from AllAPI (linked above) and MSDN.
 
Code:
Public Delegate Function CallBack( _
    ByVal hwnd As Integer, _
    ByVal lParam As IntPtr) As Boolean

Public Declare Function EnumChildWindows Lib "user32" ( _
    ByVal hwnd As Integer, _
    ByVal lpEnumFunc As CallBack, _
    ByVal lParam As Integer) As Integer

Public Shared Function ReceiveWindowHandles(ByVal hwnd As Integer, ByVal lParam As IntPtr) As Boolean
    Receive handles here
End Function

Call EnumChildWindows as such:
EnumChildWindows(Me.Handle.ToInt32, AddressOf Me.ReceiveWindowHandles, 0)

Note: I used integers above instead of .NETs IntPtr type for the window handles. Either way, it works fine, as IntPtrs will simply be converted into 32-bit values anyway. Also, most of whats above is off the top of my head, so dont sue me if it doesnt work perfectly.
 
Thanks Derek - Ill have a play with that over the weekend. I dont understand how you can use a function as a parameter type like that but Ill take your word for it. :)
 
Dont take his word for it ;)

[mshelp]ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconusingcallbackfunctions.htm[/mshelp]
 
Click on the little caret at the end of the link to be taken to the online MSDN version of it.
 
Back
Top