moving window and resize bottom flickers

I am trying to make a kind of popup notification window that slides out of the task bar.

At the moment I am only trying to get it to work if the taskbar is on bottom of screen, I have it working like it should.

But the problem im having is when the window is starting to appear/slide the bottom part of it flickers (depending on how big i have set my m_nIncrement value, it flashes the bottom area the same size as the m_nIncrement value) The window disappears fine with no flicker.

1
2
3
4
5
6
7
8
9
10
11
12
13
WNDCLASS wc =
{
    CS_HREDRAW | CS_VREDRAW, __sWndProcDlg, 0, 0, g_hInst, nullptr,
    LoadCursor(nullptr, IDC_ARROW), (HBRUSH)::GetStockObject(BLACK_BRUSH),
    nullptr, m_lpszClassName
};

if (!RegisterClass(&wc))
    return;

m_hWnd = CreateWindowEx(WS_EX_NOACTIVATE, m_lpszClassName, NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, m_hWndParent, NULL, g_hInst, NULL);



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void _ShowWindow(int _show)
{
    unsigned int nDesktopWidth = m_rcDesktop.right - m_rcDesktop.left;
    unsigned int nDesktopHeight = m_rcDesktop.bottom - m_rcDesktop.top;
    unsigned int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
    unsigned int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);

    BOOL bTaskbarOnRight = nDesktopWidth<nScreenWidth && m_rcDesktop.left == 0;
    BOOL bTaskbarOnLeft = nDesktopWidth<nScreenWidth && m_rcDesktop.left != 0;
    BOOL bTaskBarOnTop = nDesktopHeight<nScreenHeight && m_rcDesktop.top != 0;
    BOOL bTaskbarOnBottom = nDesktopHeight<nScreenHeight && m_rcDesktop.top == 0;

    if (_show)
    {
        ShowWindow(m_hWnd, SW_SHOW);

        if (bTaskbarOnBottom)
        {
            m_nCurrentPos.cx = m_rcDesktop.right - m_sMaxSize.cx;
            m_nCurrentPos.cy = m_rcDesktop.bottom - m_nCurrentSize.cy;
            m_nTaskbarPlacement = TASKBAR_ON_BOTTOM;
        }


        KillTimer(m_hWnd, IDT_DISAPPEARING);
        SetTimer(m_hWnd, IDT_APPEARING, 1, nullptr);
    }
    else
    {
        KillTimer(m_hWnd, IDT_APPEARING);

        if (bTaskbarOnRight)
            m_nCurrentPos.cx = m_rcDesktop.right - m_sMaxSize.cx;
        else if (bTaskbarOnLeft)
            m_nCurrentPos.cx = m_rcDesktop.left;
        else if (bTaskBarOnTop)
            m_nCurrentPos.cy = m_rcDesktop.top;
        else //if (bTaskbarOnBottom)
            m_nCurrentPos.cy = m_rcDesktop.bottom - m_nCurrentSize.cy;

        SetTimer(m_hWnd, IDT_DISAPPEARING, 1, NULL);
    }
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
LRESULT __OnTimer(HWND hWnd, UINT nIDEvent)
{
    int m_nIncrement = 20;
    if (nIDEvent == IDT_APPEARING)
    {
        switch (m_nTaskbarPlacement)
        {
        case TASKBAR_ON_BOTTOM:
            if (m_nCurrentPos.cy > (m_rcDesktop.bottom - m_sMaxSize.cy))
            {
                m_nCurrentPos.cy -= m_nIncrement;
                m_nCurrentSize.cy = m_rcDesktop.bottom - m_nCurrentPos.cy;
            }
            else
                KillTimer(hWnd, IDT_APPEARING);

            break;
        }

        SetFocus(hWnd);
        SetWindowPos(hWnd, HWND_TOPMOST, m_nCurrentPos.cx, m_nCurrentPos.cy, m_sMaxSize.cx, m_nCurrentSize.cy, SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);

    }
    else if (nIDEvent == IDT_DISAPPEARING)
    {
        switch (m_nTaskbarPlacement)
        {
        case TASKBAR_ON_BOTTOM:
            if (m_nCurrentPos.cy < m_rcDesktop.bottom)
            {
                m_nCurrentPos.cy += m_nIncrement;
                m_nCurrentSize.cy = m_rcDesktop.bottom - m_nCurrentPos.cy;
            }
            else
            {
                KillTimer(hWnd, IDT_DISAPPEARING);
                MoveWindow(m_hWnd, 0, 0, 0, 0, FALSE);
                ShowWindow(m_hWnd, SW_HIDE);
            }
            break;
        }

        SetWindowPos(hWnd, HWND_TOPMOST, m_nCurrentPos.cx, m_nCurrentPos.cy, m_sMaxSize.cx, m_nCurrentSize.cy, SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
    }

    return true;
}
Last edited on
Topic archived. No new replies allowed.