Solved

C++ Start app minimized

Posted on 2004-03-27
8
1,530 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:Sparky-Plug
  • 2
  • 2
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 10696203
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;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

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

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

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

   return  (   bRes);
}

Call it like

ExecuteCmdHidden ( "prog.exe");
0
 
LVL 4

Expert Comment

by:xassets
ID: 10696602
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..

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20855554.html

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.
0
 
LVL 4

Expert Comment

by:xassets
ID: 10697531
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.
0
 
LVL 2

Expert Comment

by:guntherothk
ID: 10699746
If you're starting the program from the desktop, you can click on the icon properties and command it to run minimuzed.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10953879
Hm, the question is pretty much answered...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maze travler 6 51
Getting IP address 8 71
FMX StringGrid1->Canvas->FillRect Problem 3 127
Dialogbox API leak? 18 81
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now