Solved

Modeless Property Sheet disappears

Posted on 2002-03-31
4
332 Views
Last Modified: 2013-11-20
Hello fellow experts,
I'm trying to write an application which loads a modeless property sheet (Attributes.h) with two tab pages.  In order to do this, I'm using CPropertySheet.create().  The dialog displays, but only for a brief second and then closes.  Any suggestions on how to fix it?  Thanks!

Here's my code for creating the sheet:
//includes
#include "Attributes.h"
#include "LightProperties.h"
#include "MaterialProperties.h"

//here is where i try to open the sheet
BOOL OpenGLDlg::OnInitDialog()
{
     CDialog::OnInitDialog();
         
     Attributes attributes("Attributes", NULL, 0);
     LightProperties light;
     attributes.AddPage(&light);
     MaterialProperties material;
     attributes.AddPage(&material);
     attributes.Create(this, WS_CHILD);
     attributes.ShowWindow(SW_NORMAL);
//............
0
Comment
Question by:SileNcer
[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
4 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 200 total points
ID: 6909676
I understabd ur problem. U r making the dialog in a local scope.
That is

In a {} bracket block u declared a dialog
like

{
....
CDlg oDlg;
oDlg.Create(...);
oDlg.ShowWindow(SW_SHOW);
....
}

So when it reaches the closing bracket ur dlg scope will ends...
So it calls its destructor, In destructor, the dialog class will call DestroyWindow...

So the remedy is
1. create the member in a global scope ie class member
2. create the member with new operator...and eqate that operator for future deletion...otherwise it causes memory leak
3. The Domodal is the other way- But u need parent messages this is not my suggession...

GOOD LUCK
0
 

Author Comment

by:SileNcer
ID: 6909680
THANK YOU BOTH FOR YOUR HELP :)
Roshmon,
You were right... I needed to put the line:
Attributes attributes("Attributes");
outside of this function as a global.  Runs great now!
0
 

Expert Comment

by:FelixShen
ID: 6909907
try this, it work well.

    MyPropertySheet *pattributes=new MyPropertySheet("");
    PropertyOne *light = new PropertyOne();
    pattributes->AddPage(light);
    PropertyTwo *material = new PropertyTwo();
    pattributes->AddPage(material);
    pattributes->Create();

just use "new" to create your property page and property sheet. And delete them when you close property sheet window.
0

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 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