开发者

How do you call CMFCRibbonProgressBar methods from a different thread?

I have a simple CMFCRibbonProgressBar and a thread that calls SetPos(value, TRUE) on it when a lengthy operation progresses. The problem is that in debug mode it asserts in wincore.cpp with this:

    CHandleMap* pMap = afxMapHWND();
    ASSERT(pMap != NULL);

I understand by the comments in that file that I shou开发者_运维知识库ldn't be calling it from a different thread because it could potentially be dangerous. My question then is how do you get a thread to update the position of the progress bar ? I'm very tempted to just ignore that assert and continue in release mode but that's pretty evil...

Any suggestions ?


Ok, someone commented very briefly on the question and they had the right answer. I don't know why they retracted their comment :/

I ended up storing a CWnd* pointer in the CMFCRibbonProgressBar derived class, and whenever I call the "SetAmountCompleted" method from the worker thread, I use the CWnd to send a custom message with a pointer to the derived class in the WPARAM. The CWnd that receives the message then extracts the pointer and calls Update method which will redraw the progress bar.

It's complicated, it's ugly, it's MFC. Phew.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜