Solved

C++ Start app minimized

Posted on 2004-03-27
8
1,809 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 how to clear a vector as well as how to detect empty vectors in C++.

617 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