Ok, this is as far as I have been able to get in VS2005
Right Click on Dialog->Insert Dialog.
This creates a new dialog in my project. My question is, how do I get it to show up and close when a button is pressed?
Thanks,
Matt N
Ok, this is as far as I have been able to get in VS2005
Right Click on Dialog->Insert Dialog.
This creates a new dialog in my project. My question is, how do I get it to show up and close when a button is pressed?
Thanks,
Matt N
~guitarist809~
Add a handler function for the button. I believe you can do this by right clicking on the button and choose from the popup menu.
In the handler function, declare an instance of your dialog class. Call DoModal for the dialog.
Did you want the button to open and close the dialog? If you do you will have to make a modeless dialog. The above is for a modal dialog. A modal dialog will retain focus until it is closed. A modeless dialog allows you to switch back to the main app while the dialog is still open. For a modeless dialog you have to call Create and then ShowWindow. Also the modeless dialog can't be a local instance in the button handler function. It will have to be global or a member variable, if using MFC.
Thanks! It worked
Now, how can I change variables in the first dialog from the second dialog? (like control variables for changing the text of buttons/etc...)
~guitarist809~
You can pass a pointer to the variables to the second dialog. Change the values when the second dialog is open, then if you are calling DoModal() to open the second dialog you can do something like this :
Code:... inside button handler of first dialog. // open second dialog CSecondDialog dlg; dlg.m_pSomeVariable = &m_FirstDialogVariable; if( dlg.DoModal() == IDOK ) { // here you can use the updated value for m_FirstDialogVariable. }
Admittedly, this is kind of no-no and perhaps a hack, but you can use a flag inside the dialog like bModeless, and if true, then add a "DestroyWindow" or similar inside OnClose and delete this inside OnDestroy (call the base class first!).
Then you can allocate it via new and the modeless will take core of getting rid of its memory by itself when it closes.
It may be risky. I haven't tested it, so I can't say if it works.
But I would love to know if it DOES work.