0

Trying to slide a window up and down. But trying to make it resize at the same time so the bottom stays at same place. Problem im having is that when the window is sliding up the bottom part flickers 5pixels or so. The window slides down with no problems.

here is part of the code im doing it with a dialog box that is a resource.

int w       = 500;
int h       = 150;
int Speed   = 10;

bool StartSlide()
{
    m_pDlg->GetWindowRect(&m_MyPos);

    for (int i = 0; i <= h; i += 5)
    {
        Sleep(Speed);
        SetWindowPos(m_pDlg, m_MyPos.left, m_MyPos.top - i, w, i, SWP_SHOWWINDOW | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
    }

    return true;
}

bool Close()
{
    RECT thisWindow;
    GetWindowRect(&thisWindow);

    for (int i = 0; i <= h; i += 5)
    {
        Sleep(Speed);
        SetWindowPos(m_pDlg, thisWindow.left, thisWindow.top + i, w, h - i, SWP_SHOWWINDOW | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION);
    }

    return true;
}
Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
mutotu
  • 1
  • 2
  • When the window gets bigger by 5 pixels, then the new area has to be painted. It's a resizing issue, the same problem is there if you resize by hand. Try `WM_CLIPCHILDREN`, try overriding `WM_ERASEBKGND` etc. – Barmak Shemirani Oct 21 '15 at 08:07
  • Have tried all that still seems to be doing it – mutotu Oct 21 '15 at 09:46
  • Just disable painting/updates when window is going through this stage. When window is ready, enable the painting and background updates. Otherwise you should start a different question, see if you can narrow down the problem with flickering. By the way, there is problems with usage of `Sleep`, it's not accurate. – Barmak Shemirani Oct 21 '15 at 15:59

1 Answers1

0

This issue is actually based on processing ability, and has little to do with your program. The reason that the flickering is occurring is because you are implementing two operations; you are seeing one occur (moving or resizing the window - whichever comes first - by ~5px) and then the other one at least one frame later, when the window moves/resizes the match the first change. Try playing around with the int Speed variable and see if you can get it to make the animation smoother.

If this doesn't work, there may be a way to optimise your code, allowing it to perform faster - but I'll leave that discussion to someone more experienced in that field.

Edit: This question and this question may be helpful to you in solving the dilemma.

Community
  • 1
  • 1
brads3290
  • 1,926
  • 1
  • 14
  • 20
  • But im running it on a top of the line computer so processing power should not be a problem. also the window moving/resizing is in the same function. Why does it work fine when it slides my window down? i have tryed messing with my sleeps and stuff like that dont change much, i can change the size of the flash it depends on how much i move the window each time – mutotu Oct 21 '15 at 06:14
  • Hmm.. Whenever I've had issues with that kind of thing its been using Windows Forms (.NET) so perhaps is a different cause with your problem – brads3290 Oct 21 '15 at 06:52
  • Its gotta be something simple, i thought maybe it was my math when sliding it up, but not to sure. it only seems to happen when im resizing and moving, if i was to just slide the window up without resizing the window it wouldnt flicker the bottom part. its like the bottom of the window is moving up the 5px then back down the 5px in same loop – mutotu Oct 21 '15 at 07:23
  • When i debug it and catch the loop and play it back loop at a time it seems fine – mutotu Oct 21 '15 at 07:44