⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_16883.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:16883 发表者:liuwenjun 发表日期:2002-10-05 14:24:10
<br>主题:如何将一条已画出的任意颜色的线擦除
<br>内容:我用GetDC()函数获得的CDC*在对话框上画了一条红色的直线,但不知如何将其删除。若为任意颜色的任意形状的线呢?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:Norton AntivVirus 回复日期:2002-10-05 14:30:43
<br>内容:Invalidate();
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2002-10-05 14:46:01
<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>
回复者:liuwenjun 回复日期:2002-10-05 16:57:14
<br>内容:下面是我最初的代码: <BR>&nbsp;&nbsp; CPen mypen1,mypen2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;mypen1.CreatePen(PS_SOLID,5,RGB(255,0,0));// 创建一个红色的实线笔<BR>&nbsp;&nbsp;&nbsp;&nbsp;mypen2.CreatePen(PS_SOLID,5,RGB(192,192,192));//创建一个底色的实线笔<BR>&nbsp;&nbsp;&nbsp;&nbsp;CPen *pOldPen1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;pOldPen1=pDC-&gt;SelectObject(&mypen1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;BeginPath();<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(nFlags)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(10,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(200,100);<BR>//用底色颜色的笔将前面的线重画,即相当于擦去<BR>//&nbsp;&nbsp;&nbsp;&nbsp; pDC-&gt;SelectObject(&mypen2);<BR>//&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(200,10);<BR>//&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(10,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(200,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(10,100);<BR>//用底色颜色的笔将前面的线重画,即相当于擦去<BR>//&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;SelectObject(&mypen2);<BR>//&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(10,10);<BR>//&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(200,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;nFlags=!nFlags;<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;CloseFigure();<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;EndPath();<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;StrokePath();//笔划路径<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;SelectObject(pOldPen1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CWnd::ReleaseDC(pDC);<BR>//后的代码是我想用底色线重画而擦除前面画的线写的代码,但结果是一条线都没有了,看了二位的留言我又试着将Invalidate();分别放在两句pDC-&gt;MoveTo之前(没带//后的代码运行),结果道是动画了,可是一闪一闪的,而不是象我预想的那样规则的交替出现两条线,请问,我应该怎样作呢?<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>
回复者:凯凯 回复日期:2002-10-05 17:36:37
<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>
回复者:liuwenjun 回复日期:2002-10-05 18:11:46
<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>
回复者:liuwenjun 回复日期:2002-10-05 19:27:25
<br>内容:我如果只在if{}中的pDC-&gt;MoveTo语句之前加上Invalidate();而在else{}中的pDC-&gt;MoveTo语句之前不加Invalidate();语句的话,if{}中的pDC-&gt;MoveTo(10,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(200,100);两句的执行结果就呈现规则间隔的动态显示,而else{}中的画线语句仍呈现不规则闪动的不完全的图象。而且若再在if{}中的画线语句后加上一句或若干句画线语句如:<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(100,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(100,10);等时,后加的这些语句执行结果仍为不规则闪动的不完全的图象。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:黄飚 回复日期:2002-10-05 20:11:07
<br>内容:CDC::SetROP2 <BR>int SetROP2( int nDrawMode );<BR><BR>Return Value<BR><BR>The previous drawing mode. <BR><BR>It can be any of the values given in the Windows SDK documentation. <BR><BR>Parameters<BR><BR>nDrawMode<BR><BR>Specifies the new drawing mode. It can be any of the following values: <BR><BR>R2_BLACK&nbsp;&nbsp; Pixel is always black.<BR><BR><BR>R2_WHITE&nbsp;&nbsp; Pixel is always white.<BR><BR><BR>R2_NOP&nbsp;&nbsp; Pixel remains unchanged.<BR><BR><BR>R2_NOT&nbsp;&nbsp; Pixel is the inverse of the screen color.<BR><BR><BR>R2_COPYPEN&nbsp;&nbsp; Pixel is the pen color.<BR><BR><BR>R2_NOTCOPYPEN&nbsp;&nbsp; Pixel is the inverse of the pen color.<BR><BR><BR>R2_MERGEPENNOT&nbsp;&nbsp; Pixel is a combination of the pen color and the inverse of the screen color (final pixel = (NOT screen pixel) OR pen).<BR><BR><BR>R2_MASKPENNOT&nbsp;&nbsp; Pixel is a combination of the colors common to both the pen and the inverse of the screen (final pixel = (NOT screen pixel) AND pen).<BR><BR><BR>R2_MERGENOTPEN&nbsp;&nbsp; Pixel is a combination of the screen color and the inverse of the pen color (final pixel = (NOT pen) OR screen pixel).<BR><BR><BR>R2_MASKNOTPEN&nbsp;&nbsp; Pixel is a combination of the colors common to both the screen and the inverse of the pen (final pixel = (NOT pen) AND screen pixel).<BR><BR><BR>R2_MERGEPEN&nbsp;&nbsp; Pixel is a combination of the pen color and the screen color (final pixel = pen OR screen pixel).<BR><BR><BR>R2_NOTMERGEPEN&nbsp;&nbsp; Pixel is the inverse of the R2_MERGEPEN color (final pixel = NOT(pen OR screen pixel)).<BR><BR><BR>R2_MASKPEN&nbsp;&nbsp; Pixel is a combination of the colors common to both the pen and the screen (final pixel = pen AND screen pixel).<BR><BR><BR>R2_NOTMASKPEN&nbsp;&nbsp; Pixel is the inverse of the R2_MASKPEN color (final pixel = NOT(pen AND screen pixel)).<BR><BR><BR>R2_XORPEN&nbsp;&nbsp; Pixel is a combination of the colors that are in the pen or in the screen, but not in both (final pixel = pen XOR screen pixel).<BR><BR><BR>R2_NOTXORPEN&nbsp;&nbsp; Pixel is the inverse of the R2_XORPEN color (final pixel = NOT(pen XOR screen pixel)). <BR>Remarks<BR><BR>Sets the current drawing mode. The drawing mode specifies how the colors of the pen and the interior of filled objects are combined with the color already on the display surface. <BR><BR>The drawing mode is for raster devices only; it does not apply to vector devices. Drawing modes are binary raster-operation codes representing all possible Boolean combinations of two variables, using the binary operators AND, OR, and XOR (exclusive OR), and the unary operation NOT.<BR><BR>CDC Overview |&nbsp;&nbsp;Class Members |&nbsp;&nbsp;Hierarchy Chart<BR><BR>See Also&nbsp;&nbsp; CDC::GetDeviceCaps, CDC::GetROP2,::SetROP2<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>
回复者:liuwenjun 回复日期:2002-10-06 19:59:08
<br>内容:谢谢各位的指教,我按黄飚朋友的指点,用CDC::SetROP2函数作了,代码如下:&nbsp;&nbsp;&nbsp;&nbsp;if(nFlags)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(10,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(10,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;SetROP2(R2_XORPEN);/////////<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(20,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(20,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}else{&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(20,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(20,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;SetROP2(R2_XORPEN);/////////<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;MoveTo(10,10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;LineTo(10,100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>一开始我想找Pixel is the screen color的参数,但未找到,我就将所有的参数全试了一遍,结果是:<BR>R2_BLACK:黑色,且无动画&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R2_WHITE:白色,且无动画<BR>R2_NOP:无线,无动画&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R2_NOT:淡黑色,动画<BR>R2_COPYPEN:红色,无动画<BR>R2_NOTCOPYPEN:兰色,无动画&nbsp;&nbsp;&nbsp;&nbsp;R2_MERGEPENNOT:红白间隔的动画<BR>R2_MASKPENNOT:黑红间隔的动画<BR>前边是R2_MERGEPENNOT,后边是R2_MASKPENNOT时,先出一条红线,再黑白交替动画<BR>R2_MERGENOTPEN:淡兰色,无动画&nbsp;&nbsp;&nbsp;&nbsp;R2_MASKNOTPEN:兰色,无动画<BR>R2_MERGEPEN:微红色,无动画&nbsp;&nbsp;&nbsp;&nbsp; R2_NOTMERGEPEN :黑兰交替动画<BR>R2_MASKPEN:深红色,无动画&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R2_NOTMASKPEN:蓝白交替动画<BR>R2_XORPEN:兰色,动画<BR>R2_NOTXORPEN :有些发黑的红色,动画<BR>我看最后两个R2_XORPEN和R2_NOTXORPEN虽然颜色不对,但实现了完全的动画,所以就用R2_XORPEN,为了得到鲜红色的线条,我就用 pen(RGB(x,y,z)) XOR screen pixel(RGB(192,192,192))=line(RGB(255,0,0)),得到x=212,y=62,z=62,结果改后确实出现了想要的鲜红色线条。<BR>但为什么一样的代码,不同的画图模式就会有的有动画有的无动画呢?我想虽然我勉强解决了现在这个问题,但还是有很多隐忧的,还是应该把他弄明白才对。<BR>由于我以前很少接触电脑,又没学C++就直接学VC了,其他电脑方面的知识也很少,所以知识结构有很多缺陷。但我不是个只想坐享其成的人,我周围很少有学VC的,就更不用说高手了,所以没人可以交流。苦学了好长时间,效果不大。以前上网也不方便,现在上网才接触到许多新观念。希望各位多加指点。回答我越详细越好,不然我可能不明白,那不就白费了您的苦心了吗?我想,以后还会有诸多不明之处要仰仗各位指教!<BR>
<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 + -