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 / samples4 / ch08 / bezier.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  5.8 KB  |  164 lines

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