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 ;
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.