home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch08 / bezier.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  5.8 KB  |  163 lines

  1. VERSION 5.00
  2. Begin VB.Form frmBezier 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Bezier Curves Example"
  5.    ClientHeight    =   4380
  6.    ClientLeft      =   1140
  7.    ClientTop       =   1515
  8.    ClientWidth     =   6720
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    PaletteMode     =   1  'UseZOrder
  12.    ScaleHeight     =   4380
  13.    ScaleWidth      =   6720
  14.    Begin VB.PictureBox Out 
  15.       BackColor       =   &H00FFFFFF&
  16.       ClipControls    =   0   'False
  17.       DrawMode        =   7  'Invert
  18.       FillStyle       =   0  'Solid
  19.       Height          =   4275
  20.       Left            =   0
  21.       ScaleHeight     =   283
  22.       ScaleMode       =   3  'Pixel
  23.       ScaleWidth      =   443
  24.       TabIndex        =   0
  25.       Top             =   60
  26.       Width           =   6675
  27.    End
  28. Attribute VB_Name = "frmBezier"
  29. Attribute VB_GlobalNameSpace = False
  30. Attribute VB_Creatable = False
  31. Attribute VB_PredeclaredId = True
  32. Attribute VB_Exposed = False
  33. Option Explicit
  34. ' Copyright 
  35.  1997 by Desaware Inc. All Rights Reserved
  36. Dim Points(3) As POINTAPI
  37. Dim Rects(3) As RECT
  38. Dim dl&
  39. Dim curPt%
  40. Dim fDragging%
  41. Const PT_START = 0
  42. Const PT_C1 = 1
  43. Const PT_C2 = 2
  44. Const PT_END = 3
  45. '**********************************
  46. '**  Type Definitions:
  47. #If Win32 Then
  48. Private Type RECT
  49.         Left As Long
  50.         Top As Long
  51.         Right As Long
  52.         Bottom As Long
  53. End Type
  54. Private Type POINTAPI
  55.         X As Long
  56.         Y As Long
  57. End Type
  58. #End If 'WIN32 Types
  59. '**********************************
  60. '**  Function Declarations:
  61. #If Win32 Then
  62. Private Declare Function PolyBezier& Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long)
  63. Private Declare Function PolyBezierTo& Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cCount As Long)
  64. 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)
  65. Private Declare Function SaveDC& Lib "gdi32" (ByVal hdc As Long)
  66. Private Declare Function RestoreDC& Lib "gdi32" (ByVal hdc As Long, ByVal nSavedDC As Long)
  67. Private Declare Function PtInRect& Lib "user32" (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long)
  68. 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)
  69. #End If 'WIN32
  70. Private Sub Form_Load()
  71.     SetPoint Points(PT_START), 100, 140
  72.     SetPoint Points(PT_C1), 50, 80
  73.     SetPoint Points(PT_C2), 350, 200
  74.     SetPoint Points(PT_END), 300, 140
  75.     SetPtRect PT_START
  76.     SetPtRect PT_C1
  77.     SetPtRect PT_C2
  78.     SetPtRect PT_END
  79. End Sub
  80. Private Sub Out_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  81.     Dim fAny%, i%
  82.     If Button And vbRightButton Then
  83.         Form_Load
  84.         Out.Refresh
  85.         Exit Sub
  86.     End If
  87.     For i% = 0 To 3
  88.         If PtInRect(Rects(i%), X, Y) Then
  89.             curPt = i%
  90.             fAny% = True
  91.             fDragging% = True
  92.             Exit For
  93.         End If
  94.     Next i%
  95. End Sub
  96. Private Sub Out_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  97.     Dim i%
  98.     If Not fDragging% Then Exit Sub
  99.     Out.ForeColor = (Not (QBColor(8)) And &HFFFFFF)
  100.     dl& = PolyBezier(Out.hdc, Points(0), 4)
  101.     Out.ForeColor = QBColor(10)
  102.     Out.DrawStyle = 2 'Dot
  103.     Out.Line (Points(PT_C1).X, Points(PT_C1).Y)-(Points(PT_START).X, Points(PT_START).Y)
  104.     Out.Line (Points(PT_C2).X, Points(PT_C2).Y)-(Points(PT_END).X, Points(PT_END).Y)
  105.     Out.DrawStyle = 0
  106.     SetPoint Points(curPt), X, Y
  107.     Out.ForeColor = (Not (QBColor(8)) And &HFFFFFF)
  108.     dl& = PolyBezier(Out.hdc, Points(0), 4)
  109.     Out.ForeColor = QBColor(10)
  110.     Out.DrawStyle = 2 'Dot
  111.     Out.Line (Points(PT_C1).X, Points(PT_C1).Y)-(Points(PT_START).X, Points(PT_START).Y)
  112.     Out.Line (Points(PT_C2).X, Points(PT_C2).Y)-(Points(PT_END).X, Points(PT_END).Y)
  113.     Out.DrawStyle = 0
  114.     For i% = 0 To 3
  115.         Out.ForeColor = QBColor(IIf(i% = 0 Or i% = 3, 12, 10))
  116.         Out.FillColor = QBColor(IIf(i% = 0 Or i% = 3, 12, 10))
  117.         DrawRect Out.hdc, Rects(i%)
  118.         If i% = curPt Then
  119.             SetPtRect curPt
  120.         End If
  121.         DrawRect Out.hdc, Rects(i%)
  122.     Next i%
  123. End Sub
  124. Private Sub Out_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  125.     If fDragging% Then
  126.         SetPoint Points(curPt), X, Y
  127.         SetPtRect curPt
  128.         fDragging% = False
  129.     End If
  130. End Sub
  131. Private Sub Out_Paint()
  132.     Out.ForeColor = (Not (QBColor(8)) And &HFFFFFF)
  133. '    Out.ForeColor = QBColor(8)
  134.     dl& = PolyBezier(Out.hdc, Points(0), 4)
  135.     Out.ForeColor = QBColor(12)
  136.     Out.FillColor = QBColor(12)
  137.     DrawRect Out.hdc, Rects(PT_START)
  138.     DrawRect Out.hdc, Rects(PT_END)
  139.     Out.ForeColor = QBColor(10)
  140.     Out.FillColor = QBColor(10)
  141.     DrawRect Out.hdc, Rects(PT_C1)
  142.     DrawRect Out.hdc, Rects(PT_C2)
  143.     Out.DrawStyle = 2 'Dot
  144.     Out.ForeColor = QBColor(10)
  145.     Out.Line (Points(PT_C1).X, Points(PT_C1).Y)-(Points(PT_START).X, Points(PT_START).Y)
  146.     Out.Line (Points(PT_C2).X, Points(PT_C2).Y)-(Points(PT_END).X, Points(PT_END).Y)
  147.     Out.DrawStyle = 0
  148. End Sub
  149. Private Sub SetPoint(myPt As POINTAPI, ByVal X As Long, ByVal Y As Long)
  150.         myPt.X = X
  151.         myPt.Y = Y
  152. End Sub
  153. Private Sub SetPtRect(ByVal Index As Integer)
  154.         Rects(Index).Left = Points(Index).X - 3
  155.         Rects(Index).Top = Points(Index).Y - 3
  156.         Rects(Index).Right = Rects(Index).Left + 6
  157.         Rects(Index).Bottom = Rects(Index).Top + 6
  158. '    dl& = SetRect(Rects(Index), Points(Index).X - 3, Points(Index).Y - 3, Rects(Index).Left + 6, Rects(Index).Top + 6)
  159. End Sub
  160. Private Sub DrawRect(ByVal hdc As Long, myRect As RECT)
  161.     Out.Line (myRect.Left, myRect.Top)-(myRect.Right, myRect.Bottom), , BF
  162. End Sub
  163.