Solved

How to bring AfxMessageBox()  to the front of display?

Posted on 1998-11-17
7
1,477 Views
Last Modified: 2013-11-20
In my application, there is a BusResetThread to detect device's bus reset, when the thread receives the Bus reset message, it will call a function in my CDoc file to do AfxMessageBox() to inform user to restart software. Somehow, the message box only shows on the task bar, my guess is that the message is displayed in the background. If I click on message box icon on the task bar, the message box shows ok. And from this point on, if the thread has a busreset, the message box will always display in the front. Why did it not shown at the foreground the very first time this thread ask CDoc's funtion to do AfxMessageBox?
0
Comment
Question by:nicolet
7 Comments
 
LVL 2

Expert Comment

by:jstolan
ID: 1324850
It sounds like a similar problem I had with an Automation project.  Here's what I did:

The first time the automation object is called I do this:

// Initialize window to minimum size, off-screen, top
AfxGetMainWnd()->SetWindowpos(&CWnd::wndTop,-50,-50,1,1,SWP_NOACTIVATE);
// Show the window this way, then hide it
AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL);
AfxGetMainWnd()->ShowWindow(SW_HIDE);

Whenever the dialog box is shown I do a show normal on the main window and then hide it after completion like this:

AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL);
PMyDialog->DoModal();
AfxGetMainWnd()->ShowWindow( SW_HIDE );

I don't know if your problem is exactly the same, but the symptoms were identical.  Give it a try and see if it helps.
0
 

Author Comment

by:nicolet
ID: 1324851
I don't think my symptom is quite the same as yours.

In my application, all the rest of the places using AfxMessageBox(), the message box all shows on top of my application's main window. However for this case, my main window is still on the foreground of my display, but the AfxmessageBox is in the background. I have to go to the task bar to find it and restore the message box.

0
 
LVL 12

Expert Comment

by:migel
ID: 1324852
You can use ::MessageBox API function and specify NULL (HWND - parameter) as parent;
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Expert Comment

by:wyy_cq
ID: 1324853
set your frame window to the topmost and then you can call AfxMessageBox(...);
SetWindowPos(...)can set the window to the topmost

SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );

suppose the pF is the frame window point;
pF->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
AfxMessageBox(...);
pF->SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

0
 

Author Comment

by:nicolet
ID: 1324854
I put the following 3 lines in my CDoc as suggested, it leads to a software crash. I don't think this works!

((CMainFrame *)AfxGetMainWnd())->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
AfxMessageBox(" Bus reset, Please restart application.", MB_OK|MB_ICONSTOP , 0 );
((CMainFrame *)AfxGetMainWnd())->SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 50 total points
ID: 1324855
Did you try to use MB_SYSTEMMODAL  window style with AfxMessageBox. It shuld work.

AfxMessageBox (_T ("Restart"), MB_SYSTEMMODAL);

0
 

Author Comment

by:nicolet
ID: 1324856
use MB_SYSTEMMODAL  window style with AfxMessageBox() works.
Thank you!

Is there any thing that I should be aware of using MB_SYSTEMMODAL in AfxMessageBox(). Any side effect of using MB_SYSTEMMODAL?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 108
How to match SAS datasets by multiple key variables and then rename and create new variables? 2 89
Change to event 1 114
Not needed 13 113
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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