• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

App modal dialog to display progress of some lengthy operation

Hello experts.

This question has been asked several times in different variations in this forum, but none of the answers suits my scenario.  I hope to get an answer that does.

In a standard MFC command message handler, I call a FuncA), that starts doing some file analysis.  This may take very long time, so I need a dialog box with a progress control to report on how this function is doing.  

Here are the constraints of the problem:

FuncA() resides in a remote DLL.  It must run in the same thread as the MMI that calls it, so I cannot accept answers that suggest splitting threads.

The App modal dialog, AppDlg, should be displayed as
Funca() begins its work. From what I understand, it cannot be a modal dialog, but modeless (so it won't steal the message loop), but please correct me if I am wrong.

AppDlg has a Cancel button, that when clicked, should cause FuncA to abort its operation

FuncA which runs in a loop should post a message to the dialog with progress indication every iteration.

I tried something like

while ( PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE  ) )
{
TranslateMessage(&msg);
DispatchMessage( &msg );
}

in FuncA(), and this is probably the right direction, but I couldn’t see messages, other than mouse messages(???).  Also, the main application window should not get command messages(But should get WM_PAINT).

Well I hope my modest question gets you attention and your valueable time.
10x.
0
trabar
Asked:
trabar
1 Solution
 
SteveGTRCommented:
0
 
DanRollinsCommented:
What I do is create a Modeless dialog and put all of the processing inside of that dialog class.  When a Modeless dialog is active, bot it and its parent window continue to receive and handle messages normally.

One normally needs to take some special actions in the parent window, such as disabling certain menu items or providing other U/I clues to prevent (for instance) the user from starting a second instance of that task.

The other option (which you have rejected) is to split off a secondary thread and run a Modal dialog in that thread.

-- Dan
0
 
trabarAuthor Commented:
Thanks a lot - just what we needed
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now