Solved

AfxMessageBox on A Modeless Dialog giving problem

Posted on 2006-06-29
11
873 Views
Last Modified: 2013-11-20
Hi Friends
  I have created an MFC application in which a Modeless Dialog  has been created.
In the OnInitDialog of the Modelsss Dialog i have displayed a AfxMessageBox.

The problem is that sometimes the AfxMessageBox gets hidden & i am not able to click the same.

Am i doing wrong as said above ?

Regards
0
Comment
Question by:vikrant_kpr
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17008324
check MS knowledge based article Q138681 and see if this is case with you..
http://www.kbalertz.com/Q138681/Windows.Flash.Disappear.Applications.aspx <==

As said above to resolve this problem, change the line that sets the m_pMainWnd to point to dialog object, into a comment. Or set m_pMainWnd for the CWinApp-derived object to NULL before control gets to the CWnd::OnNcDestroy function for the dialog object. One way of doing this is to override the OnNcDestroy function for the CDialog-derived object. In the overridden function, set the m_pMainWnd to NULL before calling the base class.

In short remove the "m_pMainWnd = &dlg" kinda line from 'InitInstance()' and check if your message-boxes appears......

-MAHESH
0
 

Author Comment

by:vikrant_kpr
ID: 17008412
Hi Mahesh
   Thanks for the same , but it talks of creation of a Modal Dialog when closing one Modal Dialog.
My problem is that when creating a Modal Dialog on Modeless Dialog , the Modal Dialog disappears sometimes.

Regards
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17008435
still have you checked by modifying same if your AfxMessageBox is visible ...also can you post your initdialog code ?
0
 

Author Comment

by:vikrant_kpr
ID: 17008465

BOOL CMyDialog::OnInitDialog()
{
.
.
.
AfxMessageBox("Hello"");

Created like as given below
CMyDialog* vl_pDialog=new CMyDialog(AfxGetMainWnd());
vl_pDialog->Create(IDD_DIALOG1);
vl_pDialog->ShowWindow(SW_SHOW);


0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17008543
I cannot see any problems with this .....if you create one simple dialog and one child dialog and simply invoke AfxMessageBox on InitDialog of child dialog it works..you may try that by building sample dialog based application......

Its happening sometimes or you never get messagebox ?...try by removing your dialog and recreating it from scratch..

-MAHESH
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.

 

Author Comment

by:vikrant_kpr
ID: 17008568
Mahesh
   Yes even i cannot see anything wrong into the same, but still sometimes the messagebox goes hidden.
The Application is used by the users & they face the problem & is not replicable on my pc.

Regards
 
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 75 total points
ID: 17008702
Make certain that the dialog is actually displayed before the message box

CMyDialog* vl_pDialog=new CMyDialog(AfxGetMainWnd());
vl_pDialog->Create(IDD_DIALOG1);
vl_pDialog->ShowWindow(SW_SHOW);   //<<-----------------
vl_pDialog->DisplayMessageBox();    //<<----------------

and in the CMyDialog a public function
void CMyDialog::DisplayMessageBox()
{
  AfxMessageBox("Hello");
}
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 50 total points
ID: 17011710
>>>> but still sometimes the messagebox goes hidden.

How to you invoke the modeless dialog? By keyboard Enter or Space on some button? Or by mouse-click? If yes, the problem could occur because you made a couple of key strokes or clicks and the last keystroke or mouseclick happens after the messagebox was shown. Hence, the dialog or view where you pressed the button was invoked and the messagebox was hidden cause it was modal to the modeless dialog but not to the first dialog.

Regards, Alex
 
0
 

Author Comment

by:vikrant_kpr
ID: 17016379
Alex
  The Modelsss dialog is invoked by an Icon on the Toolbar.
User clicks on that icon or alternatively can select from the menu.
Now how the problem can be resolved ?

Regards
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17016429
Have you tried my suggestion?
0
 

Author Comment

by:vikrant_kpr
ID: 17016457
Thanks Alex
I will try that
Actually for getting the actual result
i will have to deploy my application to the users & then i will get the report

Thanks
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

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 56
Excel Use VBA to get user's Mac Address for their computer 5 109
string initialization in java 11 109
post4 challenge 28 92
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

919 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

17 Experts available now in Live!

Get 1:1 Help Now