Re: Modal dialog as thread



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,
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 message
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
the
dialog 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
you
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]


Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • My Review of MFC Beta
    ... Well....after reviewing the MFC beta here is my opinion, ... the new enterprise controls introduced to MFC are the Dockers and the ... responsible for compiling and generating the dlls) exposed as API? ...
    (microsoft.public.vc.mfc)
  • Re: How much oop is too much oop?
    ... > Modal dialogs go back to the Mac and before, ... > because modeless is too hard to implement in MFC. ... MFC programs do not get it right. ... IIRC the parent window can still get some messages when a modal ...
    (microsoft.public.vc.language)
  • Re: why microsoft choose mfc rather than wtl?
    ... "It will cost you k dollars and n months to product this in MFC. ... I did three new controls this morning (one each derived from ... >> documentation)? ... >WTL is kinda neat ... ...
    (microsoft.public.vc.mfc)
  • Re: How much oop is too much oop?
    ... > MyDialog dlg; ... > int res = dlg.DoModal; ... > modal dialog where a modeless one would be a better choice. ... modeless is too hard to implement in MFC. ...
    (microsoft.public.vc.language)
  • Re: My Review of MFC Beta
    ... Most of this MFC beta covers what most people consider as just ... the new enterprise controls introduced to MFC are the Dockers and the ... responsible for compiling and generating the dlls) exposed as API? ... We need all the sleek looking Grid controls, report controls, mult- ...
    (microsoft.public.vc.mfc)

Loading