Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have to make a GUI in VS6.0 in MFC.
I want to implement the following behaviour:
When I press button another dialog window should be open.
Also how can we hide/close first window when second is open by clicking on button?

Please reply.. if possible then with demo..
my id: [e-mail address removed]
:)
Posted
Updated 27-Jan-10 2:14am
v3

This line in your child dialog class member function "OnInitDialog" will hide the parent dialog.

<br />
GetOwner()->ShowWindow( FALSE );<br />


if you want to bring the parent dialog back in case of closing the child dialog, so you have to add closing message handler in your child window class, and add that function this line:

<br />
GetOwner()->ShowWindow( TRUE );<br />
 
Share this answer
 
v2
I would concur with CPAllini's response with an adjustment.

CPallini wrote:
Assuming your dialog has a parent window, then, on button click, you should:

1. Notify to the parent window that the other dialog should be open (you may set a flag, for instance).
2. Close the current dialog.



I would not, however, set a flag to notify the parent window. Instead I would either:

1) Send the parent a Window's message. This requires you to use a custom windows message and implement a handler for it in the parent.

or

2) Call a method of the parent dialog's object. This requires that the child dialog was previously provided with a properly typed reference or pointer to the parent dialog.

I would prefer option 1 as it does not seem to require as quite as much coupling between the classes.


If you do opt for Jast_in's answer, make sure you do pay attention to exactly when & how you will see that the hidden window gets redisplayed or closed.
 
Share this answer
 
Maybe I didn't understand what you need to implement exactly.
If "show/hide" is about your parent application then my first post will work. If "show/hide" connected only to dialogs open due to button pressing then you have to keep open dialog to make the dialog hide.
Then ShowWindow(BOOL) will work surely.
 
Share this answer
 
Assuming your dialog has a parent window, then, on button click, you should:
  1. Notify to the parent window that the other dialog should be open (you may set a flag, for instance).
  2. Close the current dialog.

The parent window will eventually open the other dialog.
:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900