James Steele

All things dotNet running through my veins

Console Application Problem.. Start minimized??

Any ideas on how (the best way) a Console Application can start ITSELF minimized? I have been trying to track this down for a while now.

Comments

Johnny Thomsen said:

This works for me...

ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
startInfo.Arguments = "www.edc.dk";
Process.Start(startInfo);
// process.WaitForExit();

# November 25, 2004 2:04 PM

Rob Chartier said:

When you think of it there really should be no way i can do this. What happens if the console app is started within a existing command window, or say when you boot into command prompt only?

On the other hand you can try something along the lines of:

unsafe {
string appName = System.Reflection.Assembly.GetEntryAssembly().GetName(false).Name;
testNamespace.HWND__* hwnd =testNamespace.windows.FindWindowA(null,appName);
int newwin = testNamespace.windows.SetWindowLongA(hwnd, -16, 0x20000000);
}



[DllImport(@"..\dll\user32.dll", EntryPoint="FindWindowA", CallingConvention=CallingConvention.StdCall, SetLastError=true)]
public static extern unsafe HWND__* FindWindowA(sbyte* lpClassName, sbyte* lpWindowName);



[DllImport(@"..\dll\user32.dll", EntryPoint="SetWindowLongA", CallingConvention=CallingConvention.StdCall, SetLastError=true)]
public static extern unsafe int SetWindowLongA(HWND__* hWnd, int nIndex, int dwNewLong);



Of course this is completely untested and probably wont work but at least its something to work on.
# November 25, 2004 2:19 PM

Rolf said:

Create a win app with no ui and create a new minimized console from there?
# November 25, 2004 2:41 PM

Rolf said:

I can't really see how a console app can actually show it's window minimized, since when the main function is entered as far as I know the console window is already created.
# November 25, 2004 2:43 PM

Russ C. said:

I think Rob Chartier has the closest answer,

The problem is that the WindowsState is managed by Windows, the console doesn't know about it, as far as it's concerned it's running in full-screen.

Look at www.pinvoke.net for the User32 DllImports
# November 26, 2004 3:47 AM

TrackBack said:

^_^,Pretty Good!
# April 10, 2005 4:23 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)