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.
Printable View
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.
This is somehow a strange feature. Maybe if you explain what you want to achieve, we can give you some advice.
I want to invoke dialog A or B depending upon my requirements.
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();
}
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
Of course we can "add" two dialogs to the same class.Quote:
Originally Posted by harshandu
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
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