CoderSource.net
Search
When App was iconized, modeless boxes disappear ?
Started by narc at 05-12-2006 7:22 PM. Topic has 0 replies.

Print Search « Previous Thread Next Thread »
   05-12-2006, 7:22 PM
narc is not online. Last active: 5/13/2006 12:35:04 AM narc

Top 75 Posts
Joined on 05-12-2006
Posts 1
When App was iconized, modeless boxes disappear ?
Hello.

I found an interesting MFC bug with modeless dialog boxes in Visual C++ 6.0.  It can be reproduced in a couple of minutes if you have the time. ;-)

Basically, once I open up a modeless dialog box, I can iconize the application and bring it back up, and the box is still there.  But once I close it with OK or CANCEL then open it up again, iconize the app and bring the app back up, the box has disappeared.

---------------------

Now, it may be that the way I build those boxes is the problem here, so I'll submit my code here for comments.  To reproduce the error, do the following :

1) Use the MFC AppWizard to create an create a Single Document application.

2) Add a simple dialog box in the ressource editor.  No bells or whistles.  Create a new class with class Wizard for this dialog.

3) Add a single menu item to call the dialog box. Use ClassWizard to create a command message with this menu item.  For my tests, I have created this message on two seperates apps, one using the CMainFrame class, the other using the application-defined View class with identical results.  So, I don't think that either location is better for in this case.

4)  Depending if you use CMainFrame class or the View class, add to it's header file the appropriate #include from the dialog box's class.  Add an a pointer to this class as a member value.  Set the pointer to NULL in the class contructor


So far you should have something like this (this exemple uses CMainFrame) :
///////////////////////

class CMainFrame : public CFrameWnd
{
 
protected: // create from serialization only
CMainFrame();

DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:

MyDlg *dlg;


...

}

...

CMainFrame::CMainFrame()
{
    // TODO: add member initialization code here
    dlg = NULL;

}
///////////////////////

5) Now the nitty-gritty, add this code to the function called by the menu:

void CMainFrame::OnShowMydlg()
{
    if (!dlg)
    {
        if ((dlg = (MyDlg *) new MyDlg()))
            dlg->Create(IDD_DIALOG1, this);
    }

    if (dlg)
    {
        dlg->ShowWindow(!dlg->IsWindowVisible());
    }
}

Compile and run.  Activate the box with the help of the menu.  Since the pointer is null, it will create a new Dialog box and show it.  Use only the menu  to toggle the box.  Minimize the app while the box is showing and bring it back up: the box is still there. 

But if you use the OK or CANCEL button, or click on the top X, show the box again using the menu then iconize the app.  Bring it back up: voilà! The box has disappeared.

I guess it all comes down with the way I'm build my modeless box.  Or some extra code I need to deal with in order to restore the dialog box properly.  If anybody has insights about this, let me know.

Cheers.



   Report 
Codersource.Net » Programming » MFC Programming » When App was iconized, modeless boxes disappear ?

MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Welcome to Codersource.Net Login | Register | Faq  

Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us