|
-
February 3rd, 2009, 12:26 AM
#1
Hide ahd Show Dialog
Hi All,
I have two dialogs(IDD_DIALOG,IDD_DIALOG2).IDD_DIALOG is main dialog. I have create the second one in button click event of first dialog.
code is:
void CFirstDlg::OnBnClickedButton1()
{
this->ShowWindow(SW_HIDE);
SecondDlg *dlg=new SecondDlg (); //second dialog class
dlg->DoModal();
}
If i click the second dialog button. I need to hide the curron dialog(ie. IDD_DIALOG2) and show the first dialog with datas.
Please help me............
Regards,
Priya
-
February 3rd, 2009, 02:26 AM
#2
Re: Hide ahd Show Dialog
You created a modal dialog. You can only hide it when you close it. All mouse and keyboard input goes to it, not to its parent.
If you have to show and hide dialogs, you need to use modeless dialogs. Use Create() and ShowWindow().
-
February 3rd, 2009, 02:32 AM
#3
Re: Hide ahd Show Dialog
Rate the posts which you find useful
-
February 3rd, 2009, 02:35 AM
#4
Re: Hide ahd Show Dialog
 Originally Posted by cilu
You created a modal dialog. You can only hide it when you close it. All mouse and keyboard input goes to it, not to its parent.
If you have to show and hide dialogs, you need to use modeless dialogs. Use Create() and ShowWindow().
Something like this
Code:
void CDialog1::OnButton1()
{
CDialog2 *dia2 = new CDialog2();
dia2->Create(IDD_DIALOG2);
dia2->ShowWindow(SW_SHOW);
}
Rate the posts which you find useful
-
February 3rd, 2009, 03:19 AM
#5
Re: Hide ahd Show Dialog
HI,
I have list box,grid,etc.. and it has some datas in my first dialog.I have create the 2nd dialog in button click event.
code:
void CDialog1::OnButton1()
{
this->ShowWindow(SW_HIDE);
CDialog2 *dia2 = new CDialog2();
dia2->Create(IDD_DIALOG2);
dia2->ShowWindow(SW_SHOW);
}
In second dialog button click event, i need to show the first dialog with that datas.
How to do this?
Please help me....................
-
February 3rd, 2009, 04:05 AM
#6
Re: Hide ahd Show Dialog
Hi priya,
there are many ways for doing this.
one way is like below..
void CDialog1::OnButton1()
{
this->ShowWindow(SW_HIDE);
if(!m_dlg2)
m_dlg2.Create(IDD_DIALOG2,0);
m_dlg2.ShowWindow(SW_SHOW);
}
//m_dlg2 is an object of CDialog2 and member variable of CDialog1
void CDialog2::OnButton1()
{
this->ShowWindow(SW_HIDE);
HWND hwnd = ::FindWindow(NULL,L"Title of CDialog1");
::ShowWindow(hwnd,SW_SHOW);
}
i think it should work although Dialog1 is Model & Dialog2 is Modeless
Last edited by rahulvaishnav; February 3rd, 2009 at 04:32 AM.
-
February 3rd, 2009, 04:58 AM
#7
Re: Hide ahd Show Dialog
Hi iam very new to MFC. I know to create member variable for button and controls. But i dont know how to create member variable for CDialog.
Please help me........
-
February 3rd, 2009, 05:01 AM
#8
Re: Hide ahd Show Dialog
Rightmousclick on dialog
choose add variable then fill it in
hi,,,
-
February 3rd, 2009, 05:18 AM
#9
Re: Hide ahd Show Dialog
 Originally Posted by priyasubramani
Hi iam very new to MFC. I know to create member variable for button and controls. But i dont know how to create member variable for CDialog.
Please help me........
You have Dialog1.h & Dialog2.h right?
So Add below codein Dialog1.h
public:
CDialog2 m_dlg2;
now here you have created object of CDialog2. m_dlg2 is member variable of CDialog1 class.
now use the code which i have written in my last post.
-
February 3rd, 2009, 05:23 AM
#10
Re: Hide ahd Show Dialog
I am confused about your 2 dialog variables
-
February 3rd, 2009, 06:20 AM
#11
Re: Hide ahd Show Dialog
 Originally Posted by rahulvaishnav
Hi priya,
there are many ways for doing this.
void CDialog2::OnButton1()
{
this->ShowWindow(SW_HIDE);
HWND hwnd = ::FindWindow(NULL,L"Title of CDialog1");
::ShowWindow(hwnd,SW_SHOW);
}
My first dialog(IDD_DIALOG) class name is CDialog1.How to give it into FindWindow(). Bcoz in my application all dialogs has same name.
-
February 3rd, 2009, 07:11 AM
#12
Re: Hide ahd Show Dialog
 Originally Posted by priyasubramani
My first dialog(IDD_DIALOG) class name is CDialog1.How to give it into FindWindow(). Bcoz in my application all dialogs has same name.
Ok then use CDialog1 pointer in CDialog2 and then you can directly access its
ShowWindow(SW_SHOW) Method.
-
February 3rd, 2009, 07:56 AM
#13
Re: Hide ahd Show Dialog
 Originally Posted by rahulvaishnav
Ok then use CDialog1 pointer in CDialog2 and then you can directly access its
ShowWindow(SW_SHOW) Method.
i have given like this.
this->ShowWindow(SW_HIDE);
CDialog1 *dlg=new CDialog1();
dlg->ShowWindow(SW_SHOW);
But it showing dubug assertion error.
-
February 3rd, 2009, 08:10 AM
#14
Re: Hide ahd Show Dialog
 Originally Posted by priyasubramani
i have given like this.
this->ShowWindow(SW_HIDE);
CDialog1 *dlg=new CDialog1();
dlg->ShowWindow(SW_SHOW);
But it showing dubug assertion error.
You didn't call Create, so the Windows part of it doesn't exist yet.
Is there any reason you're using new to create your dialog, instead of just allocating it locally? You have a memory leak as you're not deleting it when you're done.
-
February 3rd, 2009, 08:44 AM
#15
Re: Hide ahd Show Dialog
 Originally Posted by priyasubramani
i have given like this.
this->ShowWindow(SW_HIDE);
CDialog1 *dlg=new CDialog1();
dlg->ShowWindow(SW_SHOW);
But it showing dubug assertion error.
above code is wrong..
Do one thing,
Although It is not good practice but for your work tobe done,
follow below steps..
1. Take a global variable
CDialog1 *g_dlg; in Dialog1.cpp.
2. in CDialog1 Constructor wrote below line
g_dlg = this;
3. Make it extern CDialog1 *g_dlg; in Dialog2.cpp.
and use below code for Button click in Dialog2.cpp
void CDialog2::OnButton1()
{
this->ShowWindow(SW_HIDE);
g_dlg->ShowWindow(SW_SHOW);
}
This will work for you.
Sorry to say, Priya you have to learn MFC more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|