Maximizing / Set Focus to an External Program

I would like to be able to Maximize (resize when minimized) & Bring Focus to (bring to front)  an external program.  To set focus i have used the AppActivation command but was not satisfied having to use the title bar's name.  

Stipulation: the external program must not be closed and repopened to achieve set focus and maximized  window status.

Using VB.net  2005
SRabidouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You could enumerate through the Process.GetProcesses list to find the process that you want (if that is not what you are doing now).

To maximize the main window, you can get the handle of the main window for
the process, and then send a SC_MAXIMIZE system command message to it.

Reference:
http://www.dotnet247.com/247reference/msgs/7/35521.aspx

Bob
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
How about?...
Public Class Form1
 
    Private Const SW_SHOWMAXIMIZED As Integer = 3
    Private Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) As Integer
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal handle As IntPtr) As Integer
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MaximizeExeByName("notepad")
    End Sub
 
    Private Sub MaximizeExeByName(ByVal ExeNameWithoutPathOrExtension As String) '
        Dim ps() As Process = Process.GetProcessesByName(ExeNameWithoutPathOrExtension)
        If ps.Length > 0 Then
            ShowWindow(ps(0).MainWindowHandle, SW_SHOWMAXIMIZED)
            SetForegroundWindow(ps(0).MainWindowHandle)
        End If
    End Sub
 
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SRabidouAuthor Commented:
Code works perfectly.  Thanks for your help.  Much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.