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 dynamically

moving controls on a dialog dynamically

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

    Hi, I have a dialog based application on which I have a tab control made of dialogs. On the tab pages I have some controls. I want to move some of these controls dynamically. The control's start coordinates seen from the resource view are (7,3), which should be seen as left:7,top:3 from a CRect type. I see some strange behaviour with the below codes (called from CTab1Dlg class member functions): Test 1: CRect rect; GetDlgItem(IDC_STAT1)->GetClientRect(&rect); // start point is (0,0) here GetDlgItem(IDC_STAT1)->MoveWindow(&rect); UpdateData(false); afterwards the control moves to the left and upwards. Test 2: If I put this line before MoveWindow() line above, then the control still moves to left and upwards, but this time a little. rect.OffsetRect(7,3); Test 3: If I change the inputs to (11,5), then the position does not change: rect.OffsetRect(11,5); Test 4: If I try to get the coordinates of the tab's dialog then I get an access violation when i try to reach its members: GetDlgItem(IDD_TAB1)->GetClientRect(&rect); I want to shift the controls upwards and downwards dynamically. How can I get the correct initial coordinates? thanks in advance

    I D 2 Replies Last reply
    0
    • C caykahve

      Hi, I have a dialog based application on which I have a tab control made of dialogs. On the tab pages I have some controls. I want to move some of these controls dynamically. The control's start coordinates seen from the resource view are (7,3), which should be seen as left:7,top:3 from a CRect type. I see some strange behaviour with the below codes (called from CTab1Dlg class member functions): Test 1: CRect rect; GetDlgItem(IDC_STAT1)->GetClientRect(&rect); // start point is (0,0) here GetDlgItem(IDC_STAT1)->MoveWindow(&rect); UpdateData(false); afterwards the control moves to the left and upwards. Test 2: If I put this line before MoveWindow() line above, then the control still moves to left and upwards, but this time a little. rect.OffsetRect(7,3); Test 3: If I change the inputs to (11,5), then the position does not change: rect.OffsetRect(11,5); Test 4: If I try to get the coordinates of the tab's dialog then I get an access violation when i try to reach its members: GetDlgItem(IDD_TAB1)->GetClientRect(&rect); I want to shift the controls upwards and downwards dynamically. How can I get the correct initial coordinates? thanks in advance

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      There is some mixing of terminology going on here. The resource view coords (7,3) are in dialog coordinates. The relationship between these and pixel coords varies depending on DPI. This the big / small fonts in the display control panel. Taking Test1:

      GetDlgItem(IDC_STAT1)->GetClientRect(&rect);

      This returns the client coordinates which *always* starts at (0,0) for its top left. These are relative to IDC_STAT1. You want:

      GetDlgItem(IDC_STAT1)->GetWindowRect(&rect);
      ScreenToClient (&rect);

      instead. Test2: This shows that dialog and screen coords are not the same thing. Test3: You've experimentally found the result of MapDialogRect function. But be careful. The results will change on a high resolution screen, where someone has chosen larger fonts. This used to be rare, but these days you can get very high res laptop displays. Test4: You haven't provided enough information for this. Again, you are using GetClientRect instead of GetWindowRect / ScreenToClient. Dies GetDlgItem (IDD_TAB1) work? Or does it return NULL? I hope this puts you on the right path, Iain.

      C 1 Reply Last reply
      0
      • I Iain Clarke Warrior Programmer

        There is some mixing of terminology going on here. The resource view coords (7,3) are in dialog coordinates. The relationship between these and pixel coords varies depending on DPI. This the big / small fonts in the display control panel. Taking Test1:

        GetDlgItem(IDC_STAT1)->GetClientRect(&rect);

        This returns the client coordinates which *always* starts at (0,0) for its top left. These are relative to IDC_STAT1. You want:

        GetDlgItem(IDC_STAT1)->GetWindowRect(&rect);
        ScreenToClient (&rect);

        instead. Test2: This shows that dialog and screen coords are not the same thing. Test3: You've experimentally found the result of MapDialogRect function. But be careful. The results will change on a high resolution screen, where someone has chosen larger fonts. This used to be rare, but these days you can get very high res laptop displays. Test4: You haven't provided enough information for this. Again, you are using GetClientRect instead of GetWindowRect / ScreenToClient. Dies GetDlgItem (IDD_TAB1) work? Or does it return NULL? I hope this puts you on the right path, Iain.

        C Offline
        C Offline
        caykahve
        wrote on last edited by
        #3

        Thank you. That helped. caykahve

        1 Reply Last reply
        0
        • C caykahve

          Hi, I have a dialog based application on which I have a tab control made of dialogs. On the tab pages I have some controls. I want to move some of these controls dynamically. The control's start coordinates seen from the resource view are (7,3), which should be seen as left:7,top:3 from a CRect type. I see some strange behaviour with the below codes (called from CTab1Dlg class member functions): Test 1: CRect rect; GetDlgItem(IDC_STAT1)->GetClientRect(&rect); // start point is (0,0) here GetDlgItem(IDC_STAT1)->MoveWindow(&rect); UpdateData(false); afterwards the control moves to the left and upwards. Test 2: If I put this line before MoveWindow() line above, then the control still moves to left and upwards, but this time a little. rect.OffsetRect(7,3); Test 3: If I change the inputs to (11,5), then the position does not change: rect.OffsetRect(11,5); Test 4: If I try to get the coordinates of the tab's dialog then I get an access violation when i try to reach its members: GetDlgItem(IDD_TAB1)->GetClientRect(&rect); I want to shift the controls upwards and downwards dynamically. How can I get the correct initial coordinates? thanks in advance

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

          See the "Extras" section of this article.


          "Take only what you need and leave the land as you found it." - Native American Proverb

          E 1 Reply Last reply
          0
          • D David Crow

            See the "Extras" section of this article.


            "Take only what you need and leave the land as you found it." - Native American Proverb

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            is that David Crow leaning sidewise ? :( .. you are like a BOSS so try Bolding it or just leave it like David Crow. it luks great. He is like a one-legged man in a bum kicking competition. -Novjot Sidhu --[v]--

            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