I want to run the app in silent mode by passing in a parameter, otherwise I will show the window.
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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With