tags:

views:

61

answers:

4

I want to run the app in silent mode by passing in a parameter, otherwise I will show the window.

+1  A: 

Well, for one you could just decide not to create a window at all if this parameter is passed in, otherwise you can try calling ShowWindow, with the handle to your window and with the SW_HIDE parameter, and see if that does what you need.

Another way of hiding the window and never having it show up, but still create it, is to chose to never call ShowWindow with SW_HIDE on it, and create it with CreateWindow/CreateWindowEx, and not set the WS_VISIBLE flag in the dwStyle parameter.

Jacob
+2  A: 

ShowWindow(... SW_HIDE ...) doesn't work?

The best practice here is to not create the window in the first place. Nothing forces you to actually create a window in InitInstance. Though if you're working with MFC it's likely a lot of your application/domain/business logic is sitting there, tightly coupled to those MFC message handlers and so forth. In which case the window will need to exist.

Swingline Rage
This is true, it is a clone of a legacy application to suite a similar but different need. There is too domain logic tied in there that I don't want to mess with because I will surely mess it all up.
Brian T Hannan
I decided to bite the bullet and move a ton of code around. I ended up not creating the window in the first place when /silent is entered as a parameter. Thanks for the motivation!
Brian T Hannan
+2  A: 

I think a better solution will be not creating the window if not needed. Take a look at the main function and you will see the code that creates the window. Call it only if you want to launch the window.

dig
I really wish it was that simple.
Brian T Hannan
but it is.unless you have design problems and the logic is mix with the view.
dig
It *is* that simple.
Hans Passant
It is legacy code with design problems and the logic is definitely mixed in with the view. I suppose I could separate the two, but then a full regression is needed and things will most certainly break.
Brian T Hannan
How about if you are expecting to get messages to that window for IPC - not necessarily best way to do IPC, but a valid reason to have a window and not need it to be shown
Greg Domjan
+1  A: 

If you have an MFC CWnd based display then CWnd::ShowWindow(SW_HIDE);
If you are using just win32 then ShowWindow(hWnd, SW_HIDE);

Other things people do depending on your goals

  • make the window very small
  • move the window off the visible desktop area
Greg Domjan