Solved

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

Posted on 2013-12-19
2
376 Views
Last Modified: 2013-12-27
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

0
Comment
Question by:romiebehunin
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39731543
0
 

Author Closing Comment

by:romiebehunin
ID: 39742031
Works like a charm thanks guys
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question