Hi guys can somebody help me out???
Im creating a program in C#.net express 2005 that can minimize other windows... how can i do this??? pls help me out... It will search for a specific window process.. then it will minimized the process if found.. help help help...
I don't think you can do that (legally) simply because the Windows API prevents you from accessing the threads of other applications that were not instantiated by you. So unless you're the one who opened that form, you can't minimize it.
You can get a handle (hwnd) of each window on the desktop and use P/Invoke to call Win32 api ShowWindow function.
LaTtEX:I don't think you can do that (legally) simply because the Windows API prevents you from accessing the threads of other applications that were not instantiated by you. So unless you're the one who opened that form, you can't minimize it.
Actually I did it already.. I'll share the codes man.. boybawang is correct..
Hehehe. P/Invoke. Sabi na eh.
I stand corrected
[DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
/*
Hide = 0,
ShowNormal = 1,ShowMinimized = 2,ShowMaximized = 3,Maximize = 3,ShowNormalNoActivate = 4,Show = 5,Minimize = 6,ShowMinNoActivate = 7,ShowNoActivate = 8,Restore = 9,ShowDefault = 10,ForceMinimized = 11*/
then:
private void HideServices() { Process[ procs = Process.GetProcessesByName("cmd"); foreach (Process p in procs) { IntPtr pFoundWindow = p.MainWindowHandle; ShowWindow(pFoundWindow, 0); } }
In this code what i did was hide all the services of the CommandLine... all the cmd processes will be hidden..
Very good fabs! Thanks for sharing!
No prblem man!!!! I'll share everything na malalaman ko.. hehehe hope this will be usefull..
Question: Why would you want to minimize all other windows? Wouldn't that be quite disrupting, if not outright rude, towards the user?
did i say all??? i said other windows... when the program starts i need to start a batch file that pauses at the center of the screen... so i need to hide or minimize it..
Doesn't this work (setting ProcessStartInfo to Minimized)? Taken from http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo(VS.71).aspx
/// <summary> /// Uses the ProcessStartInfo class to start new processes, both in a minimized /// mode. /// </summary> public void OpenWithStartInfo() { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo); startInfo.Arguments = "www.northwindtraders.com"; Process.Start(startInfo); }
good job! :)
fabs: did i say all??? i said other windows... when the program starts i need to start a batch file that pauses at the center of the screen... so i need to hide or minimize it..
So you're the one who started it. You don't need P/Invoke if you started the process. Taken from http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo(VS.71).aspx:
'/ <summary> '/ Uses the ProcessStartInfo class to start new processes, both in a minimized '/ mode. '/ </summary> Public Sub OpenWithStartInfo() Dim startInfo As New ProcessStartInfo("IExplore.exe") startInfo.WindowStyle = ProcessWindowStyle.Minimized Process.Start(startInfo) startInfo.Arguments = "www.northwindtraders.com" Process.Start(startInfo) End Sub 'OpenWithStartInfo
I need P/Invoke to HIDE some windows that i've started.. well it works now.. thanks for the advices and help man!!!