How to create a Modal dialog in a workflow (non-UI thread)?

I wrote an example MFC application in which there are two threads: -Small thread (UI thread) -Worker thread (non-UI thread)

I have a special requirement for creating a dialog Modalin a non-UI (workflow). When I create an object CDialogand call DoModalon the same one, it works. A dialog is created and acts as modal to the application. (Win XP SP2) But this does not work on the Windows 2003 server machine. The behavior on the 2003 server is that the modal dialog goes beyond the main application window and the dialog will be brought to the fore only when I click on the main window. It does not act as a modal dialog for my application.

What could be the problem - any ideas?

If creating user interface controls in a thread other than the UI is a problem, is there any Win32 API that will allow me to associate my workflow with the main user interface thread to DoModalhappen in the main thread. I tried AttachThreadInput , but it does not work.

+3
source share
4 answers

First of all, I would like to agree with other posters that it is probably better to show the dialog in the main user interface thread.

However, if necessary, you can make the dialog in another thread modal as follows:

  • When creating a dialog, pass your active window as the owner.
  • , EnableWindow(FALSE). , . , , EnableWindow(TRUE).
  • , .

, (2) , (1), MFC, , . , Win32. , (1) (3) .

+2

GUI- . , HWND, , , . 16- Windows, . , HWND . The Old New Thing " " (Part 1 2 3 Addendum).

, , . , , , . en-/disabling windows , HWND, .

, , . - SendMessage , GUI . , PostMessage , PostThreadMessage , .

+2

2003, , ::SendMessage() .

+1

, , . , , .

0

Source: https://habr.com/ru/post/1726699/


All Articles