Solved

AfxMessageBox on A Modeless Dialog giving problem

Posted on 2006-06-29
11
857 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 74
WinWaitActive parameters 12 31
dog bark java program 15 82
centeredAverage challenge 8 122
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

15 Experts available now in Live!

Get 1:1 Help Now