HOWTO: Implement Filled Geometric Lines In Windows 95 & 98

ID: Q230057


The information in this article applies to:
  • Microsoft Windows 98, included with:
    • Microsoft Win32 Application Programming Interface (API)


SUMMARY

In Windows 95 and 98 using ExtCreatePen, you cannot create a (wide) geometric pen that is filled by a brush pattern. As a result, Windows 95 and 98 geometric pens (the PS_GEOMETRIC style) are limited to the BS_SOLID brush style specified in the LOGBRUSH structure passed to ExtCreatePen.


MORE INFORMATION

However, to achieve a similar effect you can use paths such as the following code demonstrates.




/* Demonstrates patterned pen effect using paths. */ 
/* This is a Demo only...no error handling. */ 
void DemoPatternPen(HDC hDC, HBITMAP hBitmap, int iWidth, 
int x1, int y1, int x2, int y2)
{
	HBRUSH hBrush, hOldBrush;
	LOGBRUSH lb;
	HPEN hPen, hOldPen;
	BOOL bFlag;

	/* Create and select a brush... */ 
	hBrush = CreatePatternBrush(hBitmap);
	hOldBrush = SelectObject(hDC, hBrush);

	/* Create and select a wide geometric pen... */ 
	ZeroMemory(&lb, sizeof(LOGBRUSH));
	lb.lbStyle = BS_SOLID;
	lb.lbColor = RGB(0,0,0);
	hPen = ExtCreatePen(PS_GEOMETRIC, iWidth, &lb, 0, NULL);
	hOldPen = SelectObject(hDC, hPen);

	/* Create a path containing the line(s) we want to fill... */ 
	bFlag = BeginPath(hDC);
	MoveToEx(hDC, x1, y1, NULL);
	LineTo(hDC, x2, y2);
	bFlag = EndPath(hDC);

	/* Fill (widened, pen-width) path with our brush... */ 
	bFlag = WidenPath(hDC);
	bFlag = FillPath(hDC);

	/* Cleanup... */ 
	SelectObject(hDC, hOldBrush);
	DeleteObject(hBrush);
	SelectObject(hDC, hOldPen);
	DeleteObject(hPen);

	return;
} 

Additional query words: BS_PATTERN

Keywords : kbGDI kbPen
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: May 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.