?
Solved

Modal Dialog in different thread

Posted on 2006-06-02
10
Medium Priority
?
713 Views
Last Modified: 2013-11-20
I'm creating a dialog in a different thread. Basically is just a "waiting dialog" which will be displayed during a long time process. The thing is the dialog is not modal to the parent window. How can I make it to be modal to the parent window if is opened in a different thread?

Thanks,
A-
0
Comment
Question by:sparkythedog
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16822305
Disable parent window. This is the way how modal dialogs are internally implemented, when they are called by standard way.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16824038
Possibly silly question - why do you have another thread?

A second thread is usually implemented to let the main app continue whilst the second thread is busy.  From your question you sound like you want the multi-thread to behave as if it was only a single thread.
0
 

Author Comment

by:sparkythedog
ID: 16825538
Thanks for your replies.
In the main app I have several points where long-time processing operations might occur, and I want to display a waiting dialog during the executions of one of these operations. If I will use just a simple dialog with DoModal the main thread will be stopped until that dialog will be closed.

Another solution might be to use a modeless dialog in the main thread and disable the parent (as Alex said) until the long-time process will be finished.

Thanks,
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16826271
Doing the processing in the dialog you call with DoModal isn't an option I take it.


I don't know all of your requirements - I have just made the comment because it sounds like there could be a simpler way to achieve what you want.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16833420
sparkythedog ,
  Alternatively have a look at EnableWindow() Function...The EnableWindow function enables or disables mouse and keyboard input to the specified window or control. When input is disabled, the window does not receive input such as mouse clicks and key presses. When input is enabled, the window receives all input.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/enablewindow.asp

So you may call EnableWindow(FALSE) on your dialog. This will prevent any and all user input. When finished, reenable your dialog. Presenting a busy cursor when the mouse floats over your dialog is a desirable plus too...

-MAHESH
0
 
LVL 5

Accepted Solution

by:
bastibartel earned 2000 total points
ID: 16953367
Hi sparkythedog,

You've already mentioned the solution. Create a modeless dialog for the processing period.

1. Create a new dialog resource (IDD_WAITDLG), create a corresponding class (CWaitDlg).
2. Customize your dialog resource, e.g.  add an edit box and/or add an icon.
3. Maybe associate a CString member CWaitDlg::m_InfoText with that edit box.
4. Use the wait dialog as below.

void OnDoWork()
{
  CMyDialog dlg;
 
  //** pass some text to wait dialog,  
  //** assuming you have defined a CString member 'm_InfoText'  assciated with an edit-box
  dlg.m_InfoText = "I am working really hard";
 
dlg.Create(IDD_WAITDLG);
  dlg.ShowWindow(SW_SHOW);         // can be ommited if WS_VISIBLE is set for dialog resource

  //** Work really hard
  Sleep(100000);

  dlg.DestroyWindow();
}

There is no need to disable the main wnd as it will hang anyway.
If you want the main dialog or the wait dialog to still accept input, yell "YES I DO" and I will get back to you ;-)

0
 
LVL 5

Expert Comment

by:bastibartel
ID: 16953462
Hi sparkythedog

I'm not sure what to make of you 'different thread' issue, but you may not simply launch dialogs or message boxes from with a worker thread.
Instead you post a message to the main dialog window a let it do the dialog popping.

Cheers,
Sebastian
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17029870
Hi sparkythedog,

Are you making any progress on your Wait Dlg issue ?
Do keep uns informed, or keep asking for better explanations;-)

Cheers,
Sebastian
0
 

Author Comment

by:sparkythedog
ID: 17134099
Thanks,
I'll be back to you soon

Cheers,
A-
0
 

Author Comment

by:sparkythedog
ID: 17236953
It seems that the modeless dialog is a better solution. First I created a modal dialog in a different thread, but the results were very unpredictable, the waiting dialog itself behaved very weirdly, sometimes appeared in the right corner of the screen sometimes it showed with different sizes. After this, I implemented it as a modeless and displayed before the starting of worker thread.

Thanks-
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question