[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Modeless Dialog and Threads

Posted on 2001-09-02
9
Medium Priority
?
374 Views
Last Modified: 2013-11-20
Hello again folks, Here's my situation:

I have an app that starts a worker thread that parses an XML File. As this worker thread is parsing, I want to update a modeless dialog which is displayed before the worker thread is started. This modeless dialog is sort of a progress dialog as I want it to display the progress of the parsing that the worker thread is performing.

Now my problem is that when the Modeless is displayed and the worker thread starts, I can't interact with the modeless until the worker thread is finished.

Any idea what could be happeing?
0
Comment
Question by:ruff_ryder
  • 4
  • 4
9 Comments
 
LVL 2

Accepted Solution

by:
xu2000 earned 600 total points
ID: 6449579
Hi,
1. Create your modeless dialog (m_pYourDlg is a member varible)
if(m_pYourDlg->GetSafeHwnd() == 0)
{
     if(m_pYourDlg->Create() == TRUE)
     {
          ...
          m_pYourDlg->ShowWindow(SW_SHOW);
     }
}

2. Start your workthread,
CWinThread* pThread = AfxBeginThread(WorkThreadProc, m_pYourDlg->GetSafeHwnd(),
                   THREAD_PRIORITY_NORMAL);
                   
3. In your workthread
UINT WorkThreadProc(LPVOID pParam)
{
     ...
     while(...)
     {
          parse XML file
          ...
          ::PostMessage((HWND)pParam, WM_STEPIT, 0, 0);
     }
     return 0;
}

4. Define a user message WM_STEPIT and add a function for it in YourDlg.cpp
LRESULT CYourDlg::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
     ...
     step your progress control
     ...
}

Another way is define a global varible to interact with the modeless dialog

My 2 cents
Xu
0
 

Expert Comment

by:rsraj
ID: 6451013
Hi,

Instead of PostMessage, you may use SendMessage which is synchronous.

Also to ensure your modeless dialog box gets its due time,
you may use Event object.
After PostMessage you may use WaitForSingleObject(hEvent...) to ensure that the dialog box PostMessage function processesing is successful.

rgds
sun
0
 
LVL 2

Expert Comment

by:xu2000
ID: 6451035
Hi,
Progress control is only indicator of parsing file, important thing is parsing file, so I think PostMessage is the better way.

Xu
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Author Comment

by:ruff_ryder
ID: 6451826
Hi guys, Im new to the whole Windows Programming (MFC Programming) so if you can, would you give a little more detail as to what the difference is between SendMEssage and PostMessage ?
0
 
LVL 2

Expert Comment

by:xu2000
ID: 6452039
The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
The PostMessage return immediately.

MSDN has the detail. If encount problem about windows programming, consult MSDN first.

Xu
0
 
LVL 2

Expert Comment

by:xu2000
ID: 6456279
Hi ruff_ryder:
Do you have other questions?
Xu
0
 
LVL 3

Author Comment

by:ruff_ryder
ID: 6540181
Hi guys, sorry I've been so long with this but I'm just getting time to get back to it. I've tried using both PostMessage and SendMessage but neither is giving me the results I require ... the main window is still frozen while the worked thread is processing and i only get back control after its done ...
0
 
LVL 3

Author Comment

by:ruff_ryder
ID: 6622530
Hi guys, I found a workaround to the prob. Used a bit of callback to achieve the required result.

Thanks for your help though. Since xu2k had the msot input I'll give him the points.
0
 
LVL 3

Author Comment

by:ruff_ryder
ID: 6622538
Tried your code in a separate prog and it works :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

834 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