Re: Modal dialog as thread
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 07 Nov 2007 12:40:57 -0500
You are heading down a path of danger and chaos. This is the wrong approach. You will
keep spending more and more time trying to find and fix problems you have never even
thought of, keeping this thread going with more and more problems which you will uncover
one at a time, and a week from now you will realize that the problem is unfixable. I
suggest that you should abandon this approach now, instead of having to wait until next
week when you will have merely wasted a week.
Note that the desire to put UI objects into threads is inversely proportional to the
threading and MFC experience of the person doing it. Experienced MFC programmers would
not even consider this solution as viable. We would choose a modeless dialog in the main
GUI thread. It is easy to do, quick to implement, and will take far less time than
uncovering your various disasters one at a time.
joe
On Wed, 7 Nov 2007 10:36:54 +0200, "Rami" <rami@xxxxxxxxx> wrote:
Thanks,Joseph M. Newcomer [MVP]
I'll certainly follow your advises in the next version, but for the time
being I want to use the thread dialog.
My question-
Can I use the dialog C++ object pointer from the main thread instead of
using the dialog window handle?
In this case setting controls values would be much easier. Of course, I'll
have to pass the pointer to the main thread instead of passing the handle...
Regards
Rami
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:eQhZ9MKIIHA.5208@xxxxxxxxxxxxxxxxxxxxxxx
"Rami" <rami@xxxxxxxxxx> wrote in messagethe
news:OktKc2JIIHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
The following 3 step procedure was taken form CodeGuru article named
Convert modal dialogs to modeless by Jon S. Kyle
It works greate but I can't figure out how to modify controls text on
youdialog box while its already diplayed.
Can someone advise please?
Rami
1. In your header file define a CWinThread-derived class...
class CDialogThread : public CWinThread
{
DECLARE_DYNCREATE(CDialogThread)
CDialogThread() {};
virtual BOOL InitInstance();
};
2. Put this in your implementation file (where CSomeDialog is a
conventional dialog class defined the usual way).
IMPLEMENT_DYNCREATE(CDialogThread, CWinThread)
BOOL CDialogThread::InitInstance()
{
CSomeDialog dlg;
dlg.DoModal();
return FALSE;
}
3. To create an instance of your (now-modeless) modal dialog, do this...
AfxBeginThread ( RUNTIME_CLASS(CDialogThread) );
Well, life is much simpler and less troublesome (especially for a MFC
threading newbie) if you put all GUI in the main thread. So first you
should consider making a modeless dialog in your main thread. Why would
want to put a modal dialog in a secondary thread? This is probably a
mistake.
But if you must, then what you need to do is make the dialog's HWND
available to the main thread. Perhaps store it someplace during the
dialog's InitInstance. The main thread can then use
::PostMessage(dlghwnd,....) to post custom messages to the dialog. The
dialog message handlers, in turn, can access and update the dialog's
controls. See example here: http://vcfaq.mvps.org/mfc/12.htm
--
Scott McPhillips [VC++ MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Modal dialog as thread
- From: Tom Serface
- Re: Modal dialog as thread
- References:
- Modal dialog as thread
- From: Rami
- Re: Modal dialog as thread
- From: Scott McPhillips [MVP]
- Re: Modal dialog as thread
- From: Rami
- Modal dialog as thread
- Prev by Date: Re: display message in work thread
- Next by Date: Re: How can i a resource to an Document/view application?
- Previous by thread: Re: Modal dialog as thread
- Next by thread: Re: Modal dialog as thread
- Index(es):
Relevant Pages
|
Loading