C++ Start app minimized

Is there a simple way of making the C++ program run minimized? If it is any easier I suppose that altogether hidden would do.

The app reoganizes many files and it takes a while to complete so it would be more convienient for it to start minimized.

It is not a windows app c++ app but a simple command line type program.

Many thanks.
Who is Participating?
jkrConnect With a Mentor Commented:
Use "ShellExecute()" with the "SW_HIDE" option:

ShellExecute ( NULL, "open", "prog.exe", NULL, NULL, SW_HIDE);

Alternatively, "CreateProcess()" offers the same, but is a little more complex to use:

BOOL ExecuteCmdHidden   (   LPSTR   pszCmd)
   STARTUPINFO         si;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_HIDE;

   bRes    =   CreateProcess   (   NULL,

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   bRes);

Call it like

ExecuteCmdHidden ( "prog.exe");
If it has a window, sent a WM_MINIMIZE to your own hWnd, using sendmessage or postmessage

If it hasn't got a window and is starting in a command prompt black window, change the compiler/linker options to remove _CONSOLE as in this Q..


That will get rid of the console window completely. I don't think you can control the console window from the running app to minimise it.
Couple of xtra points (a) I should have said call ShowWindow instead of the minimize, (b) jkr's right, this is a way of fulfilling your need, but it just involves launching a sep process. You could use jkrs solution to call your own exe from itself as long as you carry a flag so it knows when not to launch itself, if you see what I mean.
If you're starting the program from the desktop, you can click on the icon properties and command it to run minimuzed.
Hm, the question is pretty much answered...
All Courses

From novice to tech pro — start learning today.