开发者

SetTimer dependent on WS_EX_COMPOSITED?

Strange one here: I've got a window created with an extended style of WS_EX_OVERLAPPEDWINDOW | WS_EX_COMPOSITED. On WM_SIZE I create (or reset) a timer using SetTimer, which calls a draw function after a 100 ms pause in resizing (Helps smooth resize.)

That's working just fine, but I just noticed that if I remove the WS_EX_COMPOSITIED style, suddenly my timer stops working! Huh? I've confirmed that SetTimer is being called, but I never hit the callback function. Put the style back in, and everything is happy again.

I have a feeling that I'm missing somethi开发者_开发知识库ng here. Has anyone else experienced this?

Windows 7, 64 bit (if it matters.)


I have Win 7 x64 and looks like it works for me. Anyway, you can post here some small snippet, maybe it will share some light to you problem.

class CMainWindow : public CWindowImpl<CMainWindow, CWindow, CFrameWinTraits>
{
public:
    DECLARE_WND_SUPERCLASS(_T("CMainWindow"), CWindow::GetWndClassName())

    BEGIN_MSG_MAP(CMainWindow)
        MSG_WM_SIZE(OnSize)
        MSG_WM_TIMER(OnTimer)
    END_MSG_MAP();

    VOID OnSize(UINT, CSize)
    {
        m_timerId = SetTimer((UINT_PTR)this, 100);
    }

    VOID OnTimer(UINT_PTR)
    {
        KillTimer(m_timerId);
        CDCHandle dc = GetDC();
        Draw(dc);
    }

    VOID Draw(HDC hDC)
    {
        CDCHandle dc(hDC);
        CRect objClientRect;
        GetClientRect(objClientRect);
        dc.FillSolidRect(objClientRect, RGB(0, 255, 0));
    }

private:
    UINT_PTR m_timerId;
};

int main(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{   
    _Module.Init(0, hInstance, 0);

    CMainWindow wnd;
    wnd.Create(NULL, CWindow::rcDefault, _T("Hello world"));
    wnd.ShowWindow(SW_SHOW);

    CMessageLoop loop;

    _Module.AddMessageLoop(&loop);

    int res = loop.Run();

    _Module.Term();
    return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜