CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2005
    Location
    BANGALORE ,INDIA
    Posts
    19

    Question two dialogs to same class

    Hi all,
    Can we add two dialogs to the same class?
    Consider two dialogs A and B of class clz.
    now if i make a call as
    clz obj;
    obj.DoModal();
    here which dialog is invoked.


    Thank u.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: two dialogs to same class

    This is somehow a strange feature. Maybe if you explain what you want to achieve, we can give you some advice.

  3. #3
    Join Date
    Dec 2005
    Location
    BANGALORE ,INDIA
    Posts
    19

    Re: two dialogs to same class

    I want to invoke dialog A or B depending upon my requirements.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,185

    Re: two dialogs to same class

    But, they behave different?

    If so, make 2 classes. Then, in the class which implements your special requirements, you invoke the right dialog:

    Code:
    if (bShowDialogA)
    {
        CMyADlg dlgA;
        dlgA.DoModal();
    }
    else
    {
        CMyBDlg dlgB;
        dlgB.DoModal();
    }

  5. #5
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: two dialogs to same class

    A dialog Creation depends on the ID of the Dialog .and it's upto you which id you are going to provide to your dialog .and on the basis of IDD u can make a call to your apropriate dialog .

    Thankyou
    Last edited by humptydumpty; April 19th, 2006 at 06:20 AM.

  6. #6
    Join Date
    Apr 2006
    Posts
    46

    Talking Re: two dialogs to same class

    Quote Originally Posted by harshandu
    Hi all,
    Can we add two dialogs to the same class?
    Consider two dialogs A and B of class clz.
    now if i make a call as
    clz obj;
    obj.DoModal();
    here which dialog is invoked.


    Thank u.
    Of course we can "add" two dialogs to the same class.
    We should make it clear that a "dialog" is a kind of resource.
    And it's identified by its ID (always IDD_ heading).

    We Create a dialog class inherits from CDialog,it doesn't mean that we
    must attach a dialog ID to it.
    for example:

    class CMyDlg: public CDialog
    {
    CMyDlg(CWnd* pParentWnd = NULL); //Standard construction
    CMyDlg(UINT nIDTemplate, CWnd* pParentWnd = NULL); //Not standard

    virtual ~CMyDlg();
    ...
    }

    We can use this dialog class in this way:

    CMyDlg *pMyDlg1;
    CMyDlg *pMydlg2;

    ok,now,if you want any of the two dialog to be a Mode dialog:

    pMyDlg1 = new CMyDlg(IDD_DIALOG_ONE,pParentWnd);
    pMyDlg2 = new CMyDlg(IDD_DIALOG_TWO,pParentWnd);
    //Note: pParentWnd can be NULL

    pMyDlg1->DoModal(); //Create and activate it!
    pMyDlg2->DoModal();

    If you want them to be Modeless,do in this way:

    pMyDlg1 = new CMyDlg(pParentWnd);
    pMyDlg2 = new CMyDlg(pParentWnd);
    //Note: pParentWnd also can be NULL

    pMyDlg1->Create(IDD_DIALOG_ONE,pParentWnd);
    pMyDlg2->Create(IDD_DIALOG_TWO,pParentWnd);

    pMyDlg1->ShowWindow(SW_SHOW);
    pMyDlg2->ShowWindow(SW_SHOW);

    In this way, many dialogs can share one class,isn't it great?

    Wisby
    4\19\2006

  7. #7
    Join Date
    Apr 2006
    Posts
    46

    Talking Re: two dialogs to same class

    PS:the not standard construction is like this:

    CMyDlg::CMyDlg(UINT nIDTemplate, CWnd* pParentWnd)
    : CDialog(nIDTemplate, pParentWnd)
    {
    //{{AFX_DATA_INIT(CMyDlg)
    // member initials here
    //}}AFX_DATA_INIT
    }


    Over....haha

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