Drawing Controls Problem
-
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(); }
-
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(); }
-
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 lightsSmashing Pumpkins, Tales of a Scorched Earth
I tried doing both, with no luck :( It still leaves junk behind when the user drags on the window frame
-
I tried doing both, with no luck :( It still leaves junk behind when the user drags on the window frame
-
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(); }
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
-
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
That worked great! Thanks for the help!