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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to change the Title(Caption) of Modal Dialog Box?

How to change the Title(Caption) of Modal Dialog Box?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionlearning
21 Posts 7 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.
  • M mikert_2008

    Hi, I have the dialog box. Which I am using as Modal dialog box with DoModal functionality. I need to change the Title(Caption) of dialog box before calling the domodal(). Since I am deciding the title of dialog box at run time I can't use the resource setting. One way I know to change the title of Modal Dialog Box is to use OnInitDialog() function of the class derived from the DialgBox and then call setwindowtext() function inside it. But I want to change the title/cation without using OnInitDialog as the project I am working doesn't have class derived from it. And doesn't look proper to genrate the class just for this purpose. Can anybody knows the other way of doing it?? Thanks in advance.. Mike.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #3

    I assume from your comments that this is a Win32 dialog rather than MFC. If that is the case you can still trap the WM_INITDIALOG[^] message and change the title there.

    It's time for a new signature.

    CPalliniC M D 3 Replies Last reply
    0
    • M mikert_2008

      Hi, I have the dialog box. Which I am using as Modal dialog box with DoModal functionality. I need to change the Title(Caption) of dialog box before calling the domodal(). Since I am deciding the title of dialog box at run time I can't use the resource setting. One way I know to change the title of Modal Dialog Box is to use OnInitDialog() function of the class derived from the DialgBox and then call setwindowtext() function inside it. But I want to change the title/cation without using OnInitDialog as the project I am working doesn't have class derived from it. And doesn't look proper to genrate the class just for this purpose. Can anybody knows the other way of doing it?? Thanks in advance.. Mike.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #4

      I think that you may do it, using the CDialog::InitModalIndirect route (see [^]), but it would be "full of pain", because you have to create and fill properly the DLGTEMPLATE struct ([^] read carefully the "Remarks" section). :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      M 1 Reply Last reply
      0
      • L Lost User

        I assume from your comments that this is a Win32 dialog rather than MFC. If that is the case you can still trap the WM_INITDIALOG[^] message and change the title there.

        It's time for a new signature.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #5

        Nah, inheritance is not an option in Win32. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • K KarstenK

          define a public string member in your dialog class which get set between ctor and oninit and will do setwindowtext()in your OnInitDialog()

          Press F1 for help or google it. Greetings from Germany

          M Offline
          M Offline
          mikert_2008
          wrote on last edited by
          #6

          Hi, As I mentioned I am not having any Dialog class where I can use the OnInitDialog() function. I want to do it without using it. What I am trying for is the without using separate dialog class for it. Thanks Mike

          K 1 Reply Last reply
          0
          • L Lost User

            I assume from your comments that this is a Win32 dialog rather than MFC. If that is the case you can still trap the WM_INITDIALOG[^] message and change the title there.

            It's time for a new signature.

            M Offline
            M Offline
            mikert_2008
            wrote on last edited by
            #7

            Hi, I am aware of the InItDialog functionality. But I am not having Dialog derived for it. I am trying to avoid the creation of seperate class for this purpose. Is it possible to change the dialog header without using InItDialog?? Thanks:- Mike

            1 Reply Last reply
            0
            • CPalliniC CPallini

              I think that you may do it, using the CDialog::InitModalIndirect route (see [^]), but it would be "full of pain", because you have to create and fill properly the DLGTEMPLATE struct ([^] read carefully the "Remarks" section). :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              M Offline
              M Offline
              mikert_2008
              wrote on last edited by
              #8

              Hi, It's for creating Modal dialog box indirectly. But I already have the dialog box. Thanks:- Mike

              CPalliniC 1 Reply Last reply
              0
              • M mikert_2008

                Hi, It's for creating Modal dialog box indirectly. But I already have the dialog box. Thanks:- Mike

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #9

                That's the only way, IMO. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                In testa che avete, signor di Ceprano?

                1 Reply Last reply
                0
                • L Lost User

                  I assume from your comments that this is a Win32 dialog rather than MFC. If that is the case you can still trap the WM_INITDIALOG[^] message and change the title there.

                  It's time for a new signature.

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

                  Richard MacCutchan wrote:

                  I assume from your comments that this is a Win32 dialog rather than MFC.

                  Even though he mentions DoModal()?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "Man who follows car will be exhausted." - Confucius

                  L 1 Reply Last reply
                  0
                  • M mikert_2008

                    Hi, I have the dialog box. Which I am using as Modal dialog box with DoModal functionality. I need to change the Title(Caption) of dialog box before calling the domodal(). Since I am deciding the title of dialog box at run time I can't use the resource setting. One way I know to change the title of Modal Dialog Box is to use OnInitDialog() function of the class derived from the DialgBox and then call setwindowtext() function inside it. But I want to change the title/cation without using OnInitDialog as the project I am working doesn't have class derived from it. And doesn't look proper to genrate the class just for this purpose. Can anybody knows the other way of doing it?? Thanks in advance.. Mike.

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

                    mikert_2008 wrote:

                    ...the project I am working doesn't have class derived from it.

                    So what object are you calling DoModal() from?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "Man who follows car will be exhausted." - Confucius

                    M 1 Reply Last reply
                    0
                    • D David Crow

                      mikert_2008 wrote:

                      ...the project I am working doesn't have class derived from it.

                      So what object are you calling DoModal() from?

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      "Man who follows car will be exhausted." - Confucius

                      M Offline
                      M Offline
                      mikert_2008
                      wrote on last edited by
                      #12

                      CDialog dlgAbout(IDD_ABOUTBOX); dlgAbout.DoModal();

                      C 1 Reply Last reply
                      0
                      • D David Crow

                        Richard MacCutchan wrote:

                        I assume from your comments that this is a Win32 dialog rather than MFC.

                        Even though he mentions DoModal()?

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "Man who follows car will be exhausted." - Confucius

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        OK, guys I misread it, I shall perform a suitable act of self-humiliation in penance! :((

                        It's time for a new signature.

                        D 1 Reply Last reply
                        0
                        • L Lost User

                          OK, guys I misread it, I shall perform a suitable act of self-humiliation in penance! :((

                          It's time for a new signature.

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

                          Richard MacCutchan wrote:

                          ...I shall perform a suitable act of self-humiliation in penance!

                          No, I do not wish to see you dancing on a table wearing a sombrero.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "Man who follows car will be exhausted." - Confucius

                          L 1 Reply Last reply
                          0
                          • D David Crow

                            Richard MacCutchan wrote:

                            ...I shall perform a suitable act of self-humiliation in penance!

                            No, I do not wish to see you dancing on a table wearing a sombrero.

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            "Man who follows car will be exhausted." - Confucius

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #15

                            I've been told my maracas are a sight to behold. :laugh:

                            It's time for a new signature.

                            D 1 Reply Last reply
                            0
                            • L Lost User

                              I've been told my maracas are a sight to behold. :laugh:

                              It's time for a new signature.

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

                              You did NOT just say that while I was eating.

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              "Man who follows car will be exhausted." - Confucius

                              1 Reply Last reply
                              0
                              • M mikert_2008

                                CDialog dlgAbout(IDD_ABOUTBOX); dlgAbout.DoModal();

                                C Offline
                                C Offline
                                Chris Meech
                                wrote on last edited by
                                #17

                                Just an idea to research further. Before you instantiate the dialog, would it not be possible to modify the IDD_ABOUTBOX dialog resource to change the caption property? I don't know how to do that, but that is one thing I would investigate. :)

                                Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

                                D 1 Reply Last reply
                                0
                                • C Chris Meech

                                  Just an idea to research further. Before you instantiate the dialog, would it not be possible to modify the IDD_ABOUTBOX dialog resource to change the caption property? I don't know how to do that, but that is one thing I would investigate. :)

                                  Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

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

                                  I *think* this is what InitModalIndirect() was suggested for. Like you, however, I've not personally tried it.

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  "Man who follows car will be exhausted." - Confucius

                                  1 Reply Last reply
                                  0
                                  • M mikert_2008

                                    Hi, I have the dialog box. Which I am using as Modal dialog box with DoModal functionality. I need to change the Title(Caption) of dialog box before calling the domodal(). Since I am deciding the title of dialog box at run time I can't use the resource setting. One way I know to change the title of Modal Dialog Box is to use OnInitDialog() function of the class derived from the DialgBox and then call setwindowtext() function inside it. But I want to change the title/cation without using OnInitDialog as the project I am working doesn't have class derived from it. And doesn't look proper to genrate the class just for this purpose. Can anybody knows the other way of doing it?? Thanks in advance.. Mike.

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

                                    mikert_2008 wrote:

                                    ...the project I am working doesn't have class derived from it. And doesn't look proper to genrate the class just for this purpose.

                                    Other than looks, what reservations do you have to this approach? Read here for Paul's response to using a CDialog object directly.

                                    "One man's wage rise is another man's price increase." - Harold Wilson

                                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                    "Man who follows car will be exhausted." - Confucius

                                    1 Reply Last reply
                                    0
                                    • M mikert_2008

                                      Hi, I have the dialog box. Which I am using as Modal dialog box with DoModal functionality. I need to change the Title(Caption) of dialog box before calling the domodal(). Since I am deciding the title of dialog box at run time I can't use the resource setting. One way I know to change the title of Modal Dialog Box is to use OnInitDialog() function of the class derived from the DialgBox and then call setwindowtext() function inside it. But I want to change the title/cation without using OnInitDialog as the project I am working doesn't have class derived from it. And doesn't look proper to genrate the class just for this purpose. Can anybody knows the other way of doing it?? Thanks in advance.. Mike.

                                      A Offline
                                      A Offline
                                      Aescleal
                                      wrote on last edited by
                                      #20

                                      I had a quick scan through the answers below and you didn't seem that enamoured of any of them as you weren't using/couldn't use MFC. Having said that you've already answered your own question...

                                      mikert_2008 wrote:

                                      One way I know to change the title of Modal Dialog Box is to use OnInitDialog() function of the class derived from the DialgBox and then call setwindowtext() function inside it.

                                      If you look at the MFC documentation or read the source code you'll see that CDialog::OnInitDialog is called in response to a WM_INITDIALOG message being sent to the dialog box. All you have to do in your code is handle WM_INITDIALOG and call SetWindowText at that point. Cheers, Ash

                                      1 Reply Last reply
                                      0
                                      • M mikert_2008

                                        Hi, As I mentioned I am not having any Dialog class where I can use the OnInitDialog() function. I want to do it without using it. What I am trying for is the without using separate dialog class for it. Thanks Mike

                                        K Offline
                                        K Offline
                                        KarstenK
                                        wrote on last edited by
                                        #21

                                        if you had an own dialog class you wont need this discussions :rolleyes:

                                        Press F1 for help or google it. Greetings from Germany

                                        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