1 Attachment(s)
[VB6] - Rotation a windowless controls.
Code:
Option Explicit
Private Type XFORM
eM11 As Single
eM12 As Single
eM21 As Single
eM22 As Single
eDx As Single
eDy As Single
End Type
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, lpXform As XFORM) As Long
Private Declare Function ModifyWorldTransform Lib "gdi32" (ByVal hdc As Long, lpXform As XFORM, ByVal iMode As Long) As Long
Private Const MWT_IDENTITY = 1
Private Const MWT_LEFTMULTIPLY = 2
Private Const MWT_RIGHTMULTIPLY = 3
Private Const GM_ADVANCED = 2
Private Const GM_COMPATIBLE = 1
Private Sub Form_Load()
SetGraphicsMode Me.hdc, GM_ADVANCED
End Sub
Private Sub Form_Paint()
Dim mtx1 As XFORM, mtx2 As XFORM, c As Single, s As Single, p As IPicture
ModifyWorldTransform Me.hdc, mtx1, MWT_IDENTITY
Me.Line (0, 0)-(Me.ScaleWidth, Me.ScaleHeight), Me.BackColor, BF
c = Cos(hsbAngle.Value / 100)
s = Sin(hsbAngle.Value / 100)
mtx1.eM11 = c: mtx1.eM12 = s: mtx1.eM21 = -s: mtx1.eM22 = c: mtx1.eDx = Me.ScaleWidth / 2: mtx1.eDy = Me.ScaleHeight / 2
mtx2.eM11 = 1: mtx2.eM22 = 1: mtx2.eDx = -Me.ScaleWidth / 2: mtx2.eDy = -Me.ScaleHeight / 2
SetWorldTransform Me.hdc, mtx1
ModifyWorldTransform Me.hdc, mtx2, MWT_LEFTMULTIPLY
End Sub
Private Sub hsbAngle_Change()
Me.Refresh
End Sub
Re: [VB6] - Rotation a windowless controls.
Interesting approach and haven't seen this post of yours. Don't know how I missed it. I will have to download your sample project and play with it, but maybe you can answer this question before I do...
It appears the entire hDC is modified by the XFORM. Could this logic be applied to individual windowless controls? In other words, some controls 'rotated' 90 degrees, others 45 degrees, etc. I would think subclassing the form may be needed or some other method to invalidate specific rectangles?
Re: [VB6] - Rotation a windowless controls.
Yes but you should calculate the update region for each contol, because it'll be cropped y control rectangle. Just apply transformation and call Refresh method.
Re: [VB6] - Rotation a windowless controls.
Unfortunately, within VB you really don't have any control over the Paint event within the Paint event. If the user minimizes the form and restores it, for example, every windowless control will be 'refreshed'. Within the Form_Paint event, one does not have the ability to individually handle each bounding rectangle of each windowless control.