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. How do I get the handle of a dialog in Visual C

How do I get the handle of a dialog in Visual C

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelptutorial
19 Posts 6 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.
  • J jonsey29847

    Hello, I am porting a Dialog based application that I used Lcc-Win32 to develop over to Visual C++. How to I get the handle of my Dialog box? Thanks in advance for your help.

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

    jonsey29847 wrote:

    How to I get the handle of my Dialog box?

    For what purpose?

    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

    "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

    L J 2 Replies Last reply
    0
    • D David Crow

      jonsey29847 wrote:

      How to I get the handle of my Dialog box?

      For what purpose?

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #3

      That question confuses me. What am I missing Dave? Just curious.

      D 1 Reply Last reply
      0
      • L led mike

        That question confuses me. What am I missing Dave? Just curious.

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

        led mike wrote:

        That question confuses me.

        Mine or the OP's?

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "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

        L 1 Reply Last reply
        0
        • J jonsey29847

          Hello, I am porting a Dialog based application that I used Lcc-Win32 to develop over to Visual C++. How to I get the handle of my Dialog box? Thanks in advance for your help.

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #5

          If it's your dialog, you probably have a variable assigned to it.

          YourDialog dlg;

          or

          YourDialog* pDlg;
          pDlg = new YourDialog;
          //...

          after you create the dialog (Create), you could do something like

          HWND CWnd::GetSafeHwnd( ) const;

          to get the handle to the dialog.

          This signature was proudly tested on animals.

          J 1 Reply Last reply
          0
          • D David Crow

            led mike wrote:

            That question confuses me.

            Mine or the OP's?

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "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

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #6

            Oh, sorry, yeah yours

            1 Reply Last reply
            0
            • D David Crow

              jonsey29847 wrote:

              How to I get the handle of my Dialog box?

              For what purpose?

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "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

              J Offline
              J Offline
              jonsey29847
              wrote on last edited by
              #7

              So I can use existing code in an application that I developed using Win32 APIs. i.e.SendMessage(HWND, ID, wparam, lparam) MFC "Hides" this from me. However, if I am taking off in wrong direction I would appreciate some guidance here. Thanks

              D 1 Reply Last reply
              0
              • M Maximilien

                If it's your dialog, you probably have a variable assigned to it.

                YourDialog dlg;

                or

                YourDialog* pDlg;
                pDlg = new YourDialog;
                //...

                after you create the dialog (Create), you could do something like

                HWND CWnd::GetSafeHwnd( ) const;

                to get the handle to the dialog.

                This signature was proudly tested on animals.

                J Offline
                J Offline
                jonsey29847
                wrote on last edited by
                #8

                MFC does not expose the handle to me, or does it? Thanks for fast replies!

                M 1 Reply Last reply
                0
                • J jonsey29847

                  MFC does not expose the handle to me, or does it? Thanks for fast replies!

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #9

                  Well, GetSafeHwnd() returns a safe handle to the dialog window. do you need something more ?

                  This signature was proudly tested on animals.

                  J 1 Reply Last reply
                  0
                  • M Maximilien

                    Well, GetSafeHwnd() returns a safe handle to the dialog window. do you need something more ?

                    This signature was proudly tested on animals.

                    J Offline
                    J Offline
                    jonsey29847
                    wrote on last edited by
                    #10

                    HWND hwndDlg = GetSafeHwnd(); Is it really that simple? How does GetSafeHwnd() know which window you wish the handle of? Thanks

                    D 1 Reply Last reply
                    0
                    • J jonsey29847

                      HWND hwndDlg = GetSafeHwnd(); Is it really that simple? How does GetSafeHwnd() know which window you wish the handle of? Thanks

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

                      jonsey29847 wrote:

                      How does GetSafeHwnd() know which window you wish the handle of?

                      It's called in the context of a CWnd object.

                      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                      "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

                      1 Reply Last reply
                      0
                      • J jonsey29847

                        So I can use existing code in an application that I developed using Win32 APIs. i.e.SendMessage(HWND, ID, wparam, lparam) MFC "Hides" this from me. However, if I am taking off in wrong direction I would appreciate some guidance here. Thanks

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

                        If you wanted to send a message to some edit control, you could use:

                        m_edit.SendMessage(WM_GETTEXTLENGTH, 0, 0);

                        or

                        ::SendMessage(m_edit.GetSafeHwnd(), WM_GETTEXTLENGTH, 0, 0);

                        or

                        m_edit.GetWindowTextLength();

                        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                        "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

                        J 1 Reply Last reply
                        0
                        • D David Crow

                          If you wanted to send a message to some edit control, you could use:

                          m_edit.SendMessage(WM_GETTEXTLENGTH, 0, 0);

                          or

                          ::SendMessage(m_edit.GetSafeHwnd(), WM_GETTEXTLENGTH, 0, 0);

                          or

                          m_edit.GetWindowTextLength();

                          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                          "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

                          J Offline
                          J Offline
                          jonsey29847
                          wrote on last edited by
                          #13

                          You have struck upon one of the problems I have using MFC. What does m_edit mean and where can I find a list of all the m_whatever? Thanks

                          D 1 Reply Last reply
                          0
                          • J jonsey29847

                            You have struck upon one of the problems I have using MFC. What does m_edit mean and where can I find a list of all the m_whatever? Thanks

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

                            jonsey29847 wrote:

                            What does m_edit mean and where can I find a list of all the m_whatever?

                            It's just an arbitrary name I chose for that code snippet. You may call it whatever you wish.

                            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                            "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

                            J 1 Reply Last reply
                            0
                            • D David Crow

                              jonsey29847 wrote:

                              What does m_edit mean and where can I find a list of all the m_whatever?

                              It's just an arbitrary name I chose for that code snippet. You may call it whatever you wish.

                              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                              "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

                              J Offline
                              J Offline
                              jonsey29847
                              wrote on last edited by
                              #15

                              Is it the name I assign using the class wizard?

                              D 1 Reply Last reply
                              0
                              • J jonsey29847

                                Is it the name I assign using the class wizard?

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

                                Yes.

                                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                                "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

                                J 1 Reply Last reply
                                0
                                • D David Crow

                                  Yes.

                                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                                  "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

                                  J Offline
                                  J Offline
                                  jonsey29847
                                  wrote on last edited by
                                  #17

                                  Wow! I can't wait to try it. I just love this website! Thanks.

                                  1 Reply Last reply
                                  0
                                  • J jonsey29847

                                    Hello, I am porting a Dialog based application that I used Lcc-Win32 to develop over to Visual C++. How to I get the handle of my Dialog box? Thanks in advance for your help.

                                    A Offline
                                    A Offline
                                    ali kanju
                                    wrote on last edited by
                                    #18

                                    associate a class with dialog and use object of that class to access dialog.

                                    1 Reply Last reply
                                    0
                                    • J jonsey29847

                                      Hello, I am porting a Dialog based application that I used Lcc-Win32 to develop over to Visual C++. How to I get the handle of my Dialog box? Thanks in advance for your help.

                                      S Offline
                                      S Offline
                                      sujeet
                                      wrote on last edited by
                                      #19

                                      In your dialog class m_hWnd varialbe will give you the handle of your dialog. You can store it as, HWND DialogHandle = m_hWnd ; Regards, Sujeet

                                      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