图形界面:DrawFocusRect-等待IT巨人 [英] Graphic Interface:DrawFocusRect - waiting for IT-Giant

查看:73
本文介绍了图形界面:DrawFocusRect-等待IT巨人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题:众所周知,我们可以使用"DrawFocusRect"例程在窗体的画布上绘制虚线矩形.我想知道它是如何工作的.
通常,我们通过将笔的模式设置为"Xor"或"NotXor"来绘制橡胶矩形(可以在鼠标移动时调整大小),然后用这支笔绘制直线矩形,但是这种模式有一个缺点,那就是仅适用于纯色底色形式,或者当底色的底画布是彩色图片时,这种方式将失败.

但是例程"DrawFocusRect()"喜欢在窗体的画布上方绘制虚线矩形,并且不会影响背景色.
它是如何工作的?能否在调用此例程之前将其笔或画笔属性设置为模式,样式,颜色等?

QQQ给出任何答案或建议...

解决方案

DrawFocusRect 不使用XOR.
它将像素的副本复制为4个位图(4个矩形边,每个像素宽度或高度)将虚线绘制为带有黑色前景和白色背景的"PAINT",并-恢复- blits 已保存的位图保留在其原始位置.

它只是保存/绘制/还原.

XOR的概念是不同的:由于A XOR(A XOR B)== B等于A,所以第一次绘制会产生图片的修改(通常是颜色反转"),并在第二次绘制时将其还原.

您对XOR方法绝对正确;您需要将线条设置为图片的顶部,并设置两种颜色(如黑色和白色).

请参阅本手册,详细了解GDI方法: http://www.codeguru.com/cpp /gm/gdi/article.php/c151 [ ^ ].

有一种更好的动画"方法用于显示选择(尽管不是键盘焦点),称为行进蚂蚁".我看到了许多不错的.NET示例,但不幸的是,从未在本机Windows(不受管理)中看到过.

您不应使用XOR模式,而应使用常规的不透明模式.您可能不仅想绘制破折号,还需要使用黑色和白色两种颜色绘制它们之间的间隙.这就是重点:背景可能太白而使白色笔触清晰可见,或者黑了而对黑色笔触黑色,因此您需要两种真正对比的颜色(将其中一种与另一种进行XOR运算以确保它们具有对比度) ;两种颜色的笔画交替出现.

—SA


First Q: As we know, we can use the "DrawFocusRect" routine to draw a dotted line-rect "on" a form''s canvas. I want to know how does it work.
Usually, we draw rubber rect(which can be resized while mouse moving) via setting the pen''s mode to "Xor" or "NotXor" and then draw a line-rect with this pen, but this pattern takes an disadvantage, it only works in pure-color-back form or rather, when the form''s back canvas was a colorful picture, this way would fail.

But the routine "DrawFocusRect()" likes to draw dotted line-rect above a form''s canvas and do not impact the back color.
How does it work? And can we set its pen or brush attributes as mode,style,color etc before call this routine?

QQQ for any answer or advice...

解决方案

DrawFocusRect doesn''t use XOR.
It makes a copy of the pixels into 4 bitmaps (the 4 rectangle sides, each one pixel width or height) draws the dotted line as a "PAINT" with black foreground and white background,and - to restore - blits the saved bitmaps in their original positions.

It just saves / draw / restore.

The idea of XOR is different: since A XOR (A XOR B) == B whatever A, a first draw produce a modification of the picture (typically a "color inversion") that is reverted back with a second draw.


You''re absolutely right about XOR methods; you need to make the lines on top of your picture, with both colors set by you (like black and white).

Please see this manual for detailed explanation of GDI methods: http://www.codeguru.com/cpp/g-m/gdi/article.php/c151[^].

There is much better "animated" method used to show selection (not keyboard focus though) called "marching ants". I saw many good .NET samples, but unfortunately never for native Windows (unmanaged).

You should not use XOR mode, use regular opaque mode. You may want to paint not just the dash strokes but also the gaps between them using two colors, like black and white. This is the whole point: the background could be "too white" to make white strokes well visible or "to black" for black strokes, so you need two really contrasting color (XOR one of them from another to make sure they are contrast); the stroke of both colors coming alternatively in sequence.

—SA


这篇关于图形界面:DrawFocusRect-等待IT巨人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆