Link to home
Start Free TrialLog in
Avatar of romiebehunin
romiebehunin

asked on

Center another applications window using it's handle VB.NET

Hi experts...
Is there a way that I can center another applications child window using that windows handle?

Here's what I have written so far but not sure where to go from here:

 
Private Sub CenterWindow(ByVal intHandle As Long)
        Dim iScreenHeight As Long
        Dim iScreenWidth As Long
        '##  PROVIDES SCREEN SIZE IN PIXELS
        iScreenWidth = Screen.PrimaryScreen.WorkingArea.Width
        iScreenHeight = Screen.PrimaryScreen.WorkingArea.Height


        Dim iFormHeight As Long
        Dim iFormWidth As Long

        Dim myRect As RECT
        If GetWindowRect(intHandle, myRect) > 0 Then
            If (myRect.Right - myRect.Left < My.Computer.Screen.WorkingArea.Width) Or (myRect.Bottom - myRect.Top < My.Computer.Screen.WorkingArea.Height) Then
                iFormHeight = myRect.Left
                iFormWidth = myRect.Top

            End If

        End If
        

        '## Next, we need to find the x/y location of the upper right hand corner

        Dim iTopLoc As Long
        Dim iLeftLoc As Long

        iLeftLoc = iFormWidth / 2
        iTopLoc = iFormHeight / 2


    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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 romiebehunin
romiebehunin

ASKER

Works like a charm thanks guys