general mfc question: lpszTemplateName
-
When creating a dialog you have the option of two constructors CDialog( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL ); CDialog( UINT nIDTemplate, CWnd* pParentWnd = NULL ); All the examples I have ever seen use the latter (UINT nIDTemplate). Just for my own edification could someone tell me how to use the first constructor. I've never seen an example of this. Where do you find the TemplateName? These must be templates created in your code? The first constructor parameter LPCTSTR lpszTemplateName appears in quite a few constructors, for example: CFormView( LPCTSTR lpszTemplateName ); CDialogBar::Create BOOL Create( CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID ); CDialog::Create BOOL Create( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL ); CPropertyPage( LPCTSTR lpszTemplateName, UINT nIDCaption = 0 ); COleDBRecordView( LPCTSTR lpszTemplateName ); CRecordView( LPCSTR lpszTemplateName );
-
When creating a dialog you have the option of two constructors CDialog( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL ); CDialog( UINT nIDTemplate, CWnd* pParentWnd = NULL ); All the examples I have ever seen use the latter (UINT nIDTemplate). Just for my own edification could someone tell me how to use the first constructor. I've never seen an example of this. Where do you find the TemplateName? These must be templates created in your code? The first constructor parameter LPCTSTR lpszTemplateName appears in quite a few constructors, for example: CFormView( LPCTSTR lpszTemplateName ); CDialogBar::Create BOOL Create( CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID ); CDialog::Create BOOL Create( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL ); CPropertyPage( LPCTSTR lpszTemplateName, UINT nIDCaption = 0 ); COleDBRecordView( LPCTSTR lpszTemplateName ); CRecordView( LPCSTR lpszTemplateName );
mx483 wrote: Just for my own edification could someone tell me how to use the first constructor. I've never seen an example of this. Where do you find the TemplateName? These must be templates created in your code? In your dialog's constructor, change the first parameter being sent to
CDialog
's constructor fromIDD
toMAKEINTRESOURCE(IDD_DIALOG_TEMPLATE)
instead. * Note thatIDD_DIALOG_TEMPLATE
is whatever name you have in the dialog's class declaration.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
mx483 wrote: Just for my own edification could someone tell me how to use the first constructor. I've never seen an example of this. Where do you find the TemplateName? These must be templates created in your code? In your dialog's constructor, change the first parameter being sent to
CDialog
's constructor fromIDD
toMAKEINTRESOURCE(IDD_DIALOG_TEMPLATE)
instead. * Note thatIDD_DIALOG_TEMPLATE
is whatever name you have in the dialog's class declaration.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Hey thanks David, I have seen the MAKEINTRESOURCE macro before. It seems kind of redundant doesn't it. Why bother converting to an INT when you could just use the other constructor. Could you give an example of the IDD_DIALOG_TEMPLATE name? You said it is whatever name you have in the dialog's class declaration. I'm still scratching my head. Please provide a snippet. Thanks again for the response. Jay
-
Hey thanks David, I have seen the MAKEINTRESOURCE macro before. It seems kind of redundant doesn't it. Why bother converting to an INT when you could just use the other constructor. Could you give an example of the IDD_DIALOG_TEMPLATE name? You said it is whatever name you have in the dialog's class declaration. I'm still scratching my head. Please provide a snippet. Thanks again for the response. Jay
mx483 wrote: Why bother converting to an INT That macro converts to a string not an int. mx483 wrote: Could you give an example of the IDD_DIALOG_TEMPLATE name? You said it is whatever name you have in the dialog's class declaration. Just look in your dialog's .h file for the value assigned to
IDD
. mx483 wrote: Please provide a snippet. Did you modify the dialog's constructor like I described?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
mx483 wrote: Why bother converting to an INT That macro converts to a string not an int. mx483 wrote: Could you give an example of the IDD_DIALOG_TEMPLATE name? You said it is whatever name you have in the dialog's class declaration. Just look in your dialog's .h file for the value assigned to
IDD
. mx483 wrote: Please provide a snippet. Did you modify the dialog's constructor like I described?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Thanks David, Be patient, this is coming to me. I did mispeak on MAKEINTRESOURCE macro. It does indeed return a string. Here is my call as it was pDlg->Create(IDD_DIALOG1, this); Here was my constructor CDialogView::CDialogView(CWnd* pParent /*=NULL*/) : CDialog(CDialogView::IDD, pParent) { //{{AFX_DATA_INIT(CDialogView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } From CFileDialog.h file // Dialog Data //{{AFX_DATA(CDialogView) enum { IDD = IDD_DIALOG1 }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA Are you saying I need to modify the constructor of my dialog? Here is what I did for the new constructor CDialogView::CDialogView(CWnd* pParent /*=NULL*/) : CDialog(MAKEINTRESOURCE(CDialogView::IDD), pParent) { //{{AFX_DATA_INIT(CDialogView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT }} Now for the call pDlg->Create("IDD_DIALOG1", this); I still get an assert. I'm not sure if this is what you meant. Thanks, Jay
-
Thanks David, Be patient, this is coming to me. I did mispeak on MAKEINTRESOURCE macro. It does indeed return a string. Here is my call as it was pDlg->Create(IDD_DIALOG1, this); Here was my constructor CDialogView::CDialogView(CWnd* pParent /*=NULL*/) : CDialog(CDialogView::IDD, pParent) { //{{AFX_DATA_INIT(CDialogView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } From CFileDialog.h file // Dialog Data //{{AFX_DATA(CDialogView) enum { IDD = IDD_DIALOG1 }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA Are you saying I need to modify the constructor of my dialog? Here is what I did for the new constructor CDialogView::CDialogView(CWnd* pParent /*=NULL*/) : CDialog(MAKEINTRESOURCE(CDialogView::IDD), pParent) { //{{AFX_DATA_INIT(CDialogView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT }} Now for the call pDlg->Create("IDD_DIALOG1", this); I still get an assert. I'm not sure if this is what you meant. Thanks, Jay
mx483 wrote: : CDialog(MAKEINTRESOURCE(CDialogView::IDD), pParent) Should be:
: CDialog(MAKEINTRESOURCE(IDD_DIALOG1), pParent)
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
mx483 wrote: : CDialog(MAKEINTRESOURCE(CDialogView::IDD), pParent) Should be:
: CDialog(MAKEINTRESOURCE(IDD_DIALOG1), pParent)
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Thanks David, I think I'm making it more difficult and I think you've answered my question CDialog one("IDD_DIALOG1", this); CDialog two(IDD_DIALOG1, this); Both of these work. So the answer is the template resource name is just the string representation of the ID. If I derive a class from CDialog, I have to make sure that my constructor in the derived class would accomodate the string using the MAKEINTRESOURCE macro. How did I do? Thanks again. I learned something.
-
Thanks David, I think I'm making it more difficult and I think you've answered my question CDialog one("IDD_DIALOG1", this); CDialog two(IDD_DIALOG1, this); Both of these work. So the answer is the template resource name is just the string representation of the ID. If I derive a class from CDialog, I have to make sure that my constructor in the derived class would accomodate the string using the MAKEINTRESOURCE macro. How did I do? Thanks again. I learned something.
mx483 wrote: If I derive a class from CDialog, I have to make sure that my constructor in the derived class would accomodate the string using the MAKEINTRESOURCE macro. How did I do? What is it that you are wanting to do that a
CDialog
-derived class does not already do? I must say that in 12+ years of using MFC, I've never usedCDialog
's constructor that takes a string. Maybe you have an example that shows its usefullness.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
mx483 wrote: If I derive a class from CDialog, I have to make sure that my constructor in the derived class would accomodate the string using the MAKEINTRESOURCE macro. How did I do? What is it that you are wanting to do that a
CDialog
-derived class does not already do? I must say that in 12+ years of using MFC, I've never usedCDialog
's constructor that takes a string. Maybe you have an example that shows its usefullness.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
When creating a dialog you have the option of two constructors CDialog( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL ); CDialog( UINT nIDTemplate, CWnd* pParentWnd = NULL ); All the examples I have ever seen use the latter (UINT nIDTemplate). Just for my own edification could someone tell me how to use the first constructor. I've never seen an example of this. Where do you find the TemplateName? These must be templates created in your code? The first constructor parameter LPCTSTR lpszTemplateName appears in quite a few constructors, for example: CFormView( LPCTSTR lpszTemplateName ); CDialogBar::Create BOOL Create( CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID ); CDialog::Create BOOL Create( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL ); CPropertyPage( LPCTSTR lpszTemplateName, UINT nIDCaption = 0 ); COleDBRecordView( LPCTSTR lpszTemplateName ); CRecordView( LPCSTR lpszTemplateName );
Compiled resources may be identified numerically (this is the usual case) or with a string. For example, you could have the following in your .RC file:
IDD_DLG1 DIALOG 0, 0, 210, 150
...
"DIALOG2" DIALOG 0, 0, 200, 200
...In the first case, you have a
#define
in yourresource.h
file for the valueIDD_DLG1
. In the second case, you would use thelpszTemplateName
form of the constructor, passing the string"DIALOG2"
. TheMAKEINTRESOURCE
macro converts an integer resource identifier to a form that the resource loading logic recognizes, returning it as a string type.
Software Zen:
delete this;
-
Compiled resources may be identified numerically (this is the usual case) or with a string. For example, you could have the following in your .RC file:
IDD_DLG1 DIALOG 0, 0, 210, 150
...
"DIALOG2" DIALOG 0, 0, 200, 200
...In the first case, you have a
#define
in yourresource.h
file for the valueIDD_DLG1
. In the second case, you would use thelpszTemplateName
form of the constructor, passing the string"DIALOG2"
. TheMAKEINTRESOURCE
macro converts an integer resource identifier to a form that the resource loading logic recognizes, returning it as a string type.
Software Zen:
delete this;