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. Moving controls on a dialog

Moving controls on a dialog

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

    I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny

    D P R B 4 Replies Last reply
    0
    • B bugDanny

      I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny

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

      bugDanny wrote: Can the member variable connected to those controls work as the window handle, or houw can this be done? Why not just use CWnd::GetWindowRect() and CWnd::MoveWindow()? No handle required.


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      1 Reply Last reply
      0
      • B bugDanny

        I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny

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

        You can use control variable associated with it.Alternatively ,Use GetDlgItem() for getting control windows and use those.

        A 1 Reply Last reply
        0
        • B bugDanny

          I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny

          R Offline
          R Offline
          Rage
          wrote on last edited by
          #4

          Most controls are directly derived from CWnd, in which case you can use the CWnd member function of ::GetWindowRect() and ::MoveWindow(), meaning :

          RECT rect;
          m_mycontrol.GetWindowRect(&rect);

          If you absolutley want to use the upper scope functions, you can retrieve the HWND using GetSafeHwnd()

          HWND hWnd = m_mycontrol.GetSafeHwnd()

          BTW, you might want to consider also GetClientRect(), as well as ScreenToClient() and ClientToScreen() to play around moving controls, because I am afraid that the two functions you mentioned will not be sufficient. Hope this helps, ~RaGE();

          1 Reply Last reply
          0
          • P prasad_som

            You can use control variable associated with it.Alternatively ,Use GetDlgItem() for getting control windows and use those.

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

            Depending on what you want to do, there is also some nice articles on here for dynamically moving all controls when resizing dialogues. I tend to map controsl to control variables and use their own move methods, eg: m_btnOK.MoveWindow(...); Rather than: pWnd = GetDlgItem(IDOK) if(pWnd != NULL) pWnd->MoveWindow(...) Mapping variables to the controls uses less code and no need to worry about correct id values, null pointers etc. HTH. Andrew

            1 Reply Last reply
            0
            • B bugDanny

              I'm writing an app that I want to be able to dynamically move some controls around on my dialog box. I was thinking of simply using ::GetWindowRect() and ::MoveWindow() to do that, but for those functions I need the window handle (HWND). Can the member variable connected to those controls work as the window handle, or houw can this be done? Danny

              B Offline
              B Offline
              bugDanny
              wrote on last edited by
              #6

              Thanks all! Danny

              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