Solved

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

Posted on 1998-11-17
7
1,515 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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);

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 84
Tab names are off by one 5 54
how to monitor remote shell execution on linux 9 113
mapBully challenge 6 200
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

751 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