how do i change colour of my region?

andreww
03-08-2002, 03:04 AM
i want to know how to change my region from black to a different colour

heres the code:

Private Type COORD
x As Long
y As Long
End Type
Dim mouses As COORD
Dim inside
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Const ALTERNATE = 2
Const WINDING = 4
Const BLACKBRUSH = 4
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long

Private Sub Command1_Click()
NumCoords = 3
Me.ScaleMode = vbPixels
poly(1).x = 100
poly(1).y = 100
poly(2).x = Form1.ScaleWidth / 4 + 100
poly(2).y = 3 * Form1.ScaleHeight / 4 + 100
poly(3).x = 3 * Form1.ScaleWidth / 4 + 100
poly(3).y = 3 * Form1.ScaleHeight / 4 + 100
Polygon Me.hdc, poly(1), NumCoords
hBrush = GetStockObject(BLACKBRUSH)
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
If PtInRegion(hRgn, 1, 1) <> 0 Then Me.Caption = "Inside"
DeleteObject hRgn
End Sub

Squirm
03-08-2002, 03:51 PM
You could use CreateSolidBrush API to make a solid-colour brush instead of using GetStockObject.

andreww
03-09-2002, 07:05 PM
squirm could you tell me what code to type in as i couldnt get it working

Squirm
03-10-2002, 12:10 PM
Option Explicit

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Sub Form_Paint()

'Declare variables
Dim hBrush As Long 'Used to store the solid brush
Dim hOldBrush As Long 'Used to store the old brush

'Create brush
hBrush = CreateSolidBrush(vbRed)

'Select it and store the old brush
hOldBrush = SelectObject(Me.hdc, hBrush)

'Do your draw commands here on Me.hdc
'you can use any hDC you want

'Select back the old brush
hBrush = SelectObject(hOldBrush)

'Delete the solid colour brush
DeleteObject hBrush

End Sub

andreww
03-10-2002, 09:22 PM
There now is a bit of a black border around the coloured region
heres the code.. and attached is a picture of what i mean

Private Type COORD
x As Long
y As Long
End Type
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long

Private Sub Command1_Click()
hBrush = CreateSolidBrush(vbRed)
NumCoords = 3
Me.ScaleMode = vbPixels
poly(1).x = 100
poly(1).y = 100
poly(2).x = 200
poly(2).y = 100
poly(3).x = 150
poly(3).y = 200
Polygon Me.hdc, poly(1), NumCoords
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
If PtInRegion(hRgn, 1, 1) <> 0 Then Me.Caption = "Inside"
DeleteObject hRgn
'DeleteObject hBrush
End Sub

andreww
03-10-2002, 10:16 PM
actually ive just worked that out by changing the forecolor

but is there a way of setting the colour without changing the forecolor?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum