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 to get Dialog handle

How to get Dialog handle

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
11 Posts 8 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.
  • A Anu_Bala

    Im using Setwindowpos of one dialog in another class. if i use Setwindowpos,it shows arror. I dont know how to get dialog handle. My dailog class is CToolTab and id is IDD_TOOLBAR I used

    GetDlgItem(IDD_TOOLBAR)->SetWinowPos(.....

    But fails. Pls help me.

    Anu

    N Offline
    N Offline
    Nelek
    wrote on last edited by
    #2

    One possibility could be (calling the function inside your dialog, maybe when showing up):

    CSomeDialog::SomeMethod()
    {
    HANDLE p_Dlg = GetDlgItem((HANDLE)this, IDC_YOURDIALOG);
    //...
    }

    afterwards you can give the handle to be used in other place. Forget it. I choose false example from the net. Thanks for correction Stephen :)

    Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

    modified on Thursday, January 21, 2010 4:43 AM

    S 1 Reply Last reply
    0
    • A Anu_Bala

      Im using Setwindowpos of one dialog in another class. if i use Setwindowpos,it shows arror. I dont know how to get dialog handle. My dailog class is CToolTab and id is IDD_TOOLBAR I used

      GetDlgItem(IDD_TOOLBAR)->SetWinowPos(.....

      But fails. Pls help me.

      Anu

      V Offline
      V Offline
      vasu_sri
      wrote on last edited by
      #3

      if u have pointer of dialog, then CWnd *pWnd=NULL; HWND hWnd= m_pDlg->GetSafeHwnd(); pWnd=FromHandle(hWnd);

      Regards, Srinivas

      A 1 Reply Last reply
      0
      • A Anu_Bala

        Im using Setwindowpos of one dialog in another class. if i use Setwindowpos,it shows arror. I dont know how to get dialog handle. My dailog class is CToolTab and id is IDD_TOOLBAR I used

        GetDlgItem(IDD_TOOLBAR)->SetWinowPos(.....

        But fails. Pls help me.

        Anu

        S Offline
        S Offline
        SandipG
        wrote on last edited by
        #4

        Are you trying to add ToolBar to a CDialog? If yes Check following articles CToolbarDialog - dialog with floating toolbar[^] http://www.codeguru.com/cpp/w-d/dislog/toolbarsandstatusbars/article.php/c1949/[^] If that is not the case please ignore my message. I hope it helps.

        Regards, Sandip.

        1 Reply Last reply
        0
        • V vasu_sri

          if u have pointer of dialog, then CWnd *pWnd=NULL; HWND hWnd= m_pDlg->GetSafeHwnd(); pWnd=FromHandle(hWnd);

          Regards, Srinivas

          A Offline
          A Offline
          Anu_Bala
          wrote on last edited by
          #5

          pWnd valure returns as Undefined Value.

          Anu

          V 1 Reply Last reply
          0
          • A Anu_Bala

            pWnd valure returns as Undefined Value.

            Anu

            V Offline
            V Offline
            vasu_sri
            wrote on last edited by
            #6

            might be pointer of dialog box is wrong. try out same way.

            Regards, Srinivas

            1 Reply Last reply
            0
            • N Nelek

              One possibility could be (calling the function inside your dialog, maybe when showing up):

              CSomeDialog::SomeMethod()
              {
              HANDLE p_Dlg = GetDlgItem((HANDLE)this, IDC_YOURDIALOG);
              //...
              }

              afterwards you can give the handle to be used in other place. Forget it. I choose false example from the net. Thanks for correction Stephen :)

              Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

              modified on Thursday, January 21, 2010 4:43 AM

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #7

              Nelek wrote:

              CSomeDialog::SomeMethod() { HANDLE p_Dlg = GetDlgItem((HANDLE)this, IDC_YOURDIALOG); //... }

              This code is flawed:

              1. GetDlgItem's first parameter is a HWND, not a HANDLE. Your code will give a compiler error.
              2. Even is the code was modified to look like the following, it would still be wrong: HWND p_Dlg = GetDlgItem((HWND)this, IDC_YOURDIALOG); Using what in this case is essentially a reinterpret_cast doesn't make a pointer a HWND. The cast just tells the compiler that although it knows a pointer isn't a HWND and would normally not normally compile code that incorrectly assumes it is, that in this case it should just shut-up and plough on.

              Steve

              N 1 Reply Last reply
              0
              • S Stephen Hewitt

                Nelek wrote:

                CSomeDialog::SomeMethod() { HANDLE p_Dlg = GetDlgItem((HANDLE)this, IDC_YOURDIALOG); //... }

                This code is flawed:

                1. GetDlgItem's first parameter is a HWND, not a HANDLE. Your code will give a compiler error.
                2. Even is the code was modified to look like the following, it would still be wrong: HWND p_Dlg = GetDlgItem((HWND)this, IDC_YOURDIALOG); Using what in this case is essentially a reinterpret_cast doesn't make a pointer a HWND. The cast just tells the compiler that although it knows a pointer isn't a HWND and would normally not normally compile code that incorrectly assumes it is, that in this case it should just shut-up and plough on.

                Steve

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #8

                Hmmm, thanks for the info. I'll wrap the answer.

                Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

                1 Reply Last reply
                0
                • A Anu_Bala

                  Im using Setwindowpos of one dialog in another class. if i use Setwindowpos,it shows arror. I dont know how to get dialog handle. My dailog class is CToolTab and id is IDD_TOOLBAR I used

                  GetDlgItem(IDD_TOOLBAR)->SetWinowPos(.....

                  But fails. Pls help me.

                  Anu

                  R Offline
                  R Offline
                  Raj Indian
                  wrote on last edited by
                  #9

                  Could you please post you code snippet?

                  1 Reply Last reply
                  0
                  • A Anu_Bala

                    Im using Setwindowpos of one dialog in another class. if i use Setwindowpos,it shows arror. I dont know how to get dialog handle. My dailog class is CToolTab and id is IDD_TOOLBAR I used

                    GetDlgItem(IDD_TOOLBAR)->SetWinowPos(.....

                    But fails. Pls help me.

                    Anu

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

                    Anu_Bala wrote:

                    Im using Setwindowpos of one dialog in another class.

                    GetDlgItem() returns a handle to a sub item within a Dialog, not to a Dialog window. It is much better to do this in the Dialog itself, when you handle the WM_INITDIALOG message.

                    MVP 2010 - are they mad?

                    1 Reply Last reply
                    0
                    • A Anu_Bala

                      Im using Setwindowpos of one dialog in another class. if i use Setwindowpos,it shows arror. I dont know how to get dialog handle. My dailog class is CToolTab and id is IDD_TOOLBAR I used

                      GetDlgItem(IDD_TOOLBAR)->SetWinowPos(.....

                      But fails. Pls help me.

                      Anu

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

                      Anu_Bala wrote:

                      if i use Setwindowpos,it shows arror.

                      I'm having a hard time seeing the error from here. Could you please post 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

                      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