📄 subject_44891.htm
字号:
<p>
序号:44891 发表者:vcinside 发表日期:2003-06-24 15:12:00
<br>主题:tnnd:这怎么解释的通啊?
<br>内容:The most common method for obtaining a device context handle and then releasing it involves using the BeginPaint and EndPaint calls when processing the WM_PAINT message: <BR><BR><BR>hdc = BeginPaint (hwnd, &ps) ;<BR>[other program lines]<BR>EndPaint (hwnd, &ps) ;<BR><BR>The variable ps is a structure of type PAINTSTRUCT. The hdc field of this structure is the same handle to the device context that BeginPaint returns. The PAINSTRUCT structure also contains a RECT (rectangle) structure named rcPaint that defines a rectangle encompassing the invalid region of the window's client area. With the device context handle obtained from BeginPaint you can draw only within this region. The BeginPaint call also validates this region<BR><BR>*******************************************<BR>since i could only draw in invalid region of the windows's client area,<BR>but "The BeginPaint call also validates this region" validate the area,<BR>when i do my drawing,there are no invalidate area,i can draw at any places<BR>so i think the pragraph is inconsistency.(from windows five editon )<BR>who has good idea???<BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:xiongli 回复日期:2003-06-24 17:26:13
<br>内容:The BeginPaint function automatically sets the clipping region of the device context to exclude any area outside the update region. The update region is set by the InvalidateRect or InvalidateRgn function and by the system after sizing, moving, creating, scrolling, or any other operation that affects the client area. If the update region is marked for erasing, BeginPaint sends a WM_ERASEBKGND message to the window. <BR><BR>An application should not call BeginPaint except in response to a WM_PAINT message. Each call to BeginPaint must have a corresponding call to the EndPaint function. <BR><BR>If the caret is in the area to be painted, BeginPaint automatically hides the caret to prevent it from being erased. <BR><BR>If the window's class has a background brush, BeginPaint uses that brush to erase the background of the update region before returning. <BR><BR><BR>我理解是BeginPaint返回无效区域,同时把这个区域的属性设定成为有效。<BR>这个很容易证明。<BR>你连续两次call BeginPaint,然后分别检查ps里面的无效区域,发现第二次一定是0,说明第一次就让他有效了。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:vcinside 回复日期:2003-06-24 18:18:15
<br>内容:xilong:<BR>thanks a lot ,but i can'understand you<BR><BR>now ,i understand the question like this<BR><BR>all i list above is true,it's not inconsistency.<BR>the problem is how to understand Windows's working.<BR><BR>when i call the funtion BeginPaint,the function do two things<BR>first,it define a rect reagion,we must draw in the reagion anyway when<BR>i use beginpain other than getdc getwindowdc...<BR><BR>second,the function make the reagion to be validate.<BR><BR>as a conclusion<BR>first :when we draw some thing, we don't consider weather the<BR>region is validate or not,that is :if i draw in a invalidate region,the <BR>drawing must be clip and not be displayed ,if i draw in a validate region<BR>it works just like i want <BR><BR>second:the begainpaint's two step working has no relation<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-06-25 19:19:15
<br>内容:我想应该这样理解<BR>首先,无效区域的设定有很多方式。<BR>当你在屏幕上画图以后,当这一部分被其他窗口覆盖,窗口移动,最大化最小化等等操作后,原来它所占据的拿一块地方需要重新作图,需要重新作图的地方就是无效的地方,也就叫做无效区域。这块无效区域是系统计算出来的。<BR>同时,当用户作对应的操作,比如说在画图里面拉一条直线,这个时候屏幕也需要重绘,也会产生无效区域。但是这个无效区域就需要你用代码自己计算出来,计算出来后用InvalideRect()通知系统。<BR>InvalidateRect同时产生wm_paint消息。当屏幕移动等时候,系统也会给你的程序发送wm_paint消息。当你用beginpaint相应wm_paint消息的时候,可以通过beninpaint来获取当前那些区域是无效的。同时,在调用beginpaint以后,系统认为你已经准备对这块区域操作,所以他就把前面的那些本来的无效区域设定清除。<BR>对于你说的<BR>if i draw in a invalidate region,the <BR>drawing must be clip and not be displayed <BR>我认为你说反了<BR>无论你如何画图,最后得到update的是无效区域,而不是有效区域。无效的意思是这块区域过期了,需要重绘,你可以自己写一个小程序证明。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:vcinside 回复日期:2003-06-25 21:40:07
<br>内容:多谢你的热心的回复,真的觉得你很喜欢探讨问题。<BR>现在我对这个问题不是十分的清楚,所以讨论起来<BR>难免有失误。<BR>我这么看:<BR>我说了,首先,当我begainpaint的时候,这个函数<BR>作了两件事,第一,它定义了一个区域,应该是个<BR>剪切区域,无论如何,此时我只能在这里面画图,<BR>这个问题没的说,我想你也同意,至于这个区域是<BR>什么形式,是剪切区域还是别的rect区域,我不敢肯定<BR>第二,这个函数使这个区域有效。<BR>以上两点,是我看一本e文书上的话,我相信我没有译错!!<BR><BR>下面我就把这两点的工作分析如下:<BR>首先我认为,他们没有任何关系,我们可以看成在一个函数<BR>里面的两个功能,如果的第二个功能不实现,也就是没有<BR>那我虽然可以在这个区域画图,但是不能够显现,因为这个<BR>区域无效。所以我理解windows这样用begainpaint函数,<BR>他把无效的区域先保存起来,第一步工作,规定我们只能在<BR>这里面画图,至于可见不可见他不管<BR>然后她把这块区域变为有效,这样,我们在这里画图的时候<BR>就可见了。<BR><BR>我理解的可能不对,但我觉得我能解释的同阿<BR><BR>分享一句话,去编程,就是去理解。<BR>上次把你的名字打错了,很对不起。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-06-25 22:26:42
<br>内容:/*<BR>当我begainpaint的时候,这个函数<BR>作了两件事,第一,它定义了一个区域,应该是个<BR>剪切区域,<BR>*/<BR>他不是定义了区域。注意他需要你传递进去一个地址。他是得到当前的无效区域。<BR>无效区域的定义不是通过beginpaint定义的,而是通过InvalidataRect()或者是系统定义的,beginpaint不过是得到这个区域而已。<BR><BR>/*<BR>第二,这个函数使这个区域有效<BR>*/<BR>对的<BR><BR>系统并没有规定你只能在里面画图。其实你可以在任何地方画图。你其实还可以自己设定任意无效区域。无效区域的意思是系统只更新这一部分。更新后就变成有效区域。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-06-25 22:27:12
<br>内容:你自己写几个小程序验证一下就可以了
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:vcinside 回复日期:2003-06-26 08:12:38
<br>内容:*////////////////////////<BR>当我begainpaint的时候,这个函数<BR>作了两件事,第一,它定义了一个区域,应该是个<BR>剪切区域,<BR>*/<BR>他不是定义了区域。注意他需要你传递进去一个地址。他是得到当前的无效区域。<BR>无效区域的定义不是通过beginpaint定义的,而是通过InvalidataRect()或者是系统定义的,beginpaint不过是得到这个区域而已。<BR>/////////////////////////////////////<BR>同意,我觉得你说的很精确,这么说很对<BR><BR>///////////<BR>系统并没有规定你只能在里面画图。其实你可以在任何地方画图<BR>////////////////<BR>这句话值得商榷,我们不能在无效的区域或是剪切的区域外画图<BR>在无效的区域画图会是什么样呢?难道对WM_PANIT消息使用GETDC<BR>来获得设备来处理么?<BR>不能再剪切区域外画图很明显<BR><BR><BR><BR><BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-06-26 12:00:45
<br>内容:注意BeginPaint跟GetDC的差别<BR>/*<BR>You use the GetDC function to carry out drawing that must occur instantly rather than when a WM_PAINT message is processing. Such drawing is usually in response to an action by the user, such as making a selection or drawing with the mouse. In such cases, the user should receive instant feedback and must not be forced to stop selecting or drawing in order for the application to display the result. The following sections show how to use GetDC to draw in a window: <BR>*/<BR>BeginPaint是用来专门相应wm_paint消息的,只有他才存在有效区域无效区域的概念。<BR>你可以在无效区域外面画图<BR>但是因为他是在外面的,所以系统就不会更新哪一部分,就等于你没有画<BR>正是因为你用画图函数的时候并不知道那些是无效区域,所以系统才有必要给beginpaint提供一个功能,让他返回无效区域的大小。<BR>同时beginpaint可以回发送WM_ERASEBKGND 消息擦除背景<BR><BR>GetDC是用来相应一个action的。不存在无效区域,就在你指定的地方画图。同时它永远都不会擦除背景,也不会擦除他没有画到的其他地方。<BR><BR>为什么要有这种类操作,考虑一个例子。<BR><BR>如果你有一个CView,你需要显示一些文字,同时在一个指定地方滚动显示多个图片,图片大小不一样。这个时候你就需要用beginpaint。因为图片大小不一样,如果用getdc,在显示小图片的时候大图片边缘得不到擦除,如果用beginpaint,设定整个图片显示区域,就可以正确显示。beginpaint跟wm_paint结合是用来显示窗口里面任何需要持久显示的东西。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-06-26 12:10:22
<br>内容:beginpaint比getdc多的功能就是可以选择自动擦除背景和定义无效区域,缺点是只有在相应wm_paint消息的时候才保证正常工作.<BR>//An application should not call BeginPaint except in response to a WM_PAINT message
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -