1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| Option Explicit
Private Const GM_ADVANCED = 2
Private Const GM_COMPATIBLE = 1
Private Declare Function SetGraphicsMode Lib "gdi32" (ByVal hDC As Long, ByVal iMode As Long) As Long
Private Declare Function SetWorldTransform Lib "gdi32" (ByVal hDC As Long, ByRef lpXform As XFORM) As Long
Private Declare Function GetWorldTransform Lib "gdi32" (ByVal hDC As Long, ByRef lpXform As XFORM) As Long
Private Declare Function SetViewportOrgEx Lib "gdi32" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, ByRef lpPoint As Any) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hDC As Long, ByRef lpPoint As PointAPI, ByVal nCount As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByRef lpPoint As Any) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Type XFORM
eM11 As Single
eM12 As Single
eM21 As Single
eM22 As Single
eDx As Single
eDy As Single
End Type
Private Type PointAPI
X As Long
Y As Long
End Type
Dim PolygonsPoints(7) As PointAPI
Private Sub cmdClear_Click()
Picture1.Cls
End Sub
Private Sub cmdDraw_Click()
'quelque fonctions de dessin vb
'se sera identique pour les fonction de dessin avec les api
' Set the centre of rotation
Dim OldOrg As PointAPI
Dim lRet As Long
lRet = SetViewportOrgEx(Picture1.hDC, 75, 75, OldOrg)
Call MoveToEx(Picture1.hDC, 0, -75, ByVal 0&)
Call LineTo(Picture1.hDC, 0, 75)
Call MoveToEx(Picture1.hDC, -75, 0, ByVal 0&)
Call LineTo(Picture1.hDC, 75, 0)
Call Polygon(Picture1.hDC, PolygonsPoints(0), 8)
Picture1.CurrentX = 10
Picture1.CurrentY = 10
Picture1.Print "ESSAI3"
Picture1.Line (10, 10)-(40, 25)
Picture1.CurrentY = 10
lRet = SetViewportOrgEx(Picture1.hDC, OldOrg.X, OldOrg.Y, ByVal 0&)
Picture1.Refresh
End Sub
Private Sub cmdTransform_Click()
Dim lRet As Long
Dim Matrix As XFORM
Dim OldMatrix As XFORM
Dim OldOrg As PointAPI
Dim OldMode As Long
'mise en place de la Transformation
With Matrix
'scaling
' .eM11 = xFactor
' .eM12 = 0
' .eM21 = 0
' .eM22 = yFactor
'rotation
' .eM11 = Cos(RotRad(45))
' .eM12 = Sin(RotRad(45))
' .eM21 = -.eM12
' .eM22 = .eM11
' Shear
' .eM11 = 1
' .eM12 = xShear
' .eM21 = yShear
' .eM22 = 1
'reflection
.eM11 = -1 'mirroir axe x
.eM12 = 0
.eM21 = 0
.eM22 = -1 'mirroir axe y
'decalage
'.eDx = 75
'.eDy = 75
End With
'passer en mode graphique avancé avec préservation de l'ancien mode
OldMode = SetGraphicsMode(Picture1.hDC, GM_ADVANCED)
'definir le centre de l'image
lRet = SetViewportOrgEx(Picture1.hDC, 75, 75, OldOrg)
'préserver la tranformation courante
lRet = GetWorldTransform(Picture1.hDC, OldMatrix)
'appliquer la transformation
lRet = SetWorldTransform(Picture1.hDC, Matrix)
'dessiner
cmdDraw_Click
'revenir à l'etat de départ
lRet = SetViewportOrgEx(Picture1.hDC, OldOrg.X, OldOrg.Y, ByVal 0&)
lRet = SetWorldTransform(Picture1.hDC, OldMatrix)
lRet = SetGraphicsMode(Picture1.hDC, OldMode)
Picture1.Refresh
End Sub
Private Sub Form_Load()
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
'dessin d'un polygone
PolygonsPoints(0).X = 20: PolygonsPoints(0).Y = 0
PolygonsPoints(1).X = 50: PolygonsPoints(1).Y = 0
PolygonsPoints(2).X = 50: PolygonsPoints(2).Y = 40
PolygonsPoints(3).X = 55: PolygonsPoints(3).Y = 40
PolygonsPoints(4).X = 35: PolygonsPoints(4).Y = 55
PolygonsPoints(5).X = 15: PolygonsPoints(5).Y = 40
PolygonsPoints(6).X = 20: PolygonsPoints(6).Y = 40
PolygonsPoints(7).X = 20: PolygonsPoints(7).Y = 0
End Sub
Private Function RotRad(Angle As Single) As Single
Const Pi As Single = 3.14159
RotRad = (Angle / 180) * Pi
End Function |