How does one hide a win32 app window?
I want to r开发者_高级运维un the app in silent mode by passing in a parameter, otherwise I will show the window.
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
- make the window very small
- move the window off the visible desktop area
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.
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.
create the window, omit the WS_VISIBLE flag and don't call ShowWindow.
or
When you call showWindow(), add SW_HIDE parameter.
ShowWindow(hWnd, SW_HIDE);
精彩评论