|
-
July 28th, 1999, 07:26 AM
#1
MultiThreading Problem!!!- Urgent...
Hi,
I have a problem. I have written a multithreaded program and I have used worker threads for this. ie., pWinThread = AfxBeginThread(MyThread,GetSafeHwnd(),THREAD_PRIORITY_NORMAL,0,0,NULL);
and the MyThread is .....
UINT MyThread(LPVOID pParam). This is working fine and I am doing some continuous drawing in this thread....But, the problem arises when I want to call/Create one of the modless dialog boxes I have in my application.I get an error Saying the modless dialog object which I have in my dialog class is not defined.i.e., From this thread function(which is global)..I am not able to access the member objects of any of the classes.
Tell me how to getaway with this problem. If the solution is using User interface thread please tell me how to use it.
Thanks in Advance..,
Vittal
-
July 28th, 1999, 07:31 AM
#2
Re: MultiThreading Problem!!!- Urgent...
are you trying to call a functoin that shows a preexisting dialog, or do you just want to instanciate the dialog class from the thread?
miked
-
July 28th, 1999, 07:35 AM
#3
Re: MultiThreading Problem!!!- Urgent...
I would use a user message to handle this. Create a user message (#define MY_MESSAGE (WM_APP + 1000)) add a handler in the class you are creating your thread in. Then your thread using the hwnd you passed in could send/post a message to the hwnd supplied ::SendMessage(hwnd, MY_MESSAGE, 0,0); and then in the handler display your dialog.
HTH,
Chris
PS if you have more than one dialog to display use the wparam & lparam to let the handler know which one, or use a seperate message for each.
-
July 28th, 1999, 08:00 AM
#4
Re: MultiThreading Problem!!!- Urgent...
I want to Instanciate the dialog class from the Thread....Any Ideas??
-
July 28th, 1999, 08:17 AM
#5
Re: MultiThreading Problem!!!- Urgent...
then it should be no problem at all.
...
#include "MyDialogClassHeader.h"
...
UINT MyThreadFunc(lpVoid lParam)
{
//If this is in a dll do this line
AFX_MANAGE_STATE(AfxGetStaticModuleState());
...
//Instanciate Dialog
CMyDialogClass dlg;
...
//If modal
dlg.DoModal();
//Or if no modal
dlg.Create(...);
dlg.ShowWindow(SW_SHOW);
...
}
hope that helps you out.
miked
-
July 29th, 1999, 12:47 AM
#6
Re: MultiThreading Problem!!!- Urgent...
Hi Thanks a lot...What you said works fine but, the Modless dialog box, gets created,pops up and then disppears. I dont know why? I am calling dlg.ShowWindow(SW_NORMAL) soon after calling Create. Still it doesnt work. Can you just tell me a solution for this...
Thanks
waiting for ur reply....
Vittal.
-
July 29th, 1999, 07:14 AM
#7
Re: MultiThreading Problem!!!- Urgent...
is your dialog object going out of scope? if so then you may have to make it global or maybe static. what's going on is that it'll create the dialog and show it, but since it's modeless, processing continues, so if the object goes out of scope, it disappears.
miked
-
July 29th, 1999, 07:36 AM
#8
Re: MultiThreading Problem!!!- Urgent...
Hi,
What you said is right. i have made it global and the dialog remains there as long the thread is executing and one the thread terminates, the dialog also gets closed. Thats OK but the dialog which gets popped up is not showing any of the controls on the dialog box(List Box etc). Please help me with this.
one more thing is how to make the dialog static.
Waiting for ur reply...
Vittal
-
July 29th, 1999, 07:44 AM
#9
Re: MultiThreading Problem!!!- Urgent...
are you creating the dialog with the proper create statement:
MyFunction
{
MyDialog.Create(IDD_MYDIALOG);
MyDialog.ShowWindow(SW_RESTORE);
MyDialog.UpdateWindow();
}
as far as making it static goes, you do it this way instead of making it a global:
MyFunction
{
static CMyDialogClass MyDialog;
MyDialog.Create(IDD_MYDIALOG);
...
}
hope that helps
miked
-
July 29th, 1999, 07:59 AM
#10
Re: MultiThreading Problem!!!- Urgent...
Hi,
Thanks a lot for ur patience and timely help. I am working on it. Still some problems are there. I will get back to u if there are any problems.
Thanks again...
Vittal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|