• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3213
  • Last Modified:

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
0
SRabidou
Asked:
SRabidou
1 Solution
 
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
 
SRabidouAuthor Commented:
Code works perfectly.  Thanks for your help.  Much appreciated.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now