home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / FYI__GDI+_2097811162008.psc / Form1.frm < prev    next >
Text File  |  2008-02-16  |  30KB  |  791 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form Form1 
  4.    AutoRedraw      =   -1  'True
  5.    BackColor       =   &H00FFFFFF&
  6.    BorderStyle     =   1  'Fixed Single
  7.    Caption         =   "GDI+ Path Warping"
  8.    ClientHeight    =   4815
  9.    ClientLeft      =   45
  10.    ClientTop       =   435
  11.    ClientWidth     =   6885
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   321
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   459
  17.    StartUpPosition =   2  'CenterScreen
  18.    Begin VB.PictureBox picShapes 
  19.       Appearance      =   0  'Flat
  20.       BackColor       =   &H80000005&
  21.       BorderStyle     =   0  'None
  22.       BeginProperty Font 
  23.          Name            =   "Monotype Corsiva"
  24.          Size            =   8.25
  25.          Charset         =   0
  26.          Weight          =   700
  27.          Underline       =   0   'False
  28.          Italic          =   -1  'True
  29.          Strikethrough   =   0   'False
  30.       EndProperty
  31.       ForeColor       =   &H80000008&
  32.       Height          =   1545
  33.       Left            =   60
  34.       ScaleHeight     =   1545
  35.       ScaleWidth      =   1875
  36.       TabIndex        =   21
  37.       Top             =   60
  38.       Width           =   1875
  39.       Begin VB.OptionButton optShape 
  40.          BackColor       =   &H00FFFFFF&
  41.          Caption         =   "Play with Ellipse"
  42.          Height          =   240
  43.          Index           =   2
  44.          Left            =   0
  45.          TabIndex        =   25
  46.          Top             =   1260
  47.          Width           =   1710
  48.       End
  49.       Begin VB.OptionButton optShape 
  50.          BackColor       =   &H00FFFFFF&
  51.          Caption         =   "Play with Rectangle"
  52.          Height          =   240
  53.          Index           =   1
  54.          Left            =   0
  55.          TabIndex        =   24
  56.          Top             =   990
  57.          Width           =   1710
  58.       End
  59.       Begin VB.TextBox Text1 
  60.          Height          =   615
  61.          Left            =   0
  62.          MultiLine       =   -1  'True
  63.          TabIndex        =   22
  64.          Top             =   300
  65.          Width           =   1740
  66.       End
  67.       Begin VB.OptionButton optShape 
  68.          BackColor       =   &H00FFFFFF&
  69.          Caption         =   "Play with Text"
  70.          Height          =   240
  71.          Index           =   0
  72.          Left            =   0
  73.          TabIndex        =   23
  74.          Top             =   60
  75.          Width           =   1710
  76.       End
  77.    End
  78.    Begin VB.OptionButton optWarp 
  79.       BackColor       =   &H00FFFFFF&
  80.       Caption         =   "Simple Skew"
  81.       Height          =   255
  82.       Index           =   2
  83.       Left            =   45
  84.       TabIndex        =   17
  85.       Top             =   2265
  86.       Width           =   1770
  87.    End
  88.    Begin VB.CheckBox Check1 
  89.       BackColor       =   &H00FFFFFF&
  90.       Caption         =   "Manually Warp Text - Can change Warp Type"
  91.       Height          =   270
  92.       Left            =   2595
  93.       TabIndex        =   16
  94.       Top             =   3975
  95.       Width           =   3750
  96.    End
  97.    Begin VB.CommandButton cmdReset 
  98.       Caption         =   "Reset"
  99.       Height          =   495
  100.       Left            =   975
  101.       TabIndex        =   15
  102.       Top             =   4260
  103.       Width           =   900
  104.    End
  105.    Begin VB.CheckBox chkPen 
  106.       BackColor       =   &H00FFFFFF&
  107.       Caption         =   "Outline Color"
  108.       Height          =   270
  109.       Left            =   480
  110.       TabIndex        =   9
  111.       Top             =   2595
  112.       Width           =   1425
  113.    End
  114.    Begin MSComDlg.CommonDialog CommonDialog1 
  115.       Left            =   3195
  116.       Top             =   2025
  117.       _ExtentX        =   847
  118.       _ExtentY        =   847
  119.       _Version        =   393216
  120.    End
  121.    Begin VB.ComboBox cboGradient 
  122.       Height          =   315
  123.       ItemData        =   "Form1.frx":0000
  124.       Left            =   90
  125.       List            =   "Form1.frx":0010
  126.       Style           =   2  'Dropdown List
  127.       TabIndex        =   7
  128.       Top             =   3600
  129.       Width           =   1770
  130.    End
  131.    Begin VB.CheckBox chkFillType 
  132.       BackColor       =   &H00FFFFFF&
  133.       Caption         =   "Gradient Fill"
  134.       Height          =   255
  135.       Index           =   1
  136.       Left            =   495
  137.       TabIndex        =   5
  138.       Top             =   3315
  139.       Width           =   1350
  140.    End
  141.    Begin VB.CheckBox chkFillType 
  142.       BackColor       =   &H00FFFFFF&
  143.       Caption         =   "Solid Fill"
  144.       Height          =   255
  145.       Index           =   0
  146.       Left            =   495
  147.       TabIndex        =   4
  148.       Top             =   3030
  149.       Width           =   1245
  150.    End
  151.    Begin VB.CommandButton cmdRefresh 
  152.       Caption         =   "Refresh"
  153.       Height          =   495
  154.       Left            =   60
  155.       TabIndex        =   0
  156.       Top             =   4260
  157.       Width           =   900
  158.    End
  159.    Begin VB.PictureBox Picture1 
  160.       Appearance      =   0  'Flat
  161.       BackColor       =   &H80000005&
  162.       ForeColor       =   &H80000008&
  163.       Height          =   3885
  164.       Left            =   1950
  165.       ScaleHeight     =   257
  166.       ScaleMode       =   3  'Pixel
  167.       ScaleWidth      =   324
  168.       TabIndex        =   3
  169.       Top             =   45
  170.       Width           =   4890
  171.       Begin VB.Label lblHandle 
  172.          Appearance      =   0  'Flat
  173.          BackColor       =   &H0043E9D8&
  174.          BorderStyle     =   1  'Fixed Single
  175.          ForeColor       =   &H80000008&
  176.          Height          =   150
  177.          Index           =   5
  178.          Left            =   2280
  179.          MousePointer    =   7  'Size N S
  180.          TabIndex        =   20
  181.          ToolTipText     =   "Vertical Sizing Only"
  182.          Top             =   765
  183.          Visible         =   0   'False
  184.          Width           =   150
  185.       End
  186.       Begin VB.Label lblHandle 
  187.          Appearance      =   0  'Flat
  188.          BackColor       =   &H000000FF&
  189.          BorderStyle     =   1  'Fixed Single
  190.          ForeColor       =   &H80000008&
  191.          Height          =   150
  192.          Index           =   6
  193.          Left            =   2685
  194.          MousePointer    =   5  'Size
  195.          TabIndex        =   19
  196.          ToolTipText     =   "Move Object"
  197.          Top             =   420
  198.          Visible         =   0   'False
  199.          Width           =   150
  200.       End
  201.       Begin VB.Label lblHandle 
  202.          Appearance      =   0  'Flat
  203.          BackColor       =   &H0043E9D8&
  204.          BorderStyle     =   1  'Fixed Single
  205.          ForeColor       =   &H80000008&
  206.          Height          =   150
  207.          Index           =   4
  208.          Left            =   1875
  209.          MousePointer    =   9  'Size W E
  210.          TabIndex        =   18
  211.          ToolTipText     =   "Horizontal Sizing Only"
  212.          Top             =   1155
  213.          Visible         =   0   'False
  214.          Width           =   150
  215.       End
  216.       Begin VB.Label lblHandle 
  217.          Appearance      =   0  'Flat
  218.          BackColor       =   &H00F4B1AC&
  219.          BorderStyle     =   1  'Fixed Single
  220.          ForeColor       =   &H80000008&
  221.          Height          =   150
  222.          Index           =   3
  223.          Left            =   660
  224.          MousePointer    =   2  'Cross
  225.          TabIndex        =   14
  226.          Top             =   840
  227.          Visible         =   0   'False
  228.          Width           =   150
  229.       End
  230.       Begin VB.Label lblHandle 
  231.          Appearance      =   0  'Flat
  232.          BackColor       =   &H00F4B1AC&
  233.          BorderStyle     =   1  'Fixed Single
  234.          ForeColor       =   &H80000008&
  235.          Height          =   150
  236.          Index           =   2
  237.          Left            =   1365
  238.          MousePointer    =   2  'Cross
  239.          TabIndex        =   13
  240.          Top             =   1440
  241.          Visible         =   0   'False
  242.          Width           =   150
  243.       End
  244.       Begin VB.Label lblHandle 
  245.          Appearance      =   0  'Flat
  246.          BackColor       =   &H00F4B1AC&
  247.          BorderStyle     =   1  'Fixed Single
  248.          ForeColor       =   &H80000008&
  249.          Height          =   150
  250.          Index           =   1
  251.          Left            =   330
  252.          MousePointer    =   2  'Cross
  253.          TabIndex        =   12
  254.          Top             =   465
  255.          Visible         =   0   'False
  256.          Width           =   150
  257.       End
  258.       Begin VB.Label lblHandle 
  259.          Appearance      =   0  'Flat
  260.          BackColor       =   &H00F4B1AC&
  261.          BorderStyle     =   1  'Fixed Single
  262.          ForeColor       =   &H80000008&
  263.          Height          =   150
  264.          Index           =   0
  265.          Left            =   1005
  266.          MousePointer    =   2  'Cross
  267.          TabIndex        =   11
  268.          Top             =   1170
  269.          Visible         =   0   'False
  270.          Width           =   150
  271.       End
  272.    End
  273.    Begin VB.OptionButton optWarp 
  274.       BackColor       =   &H00FFFFFF&
  275.       Caption         =   "BiLinear Warp"
  276.       Height          =   255
  277.       Index           =   1
  278.       Left            =   45
  279.       TabIndex        =   2
  280.       Top             =   1980
  281.       Width           =   1905
  282.    End
  283.    Begin VB.OptionButton optWarp 
  284.       BackColor       =   &H00FFFFFF&
  285.       Caption         =   "Perspective Warp"
  286.       Height          =   255
  287.       Index           =   0
  288.       Left            =   45
  289.       TabIndex        =   1
  290.       Top             =   1695
  291.       Width           =   1905
  292.    End
  293.    Begin VB.Label lblColor 
  294.       Appearance      =   0  'Flat
  295.       BackColor       =   &H00C00000&
  296.       BorderStyle     =   1  'Fixed Single
  297.       ForeColor       =   &H80000008&
  298.       Height          =   225
  299.       Index           =   2
  300.       Left            =   90
  301.       TabIndex        =   10
  302.       Top             =   2610
  303.       Width           =   360
  304.    End
  305.    Begin VB.Label lblColor 
  306.       Appearance      =   0  'Flat
  307.       BackColor       =   &H00FFFF00&
  308.       BorderStyle     =   1  'Fixed Single
  309.       ForeColor       =   &H80000008&
  310.       Height          =   225
  311.       Index           =   1
  312.       Left            =   90
  313.       TabIndex        =   8
  314.       Top             =   3315
  315.       Width           =   360
  316.    End
  317.    Begin VB.Label lblColor 
  318.       Appearance      =   0  'Flat
  319.       BackColor       =   &H00C0C000&
  320.       BorderStyle     =   1  'Fixed Single
  321.       ForeColor       =   &H80000008&
  322.       Height          =   225
  323.       Index           =   0
  324.       Left            =   90
  325.       TabIndex        =   6
  326.       Top             =   3030
  327.       Width           =   360
  328.    End
  329. End
  330. Attribute VB_Name = "Form1"
  331. Attribute VB_GlobalNameSpace = False
  332. Attribute VB_Creatable = False
  333. Attribute VB_PredeclaredId = True
  334. Attribute VB_Exposed = False
  335. Option Explicit
  336.  
  337. ' An example of warping paths using GDI+
  338.  
  339. ' The class has acknowledgements and is well documented.
  340. ' The class can be modified and expanded to include other path options too, like
  341. ' adding shapes, images, etc. When I have time, I may update the class for that purpose.
  342.  
  343. ' This project is just a sample to get your creative juices flowing. Other things that
  344. ' can be added for example, radial gradients and paths that follow other paths (curves).
  345.  
  346.  
  347. Private Declare Function GdiplusShutdown Lib "gdiplus" _
  348.     (ByVal token As Long) As Long
  349.  
  350. Private Declare Function GdiplusStartup Lib "gdiplus" _
  351.     (ByRef token As Long, ByRef lpInput As GDIPlusStartupInput, _
  352.     ByRef lpOutput As GdiplusStartupOutput) As Long
  353.  
  354. Private Type GDIPlusStartupInput
  355.     GdiPlusVersion As Long
  356.     DebugEventCallback As Long
  357.     SuppressBackgroundThread As Long
  358.     SuppressExternalCodecs As Long
  359. End Type
  360.  
  361. Private Type GdiplusStartupOutput
  362.     NotificationHook As Long
  363.     NotificationUnhook As Long
  364. End Type
  365.  
  366. ' used for manually drawing an outline of a GDI+ path
  367. Private Declare Function MoveToEx Lib "gdi32.dll" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByRef lpPoint As Any) As Long
  368. Private Declare Function LineTo Lib "gdi32.dll" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
  369. Private Declare Function PolyBezierTo Lib "gdi32.dll" (ByVal hDC As Long, ByRef lppt As POINTAPI, ByVal cCount As Long) As Long
  370. Private Enum gdiPathPointType
  371.     PathPointTypeStart = 0
  372.     PathPointTypeLine = 1
  373.     PathPointTypeBezier = 3
  374.     PathPointTypePathTypeMask = &H7
  375.     PathPointTypeDashMode = &H10
  376.     PathPointTypePathMarker = &H20
  377.     PathPointTypeCloseSubpath = &H80
  378. End Enum
  379.  
  380. Private Type POINTAPI
  381.     X As Long
  382.     Y As Long
  383. End Type
  384.  
  385. ' used when manually warping path
  386. Private curX As Single, curY As Single  ' used to drag labels
  387. Private pathPoints() As Single          ' GDI+ path point X,Y coords
  388. Private pathType() As Byte              ' GDI+ path types: see gdiPathPointType above
  389. Private pathPtCount As Long             ' number of points in the path
  390.  
  391. Private GdipToken As Long
  392. Private cGDIwarper As gdipPathWarper
  393.  
  394. Private Sub Form_Load()
  395.     StartUpGDIPlus 1        ' start up gdi
  396.     If GdipToken = 0& Then
  397.         MsgBox "Failed to start GDI+, closing application", vbExclamation + vbOKOnly
  398.         Unload Me
  399.         Exit Sub
  400.     End If
  401.     
  402.     Set cGDIwarper = New gdipPathWarper
  403.     Picture1.ScaleMode = vbPixels   ' want pixel scalemode when doing graphics
  404.     Picture1.AutoRedraw = True
  405.     cboGradient.ListIndex = 1       ' set initial combobox item
  406.     
  407.     ' set up initial pens/brushes and stuff
  408.     chkPen.Value = 1            ' use outline pen
  409.     chkFillType(1) = 1          ' use solid vs gradient brush
  410.     optWarp(0) = True           ' set initial warp mode
  411.     
  412.     Text1.Text = "LaVolpe"
  413.     optShape(0) = True
  414.  
  415.     ' modify the path coordinates to squeeze vertically the right edge of the path
  416.     cGDIwarper.UpdateDestPoint 247, 110, TopRight
  417.     cGDIwarper.UpdateDestPoint 247, 150, BottomRight
  418.     Call cmdRefresh_Click
  419.     Show                        ' show our form
  420.  
  421. End Sub
  422.  
  423. Private Sub Form_Unload(Cancel As Integer)
  424.     ' Tip: When using GDI+, always unload any classes/objects that can be using
  425.     ' GDI+ before you actually shutdown GDI+.
  426.     ' Best to put GDI+ shutdown in terminate event
  427.     Set cGDIwarper = Nothing
  428.     ShutdownGDIPlus
  429.  
  430. End Sub
  431.  
  432. Private Sub cboGradient_Click()
  433.     ' option to change gradient -- uses GDI+ settings
  434.     If chkFillType(1).Value Then
  435.         cGDIwarper.SetBrush lblColor(0).BackColor, lblColor(1).BackColor, cboGradient.ListIndex
  436.         Call cmdRefresh_Click
  437.     End If
  438.  
  439. End Sub
  440.  
  441. Private Sub Check1_Click()
  442.     ' option to manually warp path
  443.     
  444.     Dim I As Integer, halfCx As Long, handlePts() As Single
  445.     Dim bEnabled As Boolean
  446.     
  447.     If Check1.Value Then ' manually warping path
  448.     
  449.         ' get its point X,Y coords and the type of each point
  450.         pathPtCount = cGDIwarper.GetPathPoints(pathPoints(), pathType())
  451.         
  452.         ' position handles & make them visible
  453.         PositionHandles True, True
  454.         For I = 0 To lblHandle.UBound
  455.             lblHandle(I).Visible = True
  456.         Next
  457.         bEnabled = False    ' disable other controls except the warp option buttons
  458.         
  459.         ' show message first time only
  460.         If Check1.Tag = vbNullString Then
  461.             Check1.Tag = "NoMsgBox"
  462.             MsgBox "When warping and points cross over opposite bounds, mirroring of the path occurs." & vbNewLine & _
  463.                 "This mirroring is agreeable only in BiLinear mode. Perspective mirroring produces poor results." & vbNewLine & vbNewLine & _
  464.                 "To see the diffeernt results, drag the top left handle to the bottom/center of the picturebox. " & vbNewLine & _
  465.                 "Then toggle the BiLinear & Perspective warp options", vbInformation + vbOKOnly, "Path Mirroring"
  466.         End If
  467.     
  468.         DrawSelectionBox -1 ' show the bounding rectangle & path
  469.         
  470.     Else
  471.         Erase pathPoints
  472.         Erase pathType
  473.         For I = 0 To lblHandle.UBound   ' hide the handles
  474.             lblHandle(I).Visible = False
  475.         Next
  476.         Call cmdRefresh_Click       ' refresh
  477.         bEnabled = True             ' enable other controls
  478.     End If
  479.     
  480.     ' enable/disable controls
  481.     cboGradient.Enabled = bEnabled
  482.     For I = 0 To lblColor.UBound
  483.         lblColor(I).Enabled = bEnabled
  484.     Next
  485.     For I = 0 To chkFillType.UBound
  486.         chkFillType(I).Enabled = bEnabled
  487.     Next
  488.     chkPen.Enabled = bEnabled
  489.     Text1.Enabled = bEnabled
  490.     cmdRefresh.Enabled = bEnabled
  491.     cmdReset.Enabled = bEnabled
  492.     picShapes.Enabled = bEnabled
  493.  
  494. End Sub
  495.  
  496. Private Sub chkFillType_Click(Index As Integer)
  497.     ' option to use solid or gradient brush
  498.     ' Note: the class SetBrush function also has an Opacity setting where brushes can be semitransparent
  499.     If chkFillType(0).Tag = vbNullString Then
  500.         If chkFillType(Abs(Index - 1)).Value Then   ' only one check box, uncheck the other
  501.             chkFillType(0).Tag = "No Update"
  502.             chkFillType(Abs(Index - 1)).Value = 0
  503.             chkFillType(0).Tag = vbNullString
  504.         End If
  505.         
  506.         If chkFillType(0) = 1 Then ' solid brush
  507.             cGDIwarper.SetBrush lblColor(Index).BackColor
  508.         ElseIf chkFillType(1) = 1 Then ' gradient brush
  509.             cGDIwarper.SetBrush lblColor(0).BackColor, lblColor(1).BackColor, cboGradient.ListIndex
  510.         Else ' nothing is selected
  511.             cGDIwarper.SetBrush -1 ' transparent fill, no brush
  512.         End If
  513.         Call cmdRefresh_Click       ' refresh
  514.     End If
  515. End Sub
  516.  
  517. Private Sub chkPen_Click()
  518.     ' option to use pen
  519.     ' Note: the class SetOutline function also has an Opacity setting where pens can be semitransparent
  520.     If chkPen.Value Then
  521.         cGDIwarper.SetOutLine 2, lblColor(2).BackColor
  522.     Else
  523.         cGDIwarper.SetOutLine 2, -1 ' no outline color
  524.     End If
  525.     Call cmdRefresh_Click   ' refresh
  526. End Sub
  527.  
  528. Private Sub cmdRefresh_Click()
  529.     If Check1.Value Then                ' manual warping now
  530.         DrawSelectionBox 5
  531.         PositionHandles False, True
  532.     Else                                ' refresh
  533.         Picture1.Cls
  534.         cGDIwarper.DrawWarpPath Picture1.hDC
  535.         Picture1.Refresh
  536.     End If
  537. End Sub
  538.  
  539. Private Sub cmdReset_Click()
  540.     ' reset path to a non-warped state
  541.     ' Warped is simply a non-rectangular path
  542.     cGDIwarper.SetPathDest_Rect 40, 53, 247, 188
  543.     Call cmdRefresh_Click
  544. End Sub
  545.  
  546. Private Sub lblColor_Click(Index As Integer)
  547.     ' allow brush & color options
  548.     With CommonDialog1
  549.         .Flags = cdlCCFullOpen Or cdlCCRGBInit
  550.         .CancelError = True
  551.         .Color = lblColor(Index).BackColor
  552.     End With
  553.     On Error GoTo EH
  554.     CommonDialog1.ShowColor
  555.     lblColor(Index).BackColor = CommonDialog1.Color
  556.     If Index = 2 Then
  557.         If chkPen.Value Then Call chkPen_Click
  558.     ElseIf chkFillType(Index).Value And Index = 0 Then
  559.         Call chkFillType_Click(Index)
  560.     ElseIf chkFillType(1).Value Then
  561.         Call chkFillType_Click(1)
  562.     End If
  563. EH:
  564. If Err Then Err.Clear ' user pressed cancel
  565. End Sub
  566.  
  567. Private Sub lblHandle_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  568.     If Button = vbLeftButton Then curX = X: curY = Y   ' cache handle's current x,y
  569. End Sub
  570.  
  571. Private Sub lblHandle_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  572.     If Button = vbLeftButton Then PositionHandles False, True
  573. End Sub
  574.  
  575. Private Sub lblHandle_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  576.     If Button = vbLeftButton Then
  577.         ' update warp outline
  578.         If Index = 4 Then ' resizing horizontally only
  579.             X = ((X - curX) \ Screen.TwipsPerPixelX)
  580.             lblHandle(Index).Left = lblHandle(Index).Left + X
  581.             cGDIwarper.UpdateDestPoint lblHandle(0).Left + lblHandle(0).Width \ 2 + X, lblHandle(0).Top + lblHandle(0).Height \ 2, TopLeft
  582.             cGDIwarper.UpdateDestPoint lblHandle(2).Left + lblHandle(2).Width \ 2 + X, lblHandle(2).Top + lblHandle(0).Height \ 2, BottomLeft
  583.             DrawSelectionBox Index
  584.         ElseIf Index = 5 Then 'resizing vertically only
  585.             Y = ((Y - curX) \ Screen.TwipsPerPixelX)
  586.             lblHandle(Index).Top = lblHandle(Index).Top + Y
  587.             cGDIwarper.UpdateDestPoint lblHandle(0).Left + lblHandle(0).Width \ 2, lblHandle(0).Top + lblHandle(0).Height \ 2 + Y, TopLeft
  588.             cGDIwarper.UpdateDestPoint lblHandle(1).Left + lblHandle(0).Width \ 2, lblHandle(1).Top + lblHandle(0).Height \ 2 + Y, TopRight
  589.             DrawSelectionBox Index
  590.         ElseIf Index = 6 Then ' moving vs resizing
  591.             X = ((X - curX) \ Screen.TwipsPerPixelX)
  592.             Y = ((Y - curX) \ Screen.TwipsPerPixelX)
  593.             lblHandle(Index).Move lblHandle(Index).Left + X, lblHandle(Index).Top + Y
  594.             cGDIwarper.OffsetDestination X, Y
  595.             DrawSelectionBox 6
  596.         Else
  597.             cGDIwarper.UpdateDestPoint lblHandle(Index).Left + (X - curX) \ Screen.TwipsPerPixelX, lblHandle(Index).Top + (Y - curY) \ Screen.TwipsPerPixelX, Index
  598.             DrawSelectionBox Index
  599.         End If
  600.     End If
  601. End Sub
  602.  
  603. Private Sub optShape_Click(Index As Integer)
  604.     Picture1.Cls
  605.     Select Case Index
  606.         Case 0: Call Text1_LostFocus
  607.         Case 1: cGDIwarper.SetPathShape_Rectangle 40, 53, 247, 188
  608.                 Call cmdRefresh_Click
  609.         Case 2: cGDIwarper.SetPathShape_Ellipse 40, 53, 247, 188
  610.                 Call cmdRefresh_Click
  611.     End Select
  612. End Sub
  613.  
  614. Private Sub optWarp_Click(Index As Integer)
  615.     ' option to use BiLinear or Perspective Warp
  616.     If optWarp(0) Then ' perspective
  617.         cGDIwarper.WarpStyle = warpPerspective
  618.     ElseIf optWarp(1) Then ' bilinear
  619.         cGDIwarper.WarpStyle = warpBilinear
  620.     Else    ' skew - warp shape is parallelogram
  621.         cGDIwarper.WarpStyle = warpSkew
  622.     End If
  623.     Call cmdRefresh_Click
  624.     
  625.     If optWarp(0).Tag = vbNullString Then
  626.         If cGDIwarper.WarpStyle = warpSkew Then
  627.             optWarp(0).Tag = "shown"
  628.             MsgBox "FYI: When a warp path is a parallelogram/rectangle, " & vbNewLine & _
  629.                 "all warp modes produce the same results.", vbInformation + vbOKOnly
  630.         End If
  631.     End If
  632.     
  633.     ' FYI: When warp path is a perfect parallelogram/rectangle,
  634.     ' all warp options produce the same results.
  635.     ' Skewing is simply bilinear/perspective warping forcing use of a parallelogram shape
  636.     
  637. End Sub
  638.  
  639.  
  640. Private Function ShutdownGDIPlus() As Long
  641.     ShutdownGDIPlus = GdiplusShutdown(GdipToken)    ' shut down GDI+
  642. End Function
  643.  
  644. Private Function StartUpGDIPlus(ByVal GdipVersion As Long) As Long
  645.     ' Initialisieren der GDI+ Instanz
  646.     Dim GdipStartupInput As GDIPlusStartupInput
  647.     Dim GdipStartupOutput As GdiplusStartupOutput
  648.     
  649.     GdipStartupInput.GdiPlusVersion = GdipVersion
  650.     StartUpGDIPlus = GdiplusStartup(GdipToken, GdipStartupInput, GdipStartupOutput)
  651. End Function
  652.  
  653. Private Sub PositionHandles(Optional blueHandles As Boolean, Optional goldHandles As Boolean)
  654.     ' simply positions handle labels
  655.     Dim I As Integer, halfCx As Long, handlePts() As Single
  656.     
  657.     halfCx = lblHandle(0).Width \ 2
  658.     cGDIwarper.GetBoundingPoints handlePts()
  659.     
  660.     ' Note. GDI path points are Z-clockwise order:
  661.     '   -- Top Left, Top Right, Bottom Left, Bottom Right
  662.     If blueHandles Then ' positiong blue corner labels
  663.         For I = 0 To 3
  664.             lblHandle(I).Move handlePts(0, I) - halfCx, handlePts(1, I) - halfCx
  665.         Next
  666.     End If
  667.     If goldHandles Then ' position additional handles
  668.         lblHandle(4).Move handlePts(0, 0) + (handlePts(0, 2) - handlePts(0, 0)) \ 2 - halfCx, handlePts(1, 0) + (handlePts(1, 2) - handlePts(1, 0)) \ 2
  669.         lblHandle(5).Move handlePts(0, 2) + (handlePts(0, 3) - handlePts(0, 2)) \ 2, handlePts(1, 2) + (handlePts(1, 3) - handlePts(1, 2)) \ 2
  670.         lblHandle(6).Move lblHandle(5).Left, lblHandle(4).Top
  671.     End If
  672.     
  673. End Sub
  674.  
  675. Private Sub DrawSelectionBox(ByVal UpdatePos As Long)
  676.     ' draw the path's bounding rectangle
  677.     
  678.     Dim I As Integer, halfCx As Long, handlePts() As Single
  679.     halfCx = lblHandle(0).Width \ 2
  680.     
  681.     With Picture1
  682.         .DrawMode = 10 ' notxorpen
  683.         .DrawStyle = 2 ' dotted pen
  684.         
  685.         ' draw box. If already drawn, this will erase it
  686.         .ForeColor = RGB(192, 192, 192) ' light gray
  687.         Picture1.Line (lblHandle(0).Left + halfCx, lblHandle(0).Top + halfCx)-(lblHandle(1).Left + halfCx, lblHandle(1).Top + halfCx)
  688.         Picture1.Line (lblHandle(1).Left + halfCx, lblHandle(1).Top + halfCx)-(lblHandle(3).Left + halfCx, lblHandle(3).Top + halfCx)
  689.         Picture1.Line (lblHandle(3).Left + halfCx, lblHandle(3).Top + halfCx)-(lblHandle(2).Left + halfCx, lblHandle(2).Top + halfCx)
  690.         Picture1.Line (lblHandle(2).Left + halfCx, lblHandle(2).Top + halfCx)-(lblHandle(0).Left + halfCx, lblHandle(0).Top + halfCx)
  691.         
  692.         .ForeColor = vbRed
  693.         OutlinePath ' draw path & if already drawn, this will erase it
  694.         
  695.         If UpdatePos > -1 Then  ' else first time thru & we won't need to do this
  696.         
  697.             ' draw new bounding rectangle
  698.             .ForeColor = RGB(192, 192, 192)
  699.             PositionHandles True
  700.             Picture1.Line (lblHandle(0).Left + halfCx, lblHandle(0).Top + halfCx)-(lblHandle(1).Left + halfCx, lblHandle(1).Top + halfCx)
  701.             Picture1.Line (lblHandle(1).Left + halfCx, lblHandle(1).Top + halfCx)-(lblHandle(3).Left + halfCx, lblHandle(3).Top + halfCx)
  702.             Picture1.Line (lblHandle(3).Left + halfCx, lblHandle(3).Top + halfCx)-(lblHandle(2).Left + halfCx, lblHandle(2).Top + halfCx)
  703.             Picture1.Line (lblHandle(2).Left + halfCx, lblHandle(2).Top + halfCx)-(lblHandle(0).Left + halfCx, lblHandle(0).Top + halfCx)
  704.             
  705.             ' get the points for the new warped path & draw the outline
  706.             pathPtCount = cGDIwarper.GetPathPoints(pathPoints(), pathType())
  707.             .ForeColor = vbRed
  708.             OutlinePath
  709.             
  710.         End If
  711.         .ForeColor = vbBlack
  712.         .DrawMode = 13  ' reset back to normal
  713.         .DrawStyle = 0
  714.         Picture1.Refresh
  715.     End With
  716. End Sub
  717.  
  718. Private Sub OutlinePath()
  719.     
  720.     ' this is an example how to manually render the path
  721.     ' It isn't too complicated & I thought I'd add it for fun
  722.     
  723.     Dim I As Long, lastPt As Long, bzPt(0 To 2) As POINTAPI
  724.     If pathPtCount Then
  725.         
  726.         For I = 0 To pathPtCount - 1
  727.             Select Case ((pathType(I) And Not PathPointTypeDashMode) And Not PathPointTypePathMarker)
  728.             Case PathPointTypeStart
  729.                 If lastPt Then
  730.                     LineTo Picture1.hDC, pathPoints(0, lastPt), pathPoints(1, lastPt)
  731.                 End If
  732.                 MoveToEx Picture1.hDC, pathPoints(0, I), pathPoints(1, I), ByVal 0&
  733.                 lastPt = I
  734.             
  735.             Case PathPointTypeLine Or PathPointTypeCloseSubpath
  736.                 LineTo Picture1.hDC, pathPoints(0, I), pathPoints(1, I)
  737.                 If lastPt Then
  738.                     LineTo Picture1.hDC, pathPoints(0, lastPt), pathPoints(1, lastPt)
  739.                     lastPt = 0&
  740.                 End If
  741.                 
  742.             Case PathPointTypeLine
  743.                 LineTo Picture1.hDC, pathPoints(0, I), pathPoints(1, I)
  744.                 
  745.             Case PathPointTypeBezier Or PathPointTypeCloseSubpath
  746.                 ' convert single to long for the API
  747.                 bzPt(0).X = pathPoints(0, I): bzPt(0).Y = pathPoints(1, I)
  748.                 bzPt(1).X = pathPoints(0, I + 1): bzPt(1).Y = pathPoints(1, I + 1)
  749.                 bzPt(2).X = pathPoints(0, I + 2): bzPt(2).Y = pathPoints(1, I + 2)
  750.                 PolyBezierTo Picture1.hDC, bzPt(0), 3
  751.                 I = I + 2
  752.                 If lastPt Then
  753.                     LineTo Picture1.hDC, pathPoints(0, lastPt), pathPoints(1, lastPt)
  754.                     lastPt = 0&
  755.                 End If
  756.             
  757.             Case PathPointTypeBezier
  758.                 ' convert single to long for the API
  759.                 bzPt(0).X = pathPoints(0, I): bzPt(0).Y = pathPoints(1, I)
  760.                 bzPt(1).X = pathPoints(0, I + 1): bzPt(1).Y = pathPoints(1, I + 1)
  761.                 bzPt(2).X = pathPoints(0, I + 2): bzPt(2).Y = pathPoints(1, I + 2)
  762.                 PolyBezierTo Picture1.hDC, bzPt(0), 3
  763.                 I = I + 2
  764.             Case Else
  765.                 Stop
  766.  
  767.             End Select
  768.         Next
  769.         If lastPt Then
  770.             LineTo Picture1.hDC, pathPoints(0, lastPt), pathPoints(1, lastPt)
  771.         End If
  772.         
  773.     End If
  774. End Sub
  775.  
  776. Private Sub Text1_LostFocus()
  777.     ' option to change path text. Only triggers on lost focus
  778.     If Not Text1.Text = vbNullString Then
  779.         Dim tFont As StdFont
  780.         Set tFont = New StdFont
  781.         tFont.name = "Georgia" ' Use true-type fonts only
  782.         tFont.Size = 24 ' arbitrary, can be any size
  783.         If cGDIwarper.SetPathString(Text1.Text, tFont) = False Then
  784.             MsgBox "Failed to create string using the font: " & tFont.name, vbExclamation + vbOKCancel
  785.             Picture1.Cls
  786.         Else
  787.             Call cmdReset_Click ' refresh
  788.         End If
  789.     End If
  790. End Sub
  791.