PDA

View Full Version : minimize window from windowhandle


Doom9
16th May 2005, 20:56
Is there a way to mimimize a W32 GUI window if I have its windowhandle? I'm trying to minimize DGIndex while its running. I can get its windowhandle even from .NET but not knowing the W32 API I'm not sure if that's going to get me anywhere (.NET built-in functions to minimize a process have failed me).

Zeul
16th May 2005, 21:07
SetWindowPlacement.
This is a VB example.
http://www.mentalis.org/apilist/SetWindowPlacement.shtml

Nic
16th May 2005, 21:40
CloseWindow....Yeah. I know. I even wrote a comment about it in the QuEnc source.

Crazy crazy M$,
-Nic

dragongodz
17th May 2005, 06:27
is there any reason

ShowWindow(HwND, WS_MINIMIZE)

wouldnt work ????

iNFO-DVD
23rd May 2005, 01:08
@Doom9

Are you refering to VB.NET?
Did my example I posted work for you?
By what method are you running DGIndex?
You want me to send you my DGIndex routine?

Doom9
23rd May 2005, 08:31
actually, C#. I think I already used the same code as you but for some reason, DGIndex always comes up in full force:(

iNFO-DVD
23rd May 2005, 09:44
Well that's got me stumped then......

Was it used in conjunction with: Process.StartInfo.UseShellExecute = True ?

Doom9
23rd May 2005, 10:43
I don't have the source with me so I can't tell for sure. I'm using the same way to launch it as any other commandline tool (except I don't redirect stdout and stderr).. if I remember correctly there's only one way shellexecute can be configured for the redirection to work.

Other than that I used the following two lines to try and hide dgindex:

ProcessDG.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
ProcessDG.StartInfo.CreateNoWindow = True

iNFO-DVD
23rd May 2005, 11:03
Get rid of the: ProcessDG.StartInfo.CreateNoWindow = True

dragongodz
23rd May 2005, 13:32
since you are actually wanting to just start it minimised why not

ProcessDG.StartInfo.WindowStyle = ProcessWindowStyle.Minimized

as mentioned here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic.asp

did you try that ?

iNFO-DVD
23rd May 2005, 14:18
Yes I think he's tried that, I mentioned that in another thread, it seems weird that it's not working......

mpucoder
23rd May 2005, 16:07
It's up to the application to honor the startinfo. Every C/C++ Window application starts with

int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )

nCmdShow is ProcessDG.StartInfo.WindowStyle, and is expected to be used in the initial ShowWindow as:

hWnd = CreateWindow( ...
ShowWindow( hWnd, nCmdShow ) ;
UpdateWindow( hWnd ) ;

But that is only the convention, ie the program doesn't have to do it this way, and nothing in the system will enforce it.
In that case you will have to minimize the window after it has started.

One way you can determine if the program is honoring the startinfo is to set up a shortcut on the desktop, right click on it, and click on properties. There you can set the StartInfo.WindowSize used by explorer.exe (run - has three window size choices). If the program does not honor that, then it is not following convention.

iNFO-DVD
23rd May 2005, 17:32
DGIndex DOES allow the starting minimised. My program (avi.NET) and also AutoGK does it.

Doom9
23rd May 2005, 18:34
ok, here's the code I use to launch dgindex:

pstart.CreateNoWindow = true;
pstart.UseShellExecute = false;
pstart.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo = pstart;
proc.Start();

let me try without the CreateNoWindow now.

Doom9
23rd May 2005, 18:39
getting rid of CreateNoWindow doesn't do anything, neither does changing the ProcessWindowStyle to Minimized rather than Hidden didn't change anything either.

I'll attach the latest MeGUI sources so you can verify.

iNFO-DVD
23rd May 2005, 19:40
Even though I'm doing it in VB.NET the command type you're using is almost identical so I presume it's behaviour is too.

If I'm not redirecting stdout e.t.c. I need to make sure I use 'pstart.UseShellExecute = True' and make sure you also add 'pstart.RedirectStandardOutput = False' because if you redirect elsewhere then it will remember that setting when you run again so specify you do not want to redirect.

I'm almost 100% sure if you change to this it will work...

pstart.WindowStyle = ProcessWindowStyle.Minimized;
pstart.UseShellExecute = True;
pstart.RedirectStandardOutput = False;

I couldn't test it from this end with your source as I can never seem to get the support program to download, the '7z' ones, always times out on me. :(

xtknight
4th June 2005, 02:57
Set:
pstart.UseShellExecute = true;

By the way, awesome program. Just what I need to encode all different types of formats, and I didn't realize it until I saw this thread.