Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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.
 
Diagnostics.Process.Start("path\Notepad.exe")
 
then calling below functions
 
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 21-Nov-12 18:43pm
Edited 21-Nov-12 18:45pm
member6016.1K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The start of Notepad may take some milliseconds. Just wait a little before you call your minimize function.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I think,
 
You can't control other build exe/application accordingly, you need to change in your
application accordingly.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
 
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 176
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,077
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100