Results 1 to 6 of 6

Thread: Minimize Process

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    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:
    1. Dim hEvtCmd As IntPtr
    2.             Dim bEvntStart As Boolean = False
    3.  
    4.             Do While Not bEvntStart
    5.                 For Each oProcess In System.Diagnostics.Process.GetProcesses()
    6.                     If oProcess.ProcessName.ToString = "evntcmd" Then
    7.                         bEvntStart = True
    8.                         hEvtCmd = oProcess.Handle
    9.                         MessageBox.Show("found it: " & CType(hEvtCmd, String))
    10.                     End If
    11.                 Next
    12.             Loop

  2. #2
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    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:
    1. 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

    Helpful Links:
    VB 6 - How to get the "Key" Value in a collection
    VB.NET - File Search Utility || VB.NET - How to compare 2 directories || VB.NET - How to trust a network share
    VB.NET - Create Excel Spreadsheet From Array || VB.NET - Example Code & Hints you may not know
    VB.NET - Save JPEG with a certain quality (image compression) || VB.NET - DragDrop Files, Emails, and Email Attachments

    Please post some of the code you need help with (it makes it easier to help you)
    If your problem has been solved then please mark the thread [RESOLVED].
    Don't forget to Rate this post

    "Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    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:
    1. SetWindowPos(hEvtCmd, HWND_BOTTOM, 1, 1, 0, 0, SWP_HIDEWINDOW)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Minimize Process

    This Link cleard up the enumerations but the window does not minimize.

    VB Code:
    1. Declare Auto Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, _
    2.                           ByVal hWndInsertAfter As IntPtr, _
    3.                           ByVal X As Integer, _
    4.                           ByVal Y As Integer, _
    5.                           ByVal cx As Integer, _
    6.                           ByVal cy As Integer, _
    7.                           ByVal uFlags As UInteger) As Boolean

    VB Code:
    1. Dim hEvtCmd As IntPtr
    2.             Dim bEvntStart As Boolean = False
    3.             Dim HWND_BOTTOM As New IntPtr(1)
    4.             Dim SWP_HIDEWINDOW As UInt32 = Convert.ToUInt32(&H80)
    5.  
    6.             Do While Not bEvntStart
    7.                 For Each oProcess In System.Diagnostics.Process.GetProcesses()
    8.                     If oProcess.ProcessName.ToString = "evntcmd" Then
    9.                         bEvntStart = True
    10.                         hEvtCmd = oProcess.Handle
    11.                         SetWindowPos(hEvtCmd, HWND_BOTTOM, 1, 1, 0, 0, SWP_HIDEWINDOW)
    12.                         'MessageBox.Show("found it: " & CType(hEvtCmd, String))
    13.                     End If
    14.                 Next
    15.             Loop

  5. #5
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    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:
    1. Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

    VB Code:
    1. Dim hEvtCmd As IntPtr
    2.             Dim bEvntStart As Boolean = False
    3.             Dim SW_HIDE As Long = 0
    4.            
    5.             Do While Not bEvntStart
    6.                 For Each oProcess In System.Diagnostics.Process.GetProcesses()
    7.                     If oProcess.ProcessName.ToString = "evntcmd" Then
    8.                         bEvntStart = True
    9.                         hEvtCmd = oProcess.Handle
    10.                         ShowWindow(oProcess.Handle.ToInt64, SW_HIDE)
    11.                         'MessageBox.Show("found it: " & CType(hEvtCmd, String))
    12.                     End If
    13.                 Next
    14.             Loop

    Helpful Links:
    VB 6 - How to get the "Key" Value in a collection
    VB.NET - File Search Utility || VB.NET - How to compare 2 directories || VB.NET - How to trust a network share
    VB.NET - Create Excel Spreadsheet From Array || VB.NET - Example Code & Hints you may not know
    VB.NET - Save JPEG with a certain quality (image compression) || VB.NET - DragDrop Files, Emails, and Email Attachments

    Please post some of the code you need help with (it makes it easier to help you)
    If your problem has been solved then please mark the thread [RESOLVED].
    Don't forget to Rate this post

    "Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Minimize Process

    I think that some of the API headers have changed for 2005. This is wha tI needed to compile
    VB Code:
    1. Declare Auto Function ShowWindow Lib "user32" Alias "ShowWindow" _
    2.                         (ByVal hwnd As IntPtr, _
    3.                         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
  •  



Click Here to Expand Forum to Full Width