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. Drawing Controls Problem

Drawing Controls Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsquestion
6 Posts 3 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.
  • J Offline
    J Offline
    John Clump
    wrote on last edited by
    #1

    Hi everyone. I have some code which centers a series of buttons on a dialog, which is in OnSize(). Problem I have is, as the user resizes the control, the buttons are drawn twice (?), and there are "artifacts" of the original draw are still there. If the window is minimized and brought back up again, the buttons draw properly and the "artifacts" are gone. The buttons do center and adjust properly as the window is resized, but leave those "artifacts" for some reason. It doesn't happen when the window is maximized and normalized, but do occur when the user drags the window frame and resizes that way. I am also using Paul Wendt's CControlPos class which is found on Codeproject, which moves all the other controls (I had to move the buttons manually to achieve the centering with a series of buttons). Anyone have any ideas? Any help is greatly appreciated! void CDlgMain::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); CRect rcButtonRect; // size once window is created, then move buttons appropriately if(::IsWindow(GetDlgItem(IDC_BTN_ADD)->GetSafeHwnd())) { // resizing calculations done here bool bDrawAgain = true; // draw add button GetDlgItem(IDC_BTN_ADD)->MoveWindow(rcButtonRect, bDrawAgain); // draw edit button rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_EDIT)->MoveWindow(rcButtonRect, bDrawAgain); // draw delete button rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_DELETE)->MoveWindow(rcButtonRect, bDrawAgain); // draw copy button iButtonLeft = 391; rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_COPY)->MoveWindow(rcButtonRect, bDrawAgain); } // Paul Wendt's CControlPos class, this moves all other // controls // this class calls the following code to draw each // control // m_pParent->ScreenToClient(rcBounds); // pControl->MoveWindow(rcBounds); m_cControlPos.MoveControls(); }

    S R 2 Replies Last reply
    0
    • J John Clump

      Hi everyone. I have some code which centers a series of buttons on a dialog, which is in OnSize(). Problem I have is, as the user resizes the control, the buttons are drawn twice (?), and there are "artifacts" of the original draw are still there. If the window is minimized and brought back up again, the buttons draw properly and the "artifacts" are gone. The buttons do center and adjust properly as the window is resized, but leave those "artifacts" for some reason. It doesn't happen when the window is maximized and normalized, but do occur when the user drags the window frame and resizes that way. I am also using Paul Wendt's CControlPos class which is found on Codeproject, which moves all the other controls (I had to move the buttons manually to achieve the centering with a series of buttons). Anyone have any ideas? Any help is greatly appreciated! void CDlgMain::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); CRect rcButtonRect; // size once window is created, then move buttons appropriately if(::IsWindow(GetDlgItem(IDC_BTN_ADD)->GetSafeHwnd())) { // resizing calculations done here bool bDrawAgain = true; // draw add button GetDlgItem(IDC_BTN_ADD)->MoveWindow(rcButtonRect, bDrawAgain); // draw edit button rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_EDIT)->MoveWindow(rcButtonRect, bDrawAgain); // draw delete button rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_DELETE)->MoveWindow(rcButtonRect, bDrawAgain); // draw copy button iButtonLeft = 391; rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_COPY)->MoveWindow(rcButtonRect, bDrawAgain); } // Paul Wendt's CControlPos class, this moves all other // controls // this class calls the following code to draw each // control // m_pParent->ScreenToClient(rcBounds); // pControl->MoveWindow(rcBounds); m_cControlPos.MoveControls(); }

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      Is WS_CLIPCHILDREN set for the dialog? Maybe calling CDialog::OnSize(nType, cx, cy); after moving the controls would work. farewell goodnight last one out turn out the lights

      Smashing Pumpkins, Tales of a Scorched Earth

      J 1 Reply Last reply
      0
      • S Shog9 0

        Is WS_CLIPCHILDREN set for the dialog? Maybe calling CDialog::OnSize(nType, cx, cy); after moving the controls would work. farewell goodnight last one out turn out the lights

        Smashing Pumpkins, Tales of a Scorched Earth

        J Offline
        J Offline
        John Clump
        wrote on last edited by
        #3

        I tried doing both, with no luck :( It still leaves junk behind when the user drags on the window frame

        S 1 Reply Last reply
        0
        • J John Clump

          I tried doing both, with no luck :( It still leaves junk behind when the user drags on the window frame

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #4

          well, you could also pass in FALSE to all the MoveWindow() calls, then follow everything with Invalidate(TRUE). It'll flicker a bit, but should look ok. farewell goodnight last one out turn out the lights

          Smashing Pumpkins, Tales of a Scorched Earth

          1 Reply Last reply
          0
          • J John Clump

            Hi everyone. I have some code which centers a series of buttons on a dialog, which is in OnSize(). Problem I have is, as the user resizes the control, the buttons are drawn twice (?), and there are "artifacts" of the original draw are still there. If the window is minimized and brought back up again, the buttons draw properly and the "artifacts" are gone. The buttons do center and adjust properly as the window is resized, but leave those "artifacts" for some reason. It doesn't happen when the window is maximized and normalized, but do occur when the user drags the window frame and resizes that way. I am also using Paul Wendt's CControlPos class which is found on Codeproject, which moves all the other controls (I had to move the buttons manually to achieve the centering with a series of buttons). Anyone have any ideas? Any help is greatly appreciated! void CDlgMain::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); CRect rcButtonRect; // size once window is created, then move buttons appropriately if(::IsWindow(GetDlgItem(IDC_BTN_ADD)->GetSafeHwnd())) { // resizing calculations done here bool bDrawAgain = true; // draw add button GetDlgItem(IDC_BTN_ADD)->MoveWindow(rcButtonRect, bDrawAgain); // draw edit button rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_EDIT)->MoveWindow(rcButtonRect, bDrawAgain); // draw delete button rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_DELETE)->MoveWindow(rcButtonRect, bDrawAgain); // draw copy button iButtonLeft = 391; rcButtonRect.left = ((cx - iParentWidth)/2) + iButtonLeft; rcButtonRect.right = rcButtonRect.left + iButtonWidth; GetDlgItem(IDC_BTN_COPY)->MoveWindow(rcButtonRect, bDrawAgain); } // Paul Wendt's CControlPos class, this moves all other // controls // this class calls the following code to draw each // control // m_pParent->ScreenToClient(rcBounds); // pControl->MoveWindow(rcBounds); m_cControlPos.MoveControls(); }

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            I've also seen this problem when resizing static picture controls (eg: frame borders). Try invalidating and updating the dialog at the end of the repositioning.

            void CDlgMain::OnSize(UINT nType, int cx, int cy)
            {
            CDialog::OnSize(nType, cx, cy);
            .... // rest of your code
            Invalidate();
            UpdateWindow();
            }

            /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

            J 1 Reply Last reply
            0
            • R Ravi Bhavnani

              I've also seen this problem when resizing static picture controls (eg: frame borders). Try invalidating and updating the dialog at the end of the repositioning.

              void CDlgMain::OnSize(UINT nType, int cx, int cy)
              {
              CDialog::OnSize(nType, cx, cy);
              .... // rest of your code
              Invalidate();
              UpdateWindow();
              }

              /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

              J Offline
              J Offline
              John Clump
              wrote on last edited by
              #6

              That worked great! Thanks for the help!

              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