home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmBezier
- BorderStyle = 1 'Fixed Single
- Caption = "Bezier Curves Example"
- ClientHeight = 4380
- ClientLeft = 1140
- ClientTop = 1515
- ClientWidth = 6720
- LinkTopic = "Form1"
- MaxButton = 0 'False
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 4380
- ScaleWidth = 6720
- Begin VB.PictureBox Out
- BackColor = &H00FFFFFF&
- ClipControls = 0 'False
- DrawMode = 7 'Invert
- FillStyle = 0 'Solid
- Height = 4275
- Left = 0
- ScaleHeight = 283
- ScaleMode = 3 'Pixel
- ScaleWidth = 443
- TabIndex = 0
- Top = 60
- Width = 6675
- End
- Attribute VB_Name = "frmBezier"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- ' Copyright
- 1997 by Desaware Inc. All Rights Reserved
- Dim Points(3) As POINTAPI
- Dim Rects(3) As RECT
- Dim dl&
- Dim curPt%
- Dim fDragging%
- Const PT_START = 0
- Const PT_C1 = 1
- Const PT_C2 = 2
- Const PT_END = 3
- '**********************************
- '** Type Definitions:
- #If Win32 Then
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Private Type POINTAPI
- X As Long
- Y As Long
- End Type
- #End If 'WIN32 Types
- '**********************************
- '** Function Declarations:
- #If Win32 Then
- Private Declare Function PolyBezier& Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long)
- Private Declare Function PolyBezierTo& Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cCount As Long)
- Private Declare Function Rectangle& Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long)
- Private Declare Function SaveDC& Lib "gdi32" (ByVal hdc As Long)
- Private Declare Function RestoreDC& Lib "gdi32" (ByVal hdc As Long, ByVal nSavedDC As Long)
- Private Declare Function PtInRect& Lib "user32" (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long)
- Private Declare Function SetRect& Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long)
- #End If 'WIN32
- Private Sub Form_Load()
- SetPoint Points(PT_START), 100, 140
- SetPoint Points(PT_C1), 50, 80
- SetPoint Points(PT_C2), 350, 200
- SetPoint Points(PT_END), 300, 140
- SetPtRect PT_START
- SetPtRect PT_C1
- SetPtRect PT_C2
- SetPtRect PT_END
- End Sub
- Private Sub Out_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim fAny%, i%
- If Button And vbRightButton Then
- Form_Load
- Out.Refresh
- Exit Sub
- End If
- For i% = 0 To 3
- If PtInRect(Rects(i%), X, Y) Then
- curPt = i%
- fAny% = True
- fDragging% = True
- Exit For
- End If
- Next i%
- End Sub
- Private Sub Out_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim i%
- If Not fDragging% Then Exit Sub
- Out.ForeColor = (Not (QBColor(8)) And &HFFFFFF)
- dl& = PolyBezier(Out.hdc, Points(0), 4)
- Out.ForeColor = QBColor(10)
- Out.DrawStyle = 2 'Dot
- Out.Line (Points(PT_C1).X, Points(PT_C1).Y)-(Points(PT_START).X, Points(PT_START).Y)
- Out.Line (Points(PT_C2).X, Points(PT_C2).Y)-(Points(PT_END).X, Points(PT_END).Y)
- Out.DrawStyle = 0
- SetPoint Points(curPt), X, Y
- Out.ForeColor = (Not (QBColor(8)) And &HFFFFFF)
- dl& = PolyBezier(Out.hdc, Points(0), 4)
- Out.ForeColor = QBColor(10)
- Out.DrawStyle = 2 'Dot
- Out.Line (Points(PT_C1).X, Points(PT_C1).Y)-(Points(PT_START).X, Points(PT_START).Y)
- Out.Line (Points(PT_C2).X, Points(PT_C2).Y)-(Points(PT_END).X, Points(PT_END).Y)
- Out.DrawStyle = 0
- For i% = 0 To 3
- Out.ForeColor = QBColor(IIf(i% = 0 Or i% = 3, 12, 10))
- Out.FillColor = QBColor(IIf(i% = 0 Or i% = 3, 12, 10))
- DrawRect Out.hdc, Rects(i%)
- If i% = curPt Then
- SetPtRect curPt
- End If
- DrawRect Out.hdc, Rects(i%)
- Next i%
- End Sub
- Private Sub Out_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If fDragging% Then
- SetPoint Points(curPt), X, Y
- SetPtRect curPt
- fDragging% = False
- End If
- End Sub
- Private Sub Out_Paint()
- Out.ForeColor = (Not (QBColor(8)) And &HFFFFFF)
- ' Out.ForeColor = QBColor(8)
- dl& = PolyBezier(Out.hdc, Points(0), 4)
- Out.ForeColor = QBColor(12)
- Out.FillColor = QBColor(12)
- DrawRect Out.hdc, Rects(PT_START)
- DrawRect Out.hdc, Rects(PT_END)
- Out.ForeColor = QBColor(10)
- Out.FillColor = QBColor(10)
- DrawRect Out.hdc, Rects(PT_C1)
- DrawRect Out.hdc, Rects(PT_C2)
- Out.DrawStyle = 2 'Dot
- Out.ForeColor = QBColor(10)
- Out.Line (Points(PT_C1).X, Points(PT_C1).Y)-(Points(PT_START).X, Points(PT_START).Y)
- Out.Line (Points(PT_C2).X, Points(PT_C2).Y)-(Points(PT_END).X, Points(PT_END).Y)
- Out.DrawStyle = 0
- End Sub
- Private Sub SetPoint(myPt As POINTAPI, ByVal X As Long, ByVal Y As Long)
- myPt.X = X
- myPt.Y = Y
- End Sub
- Private Sub SetPtRect(ByVal Index As Integer)
- Rects(Index).Left = Points(Index).X - 3
- Rects(Index).Top = Points(Index).Y - 3
- Rects(Index).Right = Rects(Index).Left + 6
- Rects(Index).Bottom = Rects(Index).Top + 6
- ' dl& = SetRect(Rects(Index), Points(Index).X - 3, Points(Index).Y - 3, Rects(Index).Left + 6, Rects(Index).Top + 6)
- End Sub
- Private Sub DrawRect(ByVal hdc As Long, myRect As RECT)
- Out.Line (myRect.Left, myRect.Top)-(myRect.Right, myRect.Bottom), , BF
- End Sub
-