c++ - How to show a MFC dialog without stealing focus on the other window -


I have a dialog shown with ShowWindow (hWnd, SW_SHOWNOACTIVATE); But this does not work, the new dialog is still stealing the focus, why is it?

Here are some code snippets from my program, the MFC communication class associated with QueryWindow dialog is:

Query window window; //window.DoModal (); Window.Create (QueryWindow :: iodine disorder); Window.ShowWindow (SW_SHOWNOACTIVATE);

There are a few ways to leave the dialog by focus:

  • Create OnInitDialog () to return the zero value to you Example:

    BOOL Query Window :: OnInitDialog () {CDialog :: OnInitDialog (); return false;

    This is the best and most accurate solution.

  • Add Style WS_EX_NOACTIVATE In your dialog, you can edit the dialog resource properties or change it to runtime:

      BOOL QueryWindow :: PreCreateWindow ( CREATESTRUCT and CS) {cs.dwExStyle | = WS_EX_NOACTIVATE; Return CDialog :: PreCreateWindow (CS); Side effects: You can use control over your window, but it will appear that it was not active.  
  • The final path is to save the foreground window before creating your dialog and finally setting the foreground window:

      BOOL QueryWindow :: Create ( LPCTSTR lpszTemplateName, CWnd * pParentWnd) {CWnd * pForeground = GetForegroundWindow (); Const BOOL bRes = CAlertDialog :: Create (lpszTemplateName, pParentWnd); If (pforeground) pforeground- & gt; SetfandWindo (); Returns BRS; }  

    This is a price solution because potentially you can get flicker.

Important!

Do not forget to control the following API calls:

  • Appearance - You can use SW_SHOWNOACTIVATE but can not use SW_SHOW
  • SetWindowPos - Add SWP_NOACTIVATE flag

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -