Solved

C++ Start app minimized

Posted on 2004-03-27
8
1,579 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 67
Prototype for MessageDlg in Embacadero XE 2 2 37
ASP.net build a IF/Then Walkthrough Guide 1 208
convert char array to number in c 5 85
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

815 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

12 Experts available now in Live!

Get 1:1 Help Now