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. Moving controls center via programming

Moving controls center via programming

Scheduled Pinned Locked Moved C / C++ / MFC
designtutorialquestion
6 Posts 4 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.
  • R Offline
    R Offline
    raghuji rao
    wrote on last edited by
    #1

    Hi i hv design the controls in a form view. i want to move all controls to the center alignment with a frame control.how to do these? -- modified at 0:43 Thursday 18th May, 2006

    S S 2 Replies Last reply
    0
    • R raghuji rao

      Hi i hv design the controls in a form view. i want to move all controls to the center alignment with a frame control.how to do these? -- modified at 0:43 Thursday 18th May, 2006

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      it seems u have to calculate the width of the window and control and accordingly place it using MoveWindow function. -Sarath

      R 1 Reply Last reply
      0
      • S Sarath C

        it seems u have to calculate the width of the window and control and accordingly place it using MoveWindow function. -Sarath

        R Offline
        R Offline
        raghuji rao
        wrote on last edited by
        #3

        no There is one api with which we can move all the controls in a single instance do anyone know these?

        R 1 Reply Last reply
        0
        • R raghuji rao

          no There is one api with which we can move all the controls in a single instance do anyone know these?

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          raghuji.rao wrote:

          no There is one api with which we can move all the controls in a single instance

          No there is not. You were given the correct answer before.

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          1 Reply Last reply
          0
          • R raghuji rao

            Hi i hv design the controls in a form view. i want to move all controls to the center alignment with a frame control.how to do these? -- modified at 0:43 Thursday 18th May, 2006

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

            Here's some code to do it. Call "CenterChildren" with a HWND. ------------------------------------------------------------- BOOL CALLBACK MeasureChildrenBoundsProc(HWND hwnd, LPARAM lParam) { RECT *pRectUnion = reinterpret_cast(lParam); RECT RectControl; GetWindowRect(hwnd, &RectControl); HWND hParent = GetParent(hwnd); MapWindowPoints(NULL, hParent, reinterpret_cast(&RectControl), 2); UnionRect(pRectUnion, pRectUnion, &RectControl); return TRUE; } BOOL CALLBACK OffsetChildrenProc(HWND hwnd, LPARAM lParam) { POINT *pPoint = reinterpret_cast(lParam); RECT RectControl; GetWindowRect(hwnd, &RectControl); HWND hParent = GetParent(hwnd); MapWindowPoints(NULL, hParent, reinterpret_cast(&RectControl), 2); SetWindowPos( hwnd, NULL, RectControl.left+pPoint->x, RectControl.top+pPoint->y, 0, 0, SWP_NOZORDER|SWP_NOSIZE ); return TRUE; } void CenterChildren(HWND hWnd) { // Calculate the bounding box around our children. RECT rc = {0}; EnumChildWindows(hWnd, &MeasureChildrenBoundsProc, reinterpret_cast(&rc)); // Move the children. RECT RectParent; GetClientRect(hWnd, &RectParent); int ParentWidth = RectParent.right-RectParent.left; int ParentHeight = RectParent.bottom-RectParent.top; int ChildrenWidth = rc.right-rc.left; int ChildrenHeight = rc.bottom-rc.top; POINT offset = {(ParentWidth-ChildrenWidth)/2-rc.left, (ParentHeight-ChildrenHeight)/2-rc.top}; EnumChildWindows(hWnd, &OffsetChildrenProc, reinterpret_cast(&offset)); } Steve

            R 1 Reply Last reply
            0
            • S Stephen Hewitt

              Here's some code to do it. Call "CenterChildren" with a HWND. ------------------------------------------------------------- BOOL CALLBACK MeasureChildrenBoundsProc(HWND hwnd, LPARAM lParam) { RECT *pRectUnion = reinterpret_cast(lParam); RECT RectControl; GetWindowRect(hwnd, &RectControl); HWND hParent = GetParent(hwnd); MapWindowPoints(NULL, hParent, reinterpret_cast(&RectControl), 2); UnionRect(pRectUnion, pRectUnion, &RectControl); return TRUE; } BOOL CALLBACK OffsetChildrenProc(HWND hwnd, LPARAM lParam) { POINT *pPoint = reinterpret_cast(lParam); RECT RectControl; GetWindowRect(hwnd, &RectControl); HWND hParent = GetParent(hwnd); MapWindowPoints(NULL, hParent, reinterpret_cast(&RectControl), 2); SetWindowPos( hwnd, NULL, RectControl.left+pPoint->x, RectControl.top+pPoint->y, 0, 0, SWP_NOZORDER|SWP_NOSIZE ); return TRUE; } void CenterChildren(HWND hWnd) { // Calculate the bounding box around our children. RECT rc = {0}; EnumChildWindows(hWnd, &MeasureChildrenBoundsProc, reinterpret_cast(&rc)); // Move the children. RECT RectParent; GetClientRect(hWnd, &RectParent); int ParentWidth = RectParent.right-RectParent.left; int ParentHeight = RectParent.bottom-RectParent.top; int ChildrenWidth = rc.right-rc.left; int ChildrenHeight = rc.bottom-rc.top; POINT offset = {(ParentWidth-ChildrenWidth)/2-rc.left, (ParentHeight-ChildrenHeight)/2-rc.top}; EnumChildWindows(hWnd, &OffsetChildrenProc, reinterpret_cast(&offset)); } Steve

              R Offline
              R Offline
              raghuji rao
              wrote on last edited by
              #6

              thanx steve , i 'll try these

              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