DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

Minimize other windows...

rated by 0 users
This post has 13 Replies | 1 Follower

Top 75 Contributor
Posts 23
Points 370
fabs Posted: 01-23-2008 5:53 PM

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

  • | Post Points: 20
Top 25 Contributor
Posts 88
Points 1,240

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. 

Jon Limjap tech :: DotNet @ Kape ni LaTtEX personal :: Kape ni LaTtEX our business: I-NAV Travel & Tours
  • | Post Points: 35
Top 100 Contributor
Posts 12
Points 165

 You can get a handle (hwnd) of each window on the desktop and use P/Invoke to call Win32 api ShowWindow function.

  • | Post Points: 5
Top 75 Contributor
Posts 23
Points 370

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

Top 25 Contributor
Posts 88
Points 1,240

Hehehe. P/Invoke. Sabi na eh. Stick out tongue 

I stand corrected Smile 

Jon Limjap tech :: DotNet @ Kape ni LaTtEX personal :: Kape ni LaTtEX our business: I-NAV Travel & Tours
  • | Post Points: 20
Top 75 Contributor
Posts 23
Points 370

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

Top 10 Contributor
Posts 751
Points 10,140

Very good fabs! Thanks for sharing! 

  • Filed under:
  • | Post Points: 20
Top 75 Contributor
Posts 23
Points 370

No prblem man!!!! I'll share everything na malalaman ko.. hehehe hope this will be usefull.. 

Top 25 Contributor
Posts 88
Points 1,240

Question: Why would you want to minimize all other windows? Wouldn't that be quite disrupting, if not outright rude, towards the user?

Jon Limjap tech :: DotNet @ Kape ni LaTtEX personal :: Kape ni LaTtEX our business: I-NAV Travel & Tours
  • | Post Points: 20
Top 75 Contributor
Posts 23
Points 370

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

  • Filed under: ,
  • | Post Points: 50
Top 25 Contributor
Posts 88
Points 1,240

 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);

}

 

Jon Limjap tech :: DotNet @ Kape ni LaTtEX personal :: Kape ni LaTtEX our business: I-NAV Travel & Tours
  • | Post Points: 5
Top 100 Contributor
Posts 12
Points 165

 good job!  :)

  • | Post Points: 5
Top 25 Contributor
Posts 88
Points 1,240

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

 

Jon Limjap tech :: DotNet @ Kape ni LaTtEX personal :: Kape ni LaTtEX our business: I-NAV Travel & Tours
  • | Post Points: 20
Top 75 Contributor
Posts 23
Points 370

 I need P/Invoke to HIDE some windows that i've started.. well it works now.. thanks for the advices and help man!!!

Page 1 of 1 (14 items) | RSS

Copyright DevPinoy 2005-2008