NULL_PEN、 NULL_BRUSH 和 HOLLOW_BRUSH 的使用

NULL_PEN、 NULL_BRUSH 和 HOLLOW_BRUSH 的使用

Use of NULL_PEN, NULL_BRUSH, and HOLLOW_BRUSH

http://support.microsoft.com/kb/66532/en-us/
GDI contains several "NULL" stock objects: NULL_BRUSH, HOLLOW_BRUSH, and NULL_PEN. These objects are defined in WINDOWS.H (16-bit SDK) or in WINGDI.H (32-bit SDK). These header files define HOLLOW_BRUSH as NULL_BRUSH, so they are the same objects. 

Note that NULL_BRUSH and NULL_PEN are NOT identical to the value NULL. The value NULL is defined as 0 (zero) in WINDOWS.H and is not a valid stock object. 

Many GDI functions use the current brush to fill interiors and the current pen to draw lines. In some cases, an application may not want to modify the areas normally affected by the pen or brush. Selecting a NULL_PEN or NULL_BRUSH into the device context tells GDI not to modify the normally affected areas. In short, "NULL_" objects do not draw anything. 

For example, the Rectangle() function uses the current brush to fill the interior of the rectangle and the current pen to draw the border. If NULL_PEN is selected into the device context, no border is drawn. If NULL_BRUSH or HOLLOW_BRUSH is selected, the interior of the rectangle is not painted. If both NULL_PEN and NULL_BRUSH are selected, the rectangle will not be drawn.
原文翻译
请注意 NULL_BRUSH 和 NULL_PEN 不为 NULL 的值相同。值为 NULL 被定义在 WINDOWS.H 中为 0 (零) 他们并不是有效的常用对象。

许多 GDI 函数使用当前画笔填充内部和当前笔来绘制直线。在某些情况下,应用程序可能不需要修改通常由钢笔或画笔受影响的区域。选择到设备上下文的 NULL_PEN 或 NULL_BRUSH 通知 GDI 不能修改通常受影响的区域。简单地说,"NULL_"的对象不显示任何内容。

例如,Rectangle() 函数使用当前画笔填充矩形和当前笔来绘制边框的内部。如果 NULL_PEN 被选入设备上下文中,不加边框。如果选择 NULL_BRUSH 或 HOLLOW_BRUSH,则不绘制的矩形的内部。如果选择了 NULL_PEN 和 NULL_BRUSH,将不绘制矩形。

NULL_PEN的作用:事实上这个有时候很有用,比如你要画一个不带边框的红色圆形,那么你可以选入一个红色的画刷,然后使用NULL_PEN来画。
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
NULL_BRUSH是一个宏,表示空画刷,在这里等同于HOLLOW_BRUSH,两个可以通用。HOLLOW,中文意思即为“空”。所以,这句代码,是创建了一个画刷类(CBrush)的指针变量,并在定义之时,为其创建了一个空画刷。
通常,可以在为静态文本控件、编辑框控件、按钮控件等控件设置透明时,使用这句代码。
 
   
 
   

你可能感兴趣的:(null)