生活的天平本不平衡,只有通过努力改变其偏向。

UpdateData引发的API使用的思考

2008-08-03

在CSDN上看到一网友问起一题目,关于UpdateData函数无效的情况。出错代码如下:

1
2
3
4
5
6
7
while(a < 10)
{
a++;
m_edit=a;
UpdateData(FALSE);
Sleep(50);
}

数据肯定已经更新了,只不过没有显示出来,所以看不到变化,只能看到最终的结果9.只需在UpdateData后加入UpdateWindow即可更新窗口。问题已经决,应该回帖到此应该结束。我又想了一下,既然是更新窗口,那发送WM_PAINT消息让窗口重绘,应该也能达到效果,但是失败了。我冷静一下一分析,对呀,在循环和Sleep下,消息队列已经阻塞了。发送WM_PAINT也是无效的。

但是为什么UpdateWindow是可以呢?我猜测应该是UpdateWindow不是通过发送WM_PAINT消息来达到更新窗口的,它是直接调用WM_PAINT消息处理函数来进行更新窗口。可惜我的逆向的功夫还不到家,没有将UpdateWindow函数逆出来,郁闷,只能是个猜测。大家可以看看这篇文章,也应该可以验证我的猜测http://www.winehq.org/pipermail/wine-devel/2004-September/029825.html

MSDN是描述的:

The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window’s update region is not empty. The function sends aWM_PAINTmessage directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent.

作者:lonkil | 分类目录:编程开发 | 标签:

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>