不要拿SetBkColor,SetBkMode设置整个窗口的背景色啦

来源:互联网 发布:cnzz统计js调用 编辑:IT博客网 时间:2020/02/18 03:56
不要拿SetBkColor,SetBkMode设置整个窗口的背景色啦!!
SetBkColor的作用范围
根据目前的经验,setBkColor只在两个地方好用: 
1.填充空隙(Gaps):此处空隙,指的是点式画笔或虚线画笔之间的空隙。参见CreatePen。
空隙还可以指阴影画刷的空隙。参见,CreateHatchBrush
2.文本输出TextOut(),DrawText();
并且SetColor设置一次会对此次绘画的所有“填充空隙”“文本输出”都有效。
PS:
如果要填充背景,还是用画刷吧。FillRect()等函数吧。
代码:
case WM_CREATE://m_brush = CreateSolidBrush(RGB(255, 255, 255)); // color white brush m_brush = CreateHatchBrush (HS_BDIAGONAL,RGB (255, 255, 0)) ;        return 0 ;case WM_PAINT:        hdc = BeginPaint (hwnd, &ps) ;               GetClientRect (hwnd, &rect) ;        SetBkColor(hdc,0X0000FF);  //1.用m_brush填充矩形FillRect(hdc, &rect2,m_brush);//2.用虚线画笔画一条直线hPen= CreatePen(PS_DASH, 1, RGB(0, 255, 0));hOldPen = SelectObject(hdc,hPen);        ptLeftTop.x = 10;ptLeftTop.y = 10;        MoveToEx(hdc,ptLeftTop.x,ptLeftTop.y,NULL);ptLeftTop.x = 100;ptLeftTop.y = 100;        LineTo(hdc,ptLeftTop.x,ptLeftTop.y);        SelectObject(hdc,hOldPen);        DeleteObject(hPen);        //3.写文本DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,        DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;                 EndPaint (hwnd, &ps) ;        return 0 ;

效果:

以下摘抄自MSDN:

This function fills the gaps between styled lines (CreatePen的第一个参数PenStyle)drawn using a pen created by the CreatePen function; it does not fill the gaps between styled lines drawn using a pen created by theExtCreatePen function. TheSetBKColor function also sets the background colors for TextOut andExtTextOut.

If the background mode is OPAQUE, the background color is used to fill gaps between styled lines, gaps between hatched lines in brushes, and character cells. The background color is also used when converting bitmaps from color to monochrome and vice versa. 

The SetBkMode function affects the line styles for lines drawn using a pen created by theCreatePen function.SetBkMode does not affect lines drawn using a pen created by theExtCreatePen function.

The iBkMode parameter can also be set to driver-specific values. GDI passes such values to the device driver and otherwise ignores them.

reference:
《windows程序设计》5.3.7填充空隙


0 0
原创粉丝点击