Self closing Modeless dialog open from Modal Dialog switches Active Window in Windows.

Swapnil Prajapati 20 Reputation points
2023-01-17T08:57:42.1733333+00:00

I have a Multiple document application.

From a menu / toolbar I open a Modal Dialog.

From this Modal Dialog , I open a Self Closing Modeless dialog.

Self Closing Modeless dialog : When the dialog is made inactive : handle WA_INACTIVE message : then I call DestroyWindow().

Thus the Modeless dialog gets auto destroyed.

After this focus does not again go in my Modal Dialog.

But, I observed that Active Window gets switched to another Window open in Windows.

I tried:

After destroying Self Closing Modeless dialog, I tried activating my Application window using AfxGetMainWnd.

		CWnd* pMainWnd = AfxGetMainWnd();
		pMainWnd->SetActiveWindow();

This helped me to avoid switching. But I am facing another issue is that My Modal Dialog is not in focus.

I tried setting Focus with SetFocus() method. But its of no use.

Please help me how can I activate & have focus in my Modal Dialog after auto destroying Modeless dialog.

I tried creating Self Closing Modeless dialog with


this->Create(MWPartImageOrientationDlg::IDD, pParent);

where pParent is the Modal Dialog.


I even tried

this->Create(MWPartImageOrientationDlg::IDD, AfxGetMainWnd());


But no benefit.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
752 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 114.7K Reputation points
    2023-01-17T09:50:57.5833333+00:00

    Try calling EndDialog( 0 ) instead of DestroyWindow.

    Remove SetActiveWindow and SetFocus.