How to hide win32 application window?

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

+6
c ++ winapi mfc
source share
5 answers

ShowWindow(... SW_HIDE ...) not working?

The best practice here is not to create a window in the first place. Nothing forces you to create a window in InitInstance. Although, if you work with MFC, there is probably a lot of your application / domain / business logic, it is closely connected with these MFC message handlers, etc. In this case, the window should exist.

+10
source share

If you have a display based on MFC CWnd , then CWnd::ShowWindow(SW_HIDE);
If you use only win32, then ShowWindow(hWnd, SW_HIDE);

Other things that people do depending on your goals.

  • make the window very small.
  • move the window from the visible desktop area.
+6
source share

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

Another way to hide a window and never show it, but still create it, is to not call ShowWindow with SW_HIDE on it and create it using CreateWindow / CreateWindowEx and do not set the WS_VISIBLE flag in the dwStyle parameter.

+2
source share

I think the best solution would not be to create a 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 a window.

+2
source share

create a window, omit the WS_VISIBLE flag and do not call ShowWindow.

or

When you call showWindow (), add the SW_HIDE parameter.

 ShowWindow(hWnd, SW_HIDE); 
+1
source share

All Articles