|
-
Feb 8th, 2007, 10:25 AM
#1
Thread Starter
Hyperactive Member
Minimize Process
I start a process from my application. This process spawns a secondary process that is always maximized. I want to minimize the secondary process from my code. I can obtain the handle to this process with the following code. Now that I have the handle, how do I minimize the process?
VB Code:
Dim hEvtCmd As IntPtr
Dim bEvntStart As Boolean = False
Do While Not bEvntStart
For Each oProcess In System.Diagnostics.Process.GetProcesses()
If oProcess.ProcessName.ToString = "evntcmd" Then
bEvntStart = True
hEvtCmd = oProcess.Handle
MessageBox.Show("found it: " & CType(hEvtCmd, String))
End If
Next
Loop
-
Feb 8th, 2007, 11:04 AM
#2
Re: Minimize Process
I'm not sure if there is another way, but I know you can use the SetWindowPos API to move/resize any window using the handle.
VB Code:
Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
-
Feb 8th, 2007, 11:16 AM
#3
Thread Starter
Hyperactive Member
Re: Minimize Process
Do I need to import a specific namespace? I am getting errors that HWND_BOTTOM and SWP_HIDEWINDOW are not declared.
VB Code:
SetWindowPos(hEvtCmd, HWND_BOTTOM, 1, 1, 0, 0, SWP_HIDEWINDOW)
-
Feb 8th, 2007, 11:46 AM
#4
Thread Starter
Hyperactive Member
Re: Minimize Process
This Link cleard up the enumerations but the window does not minimize.
VB Code:
Declare Auto Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, _
ByVal hWndInsertAfter As IntPtr, _
ByVal X As Integer, _
ByVal Y As Integer, _
ByVal cx As Integer, _
ByVal cy As Integer, _
ByVal uFlags As UInteger) As Boolean
VB Code:
Dim hEvtCmd As IntPtr
Dim bEvntStart As Boolean = False
Dim HWND_BOTTOM As New IntPtr(1)
Dim SWP_HIDEWINDOW As UInt32 = Convert.ToUInt32(&H80)
Do While Not bEvntStart
For Each oProcess In System.Diagnostics.Process.GetProcesses()
If oProcess.ProcessName.ToString = "evntcmd" Then
bEvntStart = True
hEvtCmd = oProcess.Handle
SetWindowPos(hEvtCmd, HWND_BOTTOM, 1, 1, 0, 0, SWP_HIDEWINDOW)
'MessageBox.Show("found it: " & CType(hEvtCmd, String))
End If
Next
Loop
-
Feb 8th, 2007, 01:44 PM
#5
Re: Minimize Process
I'm sorry i got mixed up with my APIs. You should be using the "ShowWindow" API
Below is the code you would use.
VB Code:
Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
VB Code:
Dim hEvtCmd As IntPtr
Dim bEvntStart As Boolean = False
Dim SW_HIDE As Long = 0
Do While Not bEvntStart
For Each oProcess In System.Diagnostics.Process.GetProcesses()
If oProcess.ProcessName.ToString = "evntcmd" Then
bEvntStart = True
hEvtCmd = oProcess.Handle
ShowWindow(oProcess.Handle.ToInt64, SW_HIDE)
'MessageBox.Show("found it: " & CType(hEvtCmd, String))
End If
Next
Loop
-
Feb 8th, 2007, 02:01 PM
#6
Thread Starter
Hyperactive Member
Re: Minimize Process
I think that some of the API headers have changed for 2005. This is wha tI needed to compile
VB Code:
Declare Auto Function ShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As IntPtr, _
ByVal nCmdShow As Int32) As Long
But the window is still there. I have a feeling that the handle to the process is not the handle to the window.
I've seen code that searches for the title of all windows to find the window handle but i can't find it at the moment.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|