Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. general mfc question: lpszTemplateName

general mfc question: lpszTemplateName

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionc++wpflounge
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    23_444
    wrote on last edited by
    #1

    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 );

    D G 2 Replies Last reply
    0
    • 2 23_444

      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 );

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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 from IDD to MAKEINTRESOURCE(IDD_DIALOG_TEMPLATE) instead. * Note that IDD_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

      2 1 Reply Last reply
      0
      • D David Crow

        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 from IDD to MAKEINTRESOURCE(IDD_DIALOG_TEMPLATE) instead. * Note that IDD_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

        2 Offline
        2 Offline
        23_444
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • 2 23_444

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          2 1 Reply Last reply
          0
          • D David Crow

            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

            2 Offline
            2 Offline
            23_444
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • 2 23_444

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              2 1 Reply Last reply
              0
              • D David Crow

                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

                2 Offline
                2 Offline
                23_444
                wrote on last edited by
                #7

                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.

                D 1 Reply Last reply
                0
                • 2 23_444

                  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.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  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 used CDialog'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

                  2 1 Reply Last reply
                  0
                  • D David Crow

                    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 used CDialog'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

                    2 Offline
                    2 Offline
                    23_444
                    wrote on last edited by
                    #9

                    Nope, I haven't seen one either. Just took the opportunity to learn something new. Thanks again. Jay

                    1 Reply Last reply
                    0
                    • 2 23_444

                      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 );

                      G Offline
                      G Offline
                      Gary R Wheeler
                      wrote on last edited by
                      #10

                      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 your resource.h file for the value IDD_DLG1. In the second case, you would use the lpszTemplateName form of the constructor, passing the string "DIALOG2". The MAKEINTRESOURCE 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;

                      2 1 Reply Last reply
                      0
                      • G Gary R Wheeler

                        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 your resource.h file for the value IDD_DLG1. In the second case, you would use the lpszTemplateName form of the constructor, passing the string "DIALOG2". The MAKEINTRESOURCE 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;

                        2 Offline
                        2 Offline
                        23_444
                        wrote on last edited by
                        #11

                        Perfect! Thanks a bunch. It was a conceptual question. I have no reason to use a string but thought I should at least understand the concept. Thank you.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups