CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Feb 2009
    Posts
    24

    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

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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().
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    Re: Hide ahd Show Dialog

    Perhaps this is the one you are looking for.

    http://www.codeproject.com/KB/dialog...gmodeless.aspx
    Rate the posts which you find useful

  4. #4
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    Re: Hide ahd Show Dialog

    Quote Originally Posted by cilu View Post
    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

  5. #5
    Join Date
    Feb 2009
    Posts
    24

    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....................

  6. #6
    Join Date
    Jan 2008
    Posts
    6

    Smile 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.

  7. #7
    Join Date
    Feb 2009
    Posts
    24

    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........

  8. #8
    Join Date
    Aug 2008
    Posts
    112

    Re: Hide ahd Show Dialog

    Rightmousclick on dialog
    choose add variable then fill it in
    hi,,,

  9. #9
    Join Date
    Jan 2008
    Posts
    6

    Re: Hide ahd Show Dialog

    Quote Originally Posted by priyasubramani View Post
    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.

  10. #10
    Join Date
    Nov 2007
    Posts
    74

    Re: Hide ahd Show Dialog

    I am confused about your 2 dialog variables

  11. #11
    Join Date
    Feb 2009
    Posts
    24

    Re: Hide ahd Show Dialog

    Quote Originally Posted by rahulvaishnav View Post
    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.

  12. #12
    Join Date
    Jan 2008
    Posts
    6

    Re: Hide ahd Show Dialog

    Quote Originally Posted by priyasubramani View Post
    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.

  13. #13
    Join Date
    Feb 2009
    Posts
    24

    Re: Hide ahd Show Dialog

    Quote Originally Posted by rahulvaishnav View Post
    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.

  14. #14
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Hide ahd Show Dialog

    Quote Originally Posted by priyasubramani View Post
    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.

  15. #15
    Join Date
    Jan 2008
    Posts
    6

    Re: Hide ahd Show Dialog

    Quote Originally Posted by priyasubramani View Post
    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured