Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show CDialog with identifier

Status
Not open for further replies.

Casiopea

Programmer
Jan 15, 2003
47
ES
Hi! My question is that I would like to open a CDialog using the ID associated to the window it shows; I mean, I've got several forms, each one belongs to a CDialog class, and I see for instance that one of then has the IDD_DATETOWN_DIALOG=105 and depending on the information I've got I decide to show it, then I was thinking about using
CDialog * dlg=(CDialog *) GetDlgItem(IDD_DATETOWN_DIALOG)
dlg->DoModal()
as I do if I declare an object of the class DateTown and show it with DoModal(); but doing it through the identifier it gives me a severe error and break the program
THANK YOU,
 
The DoModal() function creates the dialog box.
The GetDlgItem() function assumes the dialog exists!
There are many ways to create a dialog box and here is one:
CMyDialog dlg = new CMyDialog();
dlg.DoModal();

Now you can query a pointer to this control by :

CMyDialog * p=(CMyDialog *) GetDlgItem(IDD_DATETOWN_DIALOG);
if (p)
{
p->LoadDateTown();
}
-obislavu-
 
The point is that I have many classes derived from CDialog (one for each form) and what I would like is to load the form through the identifier which is defined inside the class:
class DATETOWN{
..
enum IDD=IDD_DATETOWN
..
}
In the normal order of my application I call it through:
CDatetown m_date();
m_date.DoModal();
//Another form
CShop m_shop();
m_shop.DoModal();
But there's another order, and I would like to avoid writting a function to switch through the identifiers and load the appropriate Form, I mean
switch(id){
case 105:
CDatetown m_date();
m_date.DoModal();
case 106:
CShop m_shop();
m_shop.DoModal();
... and so on for all the rest of forms
it is much easier if I take the identifier from a database I have constructed in which I keep the last form filled and load the form some way, if exists. Any tip? Thank you


 
CMapStringToPtr map;
map.SetAt("town", new CTownDlg);
map.SetAt("shop",new CShopDlg);
....
//
Now retrieve the name of the last form from your database:
CString lastForm = "shop";
ShowDialog(lastForm); will creates the the corresponding dialog.


void ShowDialog(const CString &rKey)
{
CDialog *pDlg = NULL;
if( map.Lookup( rKey, (CObject *&)pDlg ) )
pDlg->DoModal();

}


To find out the class of the displayed dialog use RUNTIME_CLASS macro like here:

if(pDlg->IsKindOf( RUNTIME_CLASS( CTownDlg ) ) )
{
// This dialog is a CTownDialog
CTownDlg *p1 = (CTownDlg *)pDlg;
// ...
}

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top