Solved

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

Posted on 1998-11-17
7
1,466 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

937 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

3 Experts available now in Live!

Get 1:1 Help Now