Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one hide a win32 app window?

Tags:

c++

winapi

mfc

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

like image 882
Brian T Hannan Avatar asked Jun 10 '10 17:06

Brian T Hannan


People also ask

What is Win32 used for?

The Win32 API (also called the Windows API) is the native platform for Windows apps. This API is best for desktop apps that require direct access to system features and hardware. The Windows API can be used in all desktop apps, and the same functions are generally supported on 32-bit and 64-bit Windows.

What is an overlapped window?

An overlapped window is a top-level window (non-child window) that has a title bar, border, and client area; it is meant to serve as an application's main window. It can also have a window menu, minimize and maximize buttons, and scroll bars.

What is Hwnd?

A Windows window is identified by a "window handle" ( HWND ) and is created after the CWnd object is created by a call to the Create member function of class CWnd . The window may be destroyed either by a program call or by a user's action. The window handle is stored in the window object's m_hWnd member variable.


3 Answers

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.

like image 196
Swingline Rage Avatar answered Oct 05 '22 05:10

Swingline Rage


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
like image 32
Greg Domjan Avatar answered Oct 05 '22 05:10

Greg Domjan


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.

like image 25
Jacob Avatar answered Oct 05 '22 04:10

Jacob