Maxmize external program?

WinDev

Member
Joined
Jul 10, 2012
Messages
9
Programming Experience
1-3
I am looking to maximize an external running program that is currently minimized/hidden. my program already gets the current running processes listed in a combo box and it grabs the titles and on selection from the combo box it adds the title to a textbox. How would I be able to maximize the currently selected process?
 
You can use the Win32 API call ShowWindow to do that.

Imports System.Runtime.InteropServices

<DllImport("User32")> _
Private Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
End Function

Const SW_HIDE As Integer = 0
Const SW_RESTORE As Integer = 1
Const SW_MINIMIZE As Integer = 2
Const SW_MAXIMIZE As Integer = 3

ShowWindow(CType(myProc.MainWindowHandle, Integer), SW_MAXIMIZE)
 
I am not entirely sure how to use that? What exactly do I put in the private function showwindow?

If I add the imports and then paste the rest of the code in I get many errors. How do modify it to select the process from the title in my textbox?
 
myProc is the process object you want to maximize the main window of. I cannot say more than that, you should know where to put imports, external declares and constants in your code.
 
I should of been more clear. I know what myproc is I just don't know how to declare my textbox as myproc

Here is what I tried, but I get the cannot be converted into string error.

VB.NET:
            Dim myproc As Process           
            myproc = TextBox1.Text
            ShowWindow(CType(myproc.MainWindowHandle, Integer), SW_MAXIMIZE)

In my program I check for processes and list them in a combo box. Then when the combobox has been changed it adds the process title to a textbox.

VB.NET:
            Dim ProcessList() As Process = Process.GetProcesses       
             For I = 0 To UBound(ProcessList)
                If ProcessList(I).MainWindowTitle.ToString = "" = False Then
                    ComboBox1.Items.Add(ProcessList(I).MainWindowTitle.ToString)
                       End If
 
Okay so here is what I have now. It still doesn't work but it's progress lol.

For Each MyProc As Process In Process.GetProcesses
If MyProc.MainWindowTitle = (GameName.Text) Then
ShowWindow(CType(MyProc.MainWindowHandle, Integer), SW_MAXIMIZE)
End If
next
 
Okay so here is what I have now. It still doesn't work but it's progress lol.

For Each MyProc As Process In Process.GetProcesses
If MyProc.MainWindowTitle = (GameName.Text) Then
ShowWindow(CType(MyProc.MainWindowHandle, Integer), SW_MAXIMIZE)
End If
next


Got it :) Here is the code. Thanks for your help.


Public Class GameBotMain
Private Declare Function ShowWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nCmdShow As SHOW_WINDOW _
) As Boolean


<Flags()> _
Private Enum SHOW_WINDOW As Integer
SW_HIDE = 0
SW_SHOWNORMAL = 1
SW_NORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWMAXIMIZED = 3
SW_MAXIMIZE = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_FORCEMINIMIZE = 11
SW_MAX = 11
End Enum

For Each myProc As Process In Process.GetProcesses
If myProc.MainWindowTitle = (GameName.Text) Then
' ShowWindow(CType(myProc.MainWindowHandle, Integer), SW_MAXIMIZE)
' End If
'Next


ShowWindow(myProc.MainWindowHandle, SHOW_WINDOW.SW_MAXIMIZE)
End If
Next myProc
 
Back
Top