Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AfxMessageBox from a worker thread?

540 views
Skip to first unread message

Erich Hermann

unread,
Sep 23, 1998, 3:00:00 AM9/23/98
to
Hi,

I have my main thread handling all the MFC-window stuff. In a worker
thread, started by the main-thread, I want to display a message box.

1. AfxMessageBox( "text" ) leads to an error deep in mfc-code

2. MessageBox( (HWND)AfxGetMainWnd(), "text", "heading", MB_XXX )
doesn't display a message box and returns immediatedly.

3. MessageBox( NULL, "text", "heading", MB_XXX ) displays the message
box behind the windows, i.e. can only be seen when changing via the
task list to the message-task.

3a. MB_XXX, all values are ignored: MB_OK, MB_TOPMOST, MB_SYSTEMMODAL,
...


- Why is version 1. not working?

- How can I display the message box in from of the apps window, so
that it can be seen by the user.

- Why are the MB_XXX's ignored in 3./3a.

Please help.

Erich

To Send Email, remove the dashes at the beginning of the e-mail-address!
_____________________________________________________________________
Erich Hermann
ETAS GmbH & Co. KG e-mail: ---Erich...@ETAS.de
Borsigstr. 10 Phone: (+49)711-89661-144
D-70469 Stuttgart Fax: (+49)711-89661-107

John Fisher

unread,
Sep 23, 1998, 3:00:00 AM9/23/98
to
Erich Hermann <---Erich...@ETAS.de> wrote in message
<3608f044...@news.fr.bosch.de>...

>Hi,
>
>I have my main thread handling all the MFC-window stuff. In a worker
>thread, started by the main-thread, I want to display a message box.
>
>1. AfxMessageBox( "text" ) leads to an error deep in mfc-code
>
>2. MessageBox( (HWND)AfxGetMainWnd(), "text", "heading", MB_XXX )
>doesn't display a message box and returns immediatedly.

Number 2 is pretty close, change (HWND)AfxGetMainWnd() to
AfxGetMainWnd()->m_hWnd. That should work, but it might be better on
initialization of your thread to get the hWnd you desire and save it in a
member variable of the thread (if you know the window will stay there as
long as your thread needs it).


>
>3. MessageBox( NULL, "text", "heading", MB_XXX ) displays the message
>box behind the windows, i.e. can only be seen when changing via the
>task list to the message-task.
>
>3a. MB_XXX, all values are ignored: MB_OK, MB_TOPMOST, MB_SYSTEMMODAL,
>...
>
>- Why is version 1. not working?


It appears that your thread doesn't have a valid window for AfxMessageBox()
to use.

>
>- How can I display the message box in from of the apps window, so
>that it can be seen by the user.
>
>- Why are the MB_XXX's ignored in 3./3a.

No idea. Should be fixed with solution to number 2.

>
>Please help.
>
>Erich


--
John

God is the ultimate programmer. He designed the universe!


Uwe Kotyczka

unread,
Sep 23, 1998, 3:00:00 AM9/23/98
to
Perhaps you could give the main frame's handle to
the thread (via the ,say, m_pTrheadInfo) when calling it.

Did not try this, it's just an idea.

Erich Hermann schrieb:

> Hi,
>
> I have my main thread handling all the MFC-window stuff. In a worker
> thread, started by the main-thread, I want to display a message box.
>
> 1. AfxMessageBox( "text" ) leads to an error deep in mfc-code
>
> 2. MessageBox( (HWND)AfxGetMainWnd(), "text", "heading", MB_XXX )
> doesn't display a message box and returns immediatedly.
>

Erich Hermann

unread,
Sep 24, 1998, 3:00:00 AM9/24/98
to
"John Fisher" <johnREM...@enrnews.com> wrote:

>Number 2 is pretty close, change (HWND)AfxGetMainWnd() to
>AfxGetMainWnd()->m_hWnd. That should work, but it might be better on
>initialization of your thread to get the hWnd you desire and save it in a
>member variable of the thread (if you know the window will stay there as
>long as your thread needs it).

AfxGetMainWnd()->m_hWnd is ok. But ...

>>- Why are the MB_XXX's ignored in 3./3a.
>
>No idea. Should be fixed with solution to number 2.

MB_XXX's are still ignored (I don't get the buttons, the icon, ...)
and I could not bring the message box in front of all the other
windows. Problem: when the message box is to be displayed, my
main-window may be behind some other windows or even hidden (SW_HIDE).
So I tried this, before opening the message box:

AfxGetMainWnd()->ShowWindow(SW_RESTORE);
if (IDNO == MessageBox( AfxGetMainWnd()->m_hWnd, s,
"Heading", MB_TOPMOST || MB_YESNO || MB_ICONHAND
|| MB_SYSTEMMODAL )) {
...
}

ARGHH, it works fine, if the window is hidden, but when it's
minimized, it's displayed behind the other windows!?! :-(

BTW, how do I get the display status of a Window?

0 new messages