Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-11-17
7
Medium Priority
?
1,559 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
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 200 total points
ID: 1324855
Did you try to use MB_SYSTEMMODAL  window style with AfxMessageBox. It shuld work.

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

1
 

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?
1

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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