Link to home
Start Free TrialLog in
Avatar of ACAE
ACAE

asked on

Get the windows handle

Hello,

I'm trying to establish an internet connection using the InternetAutodial function.  The second parameter you need to pass is the windows handle (I'm using it on a PDA, so .NET COMPACT FRAMEWORK is used).

How can I get the windows handle in vb.net ?

This is the code I use now :

Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2

InternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED, 0&)

This returns this error : NotSupportedException
Avatar of jazduck
jazduck

Dim objProcess As New Process()
        Dim objProcesses() As Process '
        objProcesses = Process.GetProcesses()

iWnd = objProcess.MainWindowHandle.ToInt32()

Along those lines, sorry I cant currently test anything, laptop's decided it doesnt like me (again).

Regards
Jaz
Avatar of ACAE

ASKER

I have 2 problems :
- Process type doesn't seem to be supported by the .net compact framework
- If I try this on a normal windows application, I get an error : 'No process is associated with this object'

Any ideas ?
Ill have another look at it today, I pulled this out of some code i use to setfocus back to my application using its hwnd, ill just have to see what bits I missed. But first im going to have to install vs.net again, thats a nice hour wait to think about it :)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetHandle(Me.Name) 'Call using WindowTitle as parameter
    End Sub

    Sub GetHandle(ByVal strWindowTitle As String)
        Dim hWnd As Long
        Dim objProcess As New Process()
        Dim objProcesses() As Process

        objProcesses = Process.GetProcesses()

        For Each objProcess In objProcesses
            If UCase(objProcess.MainWindowTitle) = UCase(strWindowTitle) Then
                hWnd = objProcess.MainWindowHandle.ToInt32()
                Exit For
            End If
        Next
        MsgBox(hWnd)
    End Sub

That does the trick
Regards
Jaz
ASKER CERTIFIED SOLUTION
Avatar of jazduck
jazduck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ACAE

ASKER

The problem is that with the compact framework the type 'processed' is not supported.  Anyhow, we bought a dll from another company (intelliprog) whch does the job.  Thanx for your help