Implementing the program in the VC hide when starting

zhaozj2021-02-11  160

Recently, some people often ask in the forum, how to hide when the program is started. Here is some ways I summarized, welcome to discuss, find better ways.

For this type of problem, everyone is most probant may be to add cs.style & = ~ ws_visible in PrecreateWindow; this is not feasible. The program can still be displayed using showwindow ().

1. Procedure Based on dialog, I saw someone in the forum said that there is no way to add the showWindow (SW_HIDE) dialog in OnInitDialog (), it is not feasible. As for the reason, I think the system is in turnWindow after OnNitDialog () to make the dialog display. You can add the following code: cxxdlg :: onInitdialog () {... Sleep (5000); return true;} can be found After 5 seconds, the dialog is displayed. As for when I call it, I don't know, but we can add ShowWindow (SW_HIDE) in OnPaint () to achieve hidden purposes. However, this method, there will be A little flashing. Another way is to use SetWindowPlacement in OnInitDialog ()

GetWindowPlacement; // When recovering with modifyStyleex (WS_EX_APPWINDOW, WS_EX_TOOLWINDOW); // Remove from the taskbar.

WindowPlacement WP; WP.LENGTH = SIZEOF (WP.Flags = WPF_RESTORETOMAXIMIZED; WP.SHOWCMD = SW_HIDE; SETWINDOWPLACEMENT (& WP);

There is also a simpler way: call the following code .SetWindowPos (& WNDTOP, 0, 0, 0, 0, NULL) in OnInitDialog ();

2. Single document-based program

The method we generally adopted is to use: cxxapp :: initInstance () {// m_pmainwnd-> showwindow (sw_show);} but such a form will flash. Because MFC ActiveFrame but also in display frame, so we also need to add the following codes: void CMainFrame :: ActivateFrame (int nCmdShow) {nCmdShow = SW_HIDE; CFrameWnd :: ActivateFrame (nCmdShow);} or: int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct ) {AFXGetApp () -> m_ncmdshow = sw_hide;} By the way, the above is implemented from the taskbar to remove the button from the taskbar, so that the display is switched when the display is displayed, which can also be called Taskbarlist components Directly delete and add: ItaskBarlist's definitions are in Shobjidl.h (vs.net). You may also be manually defined: DECLARE_INTERFACE_ (ITaskbarList, IUnknown) {STDMETHOD (QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE; STDMETHOD_ (ULONG, AddRef) (THIS) PURE; STDMETHOD_ (ULONG, Release) (THIS) PURE; STDMETHOD (Hwnd) Pure; stdmethod (hwnd) Pure; stdmethod (hwnd) Pure; stdmethod (void) Pure;}; Bool CMY2App :: InitInstance () {Coinitialize (0); ITaskbarList * pObj; CoCreateInstance (CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList, (void **) & pObj); pObj-> DeleteTab (m_pMainWnd-> m_hWnd); // delete from the taskbar // pObj-> AddTab (m_pMainWnd-> M_hWnd); // Add pobj-> release (); couninitialize ();

So we can also use the form to minimize the form and remove the button on the built-in column to achieve hidden.

转载请注明原文地址:https://www.9cbs.com/read-5860.html

New Post(0)