|
-
Feb 27th, 2002, 10:02 PM
#1
Thread Starter
Frenzied Member
Create dashed rectangle with GDI
Hi,
I'm creating a dashed rectangle using the following code:
Code:
Dim hPen As Long, hOldPen As Long
Dim hBrush As Long, hOldBrush As Long
Dim hScreenDC As Long, nDrawMode As Long
'-- Get DC of entire screen in order to draw on top of all controls
hScreenDC = GetDC(0)
'-- Select GDI object
hPen = CreatePen(PS_DASH, 0, RGB(0, 0, 0))
hOldPen = SelectObject(hScreenDC, hPen)
'-- Draw rectangle
Rectangle hScreenDC, miSelectX1, miSelectY1, miSelectX2, miSelectY2
'-- Restore DC
SelectObject hScreenDC, hOldPen
ReleaseDC 0, hScreenDC
'-- Delete GDI objects
DeleteObject hPen
However, it's creating a white background and the dash lengths are too long. Take a look at the first rectangle below.
What I want it to look like is the second rectangle where the dashes are shorter and the background is transparent to show the underlying form color.
Any help would be appreciated..
Dan
-
Feb 28th, 2002, 03:54 AM
#2
Frenzied Member
Instead use the DrawFocusRect API:
Code:
Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Long, lpRect As RECT) As Long
HTH,
Duncan
-
Feb 28th, 2002, 04:05 AM
#3
Or use PS_DOT to get a dotted line, and create a transparent brush and select it into the dc.
Private Const PS_DOT = 2
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|