Solved

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

Posted on 1998-11-17
7
1,458 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now