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 can I get the handle of the dialog ?

How can I get the handle of the dialog ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 5 Posters 1 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.
  • S Offline
    S Offline
    SherTeks
    wrote on last edited by
    #1

    I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.

    CLoginNConfigDlg clncdLoginNConfig;

    m_pMainWnd = &clncdLoginNConfig;

    HWND hand = clncdLoginNConfig.m_hWnd;

    I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance

    S P M 3 Replies Last reply
    0
    • S SherTeks

      I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.

      CLoginNConfigDlg clncdLoginNConfig;

      m_pMainWnd = &clncdLoginNConfig;

      HWND hand = clncdLoginNConfig.m_hWnd;

      I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance

      S Offline
      S Offline
      Saurabh Garg
      wrote on last edited by
      #2

      That is because there is no window created yet. A Dialog is created only when you call DoModal (for a modal dialog ofcourse). Try calling this in OnInitDialog member of the dialog class. -Saurabh

      1 Reply Last reply
      0
      • S SherTeks

        I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.

        CLoginNConfigDlg clncdLoginNConfig;

        m_pMainWnd = &clncdLoginNConfig;

        HWND hand = clncdLoginNConfig.m_hWnd;

        I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance

        P Offline
        P Offline
        pallaka
        wrote on last edited by
        #3

        HANDLE p_Dialog= GetDlgItem(/*handle of dialogbox*/,IDDIALOG); The GetDlgItem function retrieves a handle to a control in the specified dialog box. Syntax

        HWND GetDlgItem( HWND hDlg,
        int nIDDlgItem
        );

        Parameters hDlg [in] Handle to the dialog box that contains the control. nIDDlgItem [in] Specifies the identifier of the control to be retrieved. Return Value If the function succeeds, the return value is the window handle of the specified control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.

        S 1 Reply Last reply
        0
        • P pallaka

          HANDLE p_Dialog= GetDlgItem(/*handle of dialogbox*/,IDDIALOG); The GetDlgItem function retrieves a handle to a control in the specified dialog box. Syntax

          HWND GetDlgItem( HWND hDlg,
          int nIDDlgItem
          );

          Parameters hDlg [in] Handle to the dialog box that contains the control. nIDDlgItem [in] Specifies the identifier of the control to be retrieved. Return Value If the function succeeds, the return value is the window handle of the specified control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.

          S Offline
          S Offline
          Saurabh Garg
          wrote on last edited by
          #4

          Nope this doesnt work. GetDlgItem either works in the CDialog derived classes, in that case you can simply use m_hWnd, or it expectes two parameters and first is HWND of the the dialog. -Saurabh

          P 1 Reply Last reply
          0
          • S Saurabh Garg

            Nope this doesnt work. GetDlgItem either works in the CDialog derived classes, in that case you can simply use m_hWnd, or it expectes two parameters and first is HWND of the the dialog. -Saurabh

            P Offline
            P Offline
            pallaka
            wrote on last edited by
            #5

            Hi, But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel. And once the function executes u will get the Dialog handel, as it returns the handel of the window.

            CPalliniC S 2 Replies Last reply
            0
            • P pallaka

              Hi, But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel. And once the function executes u will get the Dialog handel, as it returns the handel of the window.

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

              pallaka wrote:

              But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel.

              What is the 'default dialog handle'?

              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?

              P 1 Reply Last reply
              0
              • CPalliniC CPallini

                pallaka wrote:

                But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel.

                What is the 'default dialog handle'?

                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]

                P Offline
                P Offline
                pallaka
                wrote on last edited by
                #7

                You just pass Hwnd = NULL as parameter. The return value will be your dialog handel. try it will work for sure.

                1 Reply Last reply
                0
                • P pallaka

                  Hi, But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel. And once the function executes u will get the Dialog handel, as it returns the handel of the window.

                  S Offline
                  S Offline
                  Saurabh Garg
                  wrote on last edited by
                  #8

                  I just tried this and I get NULL pointer on return. I also checked MSDN and it doesn't say anything about first parameter being NULL. In fact it specifically says: "If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control." I take that as input dialog boc handle must be valid. Can you share you source of information? -Saurabh Edit1: I checked GetLastError after calling GetDlgItem(NULL, IDD_MYDIALOG) and it says Invalid Window Handle. Edit2: Okay just saw that you modified your original post to include MSDN documentation.

                  1 Reply Last reply
                  0
                  • S SherTeks

                    I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.

                    CLoginNConfigDlg clncdLoginNConfig;

                    m_pMainWnd = &clncdLoginNConfig;

                    HWND hand = clncdLoginNConfig.m_hWnd;

                    I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    an important concept to know in MFC is that window creation and destruction are TWO STEP PROCESSES.... 1) the C++ object - a CWnd or derived object 2) the operating system object - an HWND You have only created item 1 :) Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    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