What To Do With Second Dialog Box? - Programmer
This is a discussion on What To Do With Second Dialog Box? - Programmer ; I have an app that has a main dialog window, with a button that opens
a second dialog window in which the user selects cards. The user then
gets taken back to the main dialog window after card selection. But,
...
-
What To Do With Second Dialog Box?
I have an app that has a main dialog window, with a button that opens
a second dialog window in which the user selects cards. The user then
gets taken back to the main dialog window after card selection. But,
there will be several more times when the user is taken back to the
cards window to select more cards. The previously selected cards must
be dis-enabled so he doesn't choose the same card twice (that I know
how to do).
How should I handle the card window after cards are selected? Do I
minimize it? Hide it? I know I can't destroy it, as data needs to be
maintained for each visit to the cards window.
Any ideas?
Thanks,
Matt
-
Re: What To Do With Second Dialog Box?
matt wrote:
> I have an app that has a main dialog window, with a button that opens
> a second dialog window in which the user selects cards. The user then
> gets taken back to the main dialog window after card selection. But,
> there will be several more times when the user is taken back to the
> cards window to select more cards. The previously selected cards must
> be dis-enabled so he doesn't choose the same card twice (that I know
> how to do).
>
> How should I handle the card window after cards are selected? Do I
> minimize it? Hide it? I know I can't destroy it, as data needs to be
> maintained for each visit to the cards window.
>
> Any ideas?
>
> Thanks,
>
> Matt
The window and the CDialog object are separate entities. The standard
OnOK() dialog function destroys the window but preserves your CDialog's
member variables. Assuming that you make your CDialog object a member
variable in the parent window then you can reuse it, calling DoModal
again the next time the user selects it.
--
Scott McPhillips [VC++ MVP]
-
Re: What To Do With Second Dialog Box?
Scott,
I tried that, and after I hit the Ok button in the card window, it
closes, but the second time I open the card dialog window, the
disenabled buttons are enabled. Here's the relevant code:
class CCards1Dlg : public CDialog
{
// Construction
public:
CCards1Dlg(CWnd* pParent = NULL); // standard constructor
private:
CPickCards m_dPickCards;
};
void CCards1Dlg::OnPickcards()
{
//if no first round cards yet, instantiate the cards window and get
cards
if(m_dFirstPicked==0){
//instantiate second window
m_dPickCards.DoModal();
m_dFirstPicked=1;
}
else if(m_dSecondPicked==0)
m_dPickCards.DoModal();
}
Is that enough code for you to see where I'm going wrong?
Matt
"Scott McPhillips [MVP]" wrote in message news:...
> matt wrote:
> > I have an app that has a main dialog window, with a button that opens
> > a second dialog window in which the user selects cards. The user then
> > gets taken back to the main dialog window after card selection. But,
> > there will be several more times when the user is taken back to the
> > cards window to select more cards. The previously selected cards must
> > be dis-enabled so he doesn't choose the same card twice (that I know
> > how to do).
> >
> > How should I handle the card window after cards are selected? Do I
> > minimize it? Hide it? I know I can't destroy it, as data needs to be
> > maintained for each visit to the cards window.
> >
> > Any ideas?
> >
> > Thanks,
> >
> > Matt
>
> The window and the CDialog object are separate entities. The standard
> OnOK() dialog function destroys the window but preserves your CDialog's
> member variables. Assuming that you make your CDialog object a member
> variable in the parent window then you can reuse it, calling DoModal
> again the next time the user selects it.
-
Re: What To Do With Second Dialog Box?
matt wrote:
> Scott,
>
> I tried that, and after I hit the Ok button in the card window, it
> closes, but the second time I open the card dialog window, the
> disenabled buttons are enabled.
>
Yes, when the dialog is closed all of its controls are destroyed. The
only thing preserved is your data members, not the state of controls.
You could add code to the dialog initialization that sets control states
from data members.
Or, maybe what you're looking for is a way to preserve the controls and
their state. That can be done with a modeless dialog by hiding it
instead of destroying it. The only trick to this is to make the
modeless dialog act modal. Each time you make the dialog visible just
call EnableWindow(FALSE) on the parent window. When OK is clicked hide
the dialog and call EnableWindow(TRUE) on the parent window.
--
Scott McPhillips [VC++ MVP]
-
Re: What To Do With Second Dialog Box?
Scott,
Yes on the second part. That looks like the right strategy of not
destroying, but hiding the second dialog window.
How do you create a dialog window that's modeless? I created it in a
similar way in the Resource Editor, added the window as a variable in
the main application window class, then used:
m_dSecondWindow.ShowWindow(SW_SHOW);
I got an error. Can you tell what went wrong?
Thanks much,
Matt
"Scott McPhillips [MVP]" wrote in message news:...
> matt wrote:
> > Scott,
> >
> > I tried that, and after I hit the Ok button in the card window, it
> > closes, but the second time I open the card dialog window, the
> > disenabled buttons are enabled.
> >
>
> Yes, when the dialog is closed all of its controls are destroyed. The
> only thing preserved is your data members, not the state of controls.
> You could add code to the dialog initialization that sets control states
> from data members.
>
> Or, maybe what you're looking for is a way to preserve the controls and
> their state. That can be done with a modeless dialog by hiding it
> instead of destroying it. The only trick to this is to make the
> modeless dialog act modal. Each time you make the dialog visible just
> call EnableWindow(FALSE) on the parent window. When OK is clicked hide
> the dialog and call EnableWindow(TRUE) on the parent window.
-
Re: What To Do With Second Dialog Box?
matt wrote:
>>Or, maybe what you're looking for is a way to preserve the controls and
>>their state. That can be done with a modeless dialog by hiding it
>>instead of destroying it. The only trick to this is to make the
>>modeless dialog act modal. Each time you make the dialog visible just
>>call EnableWindow(FALSE) on the parent window. When OK is clicked hide
>>the dialog and call EnableWindow(TRUE) on the parent window.
> Scott,
>
> Yes on the second part. That looks like the right strategy of not
> destroying, but hiding the second dialog window.
>
> How do you create a dialog window that's modeless? I created it in a
> similar way in the Resource Editor, added the window as a variable in
> the main application window class, then used:
> m_dSecondWindow.ShowWindow(SW_SHOW);
>
> I got an error. Can you tell what went wrong?
>
> Thanks much,
>
> Matt
Elementary. You didn't call Create(). See the help page for CDialog.
It lists the steps for creating either a modal or modeless dialog.
--
Scott McPhillips [VC++ MVP]
-
Re: What To Do With Second Dialog Box?
Don't know if my last post will show, but I was getting an error. I
realized I have to use Create() to make the window before I can show
it. That worked. Onward I go.
Matt
"Scott McPhillips [MVP]" wrote in message news:...
> matt wrote:
> > Scott,
> >
> > I tried that, and after I hit the Ok button in the card window, it
> > closes, but the second time I open the card dialog window, the
> > disenabled buttons are enabled.
> >
>
> Yes, when the dialog is closed all of its controls are destroyed. The
> only thing preserved is your data members, not the state of controls.
> You could add code to the dialog initialization that sets control states
> from data members.
>
> Or, maybe what you're looking for is a way to preserve the controls and
> their state. That can be done with a modeless dialog by hiding it
> instead of destroying it. The only trick to this is to make the
> modeless dialog act modal. Each time you make the dialog visible just
> call EnableWindow(FALSE) on the parent window. When OK is clicked hide
> the dialog and call EnableWindow(TRUE) on the parent window.
-
Re: What To Do With Second Dialog Box?
Scott,
When I hit the Ok button in the cards window, how do I reference the
main window so I can enable it again within the OnOk function of the
cards window? I tried GetParent without success. What is the best
way to keep pointers to the 2 windows so they can be enabled and
hidden?
Thanks,
Jim
"Scott McPhillips [MVP]" wrote in message news:...
> matt wrote:
> > Scott,
> >
> > I tried that, and after I hit the Ok button in the card window, it
> > closes, but the second time I open the card dialog window, the
> > disenabled buttons are enabled.
> >
>
> Yes, when the dialog is closed all of its controls are destroyed. The
> only thing preserved is your data members, not the state of controls.
> You could add code to the dialog initialization that sets control states
> from data members.
>
> Or, maybe what you're looking for is a way to preserve the controls and
> their state. That can be done with a modeless dialog by hiding it
> instead of destroying it. The only trick to this is to make the
> modeless dialog act modal. Each time you make the dialog visible just
> call EnableWindow(FALSE) on the parent window. When OK is clicked hide
> the dialog and call EnableWindow(TRUE) on the parent window.
-
Re: What To Do With Second Dialog Box?
matt wrote:
> Scott,
>
> When I hit the Ok button in the cards window, how do I reference the
> main window so I can enable it again within the OnOk function of the
> cards window? I tried GetParent without success. What is the best
> way to keep pointers to the 2 windows so they can be enabled and
> hidden?
>
> Thanks,
>
> Jim
You can access your application's main window from anywhere by calling
AfxGetMainWnd(). It is a global MFC function.
CDialog::Create accepts an optional pParentWnd parameter. If you
passed 'this' for pParentWnd then GetParent() should work.
--
Scott McPhillips [VC++ MVP]
-
Re: What To Do With Second Dialog Box?
Your suggestioned worked. The only thing I added was the functiion to
move the first dialog window to the front when the second dialog box
was hidden. It seems when there are other windows from other apps
open, my first dialog box isn't up front.
Thanks muchly!
M
"Scott McPhillips [MVP]" wrote in message news:...
> matt wrote:
> > Scott,
> >
> > When I hit the Ok button in the cards window, how do I reference the
> > main window so I can enable it again within the OnOk function of the
> > cards window? I tried GetParent without success. What is the best
> > way to keep pointers to the 2 windows so they can be enabled and
> > hidden?
> >
> > Thanks,
> >
> > Jim
>
> You can access your application's main window from anywhere by calling
> AfxGetMainWnd(). It is a global MFC function.
>
> CDialog::Create accepts an optional pParentWnd parameter. If you
> passed 'this' for pParentWnd then GetParent() should work.
-
Re: What To Do With Second Dialog Box?
1 last problem:
The second dialog window is used to get card choices by the user.
Those choices are input for a computational function whose results
will be displayed in the main window. So, either I need a way to
signal my main window when the second window is hidden so I can
trigger this function in the main window class, or I need to put the
function in the second window's class and somehow access a parameter
of the main window class (Origin, which is a point in the main
window). Can anyone let me know how this can be done?
Thanks,
Matt
-
Re: What To Do With Second Dialog Box?
Someone answered it elsewhere. No need to reply.