Reputation: 1
I require my MFC SDI application to start up inactive. It's an on-screen keyboard.
In straight Win32 it is trivial to do by simply calling ShowWindow( hWnd, SW_SHOWNA );
This does not work in MFC. I've tried various things:
Overriding OnActivate()
, OnActivateApp()
, OnCreate()
, PreCreateWindow()
of CMainFrame
.
I've also tried an override of LoadWindowPlacement()
in my app class.
Also tried things like:
AllowSetForegroundWindow( ASFW_ANY );
::SetForegroundWindow(::GetNextWindow(::GetDesktopWindow(), GW_HWNDPREV ));
No luck.
Upvotes: 0
Views: 244
Reputation: 15375
MFC application have a special parameter CWinApp::m_nCmdShow. This parameter is usually set to SW_SHOW and the application is shown and activtated. The parameter comes from STARTUPINFO. It is defined via WinMain and the MFC stores it in CWinApp::m_nCmdShow.
Thi smember is used in the depth of the framework, when the frame windows is created and need to be shown.
So set it before any window is created. If you want to show your application but don't want to activate it, set to
m_nCmdShow = SW_SHOWNA;
If you search for this, you find a bunch of articles.
Upvotes: 2