Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an appliction through it opening/starting another software which always come front of my application and i have to minimize it manualy.

I want when any application/software open through my applicaion should be open in background and minimize always(no reflection).

using code like this but not working.

Any suggestion or something new.

VB
Diagnostics.Process.Start("path\Notepad.exe")


then calling below functions

VB
FindAndMinimizeWindowByTitle("notepad")
Public Const SW_MINIMIZE As Integer = 6
Public Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Integer
End Function

Public Function FindAndMinimizeWindowByTitle(ByVal Title As String) As Boolean

For Each clsProcess As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
  If (clsProcess.ProcessName = Title) Then

     ShowWindow(clsProcess.MainWindowHandle, SW_MINIMIZE)

Return True
End If
Next
Return False

 End Function
Posted
Updated 21-Nov-12 18:45pm
v3

The start of Notepad may take some milliseconds. Just wait a little before you call your minimize function.
 
Share this answer
 
I think,

You can't control other build exe/application accordingly, you need to change in your
application accordingly.
 
Share this answer
 
I find the following code is often successful for keeping a new process inactive. It does require that the new process respects the initial window state request from the operating system and not all will do this. Notepad is one that does but e.g. VideoLan media player does not.

VB
Private Sub StartProcess()
    Dim psi As New ProcessStartInfo()
    psi.FileName = "notepad.exe"
    psi.UseShellExecute = True
    ' Window Styles not operational unless shell exec is true
    psi.WindowStyle = ProcessWindowStyle.Minimized

    Dim p As New Process()
    p.StartInfo = psi
    p.Start()
    p.WaitForInputIdle()
    ' Reactivate the parent application's form AFTER the new Process has become idle
    Me.Activate()
End Sub


Console processes will raise an exception if WaitForIdleInput is called and I've never found a wholly successful method of keeping those in the background. I had one really annoying application which would activate itself at certain points in it's processing cycle and the only way I could stop that driving me crazy was to run it in a separate desktop via SysInternals Desktops.exe.

Alan.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900