@@ -35,6 +35,11 @@ Private Const STR_MODULE_NAME As String = "AlphaBlendImage"
3535
3636Event Click()
3737Event OwnerDraw(ByVal hGraphics As Long , ClientLeft As Long , ClientTop As Long , ClientWidth As Long , ClientHeight As Long , ByVal hPicture As Long )
38+ Event DblClick()
39+ Event ContextMenu()
40+ Event MouseDown(Button As Integer , Shift As Integer , X As Single , Y As Single )
41+ Event MouseMove(Button As Integer , Shift As Integer , X As Single , Y As Single )
42+ Event MouseUp(Button As Integer , Shift As Integer , X As Single , Y As Single )
3843
3944'=========================================================================
4045' API
@@ -146,6 +151,10 @@ Private m_hBitmap As Long
146151Private m_hPictureBitmap As Long
147152Private m_hPictureAttributes As Long
148153Private m_hRedrawDib As Long
154+ Private m_nDownButton As Integer
155+ Private m_nDownShift As Integer
156+ Private m_sngDownX As Single
157+ Private m_sngDownY As Single
149158
150159Private Type UcsRgbQuad
151160 R As Byte
@@ -599,7 +608,7 @@ Private Function pvPreparePicture(oPicture As StdPicture, ByVal clrMask As OLE_C
599608 If GdipCreateImageAttributes(hNewAttributes) <> 0 Then
600609 GoTo QH
601610 End If
602- If GdipSetImageAttributesColorKeys(hNewAttributes, 0 , 1 , pvTranslateColor (clrMask), pvTranslateColor (clrMask)) <> 0 Then
611+ If GdipSetImageAttributesColorKeys(hNewAttributes, 0 , 1 , TranslateColor (clrMask), TranslateColor (clrMask)) <> 0 Then
603612 GoTo QH
604613 End If
605614 End If
@@ -733,6 +742,15 @@ Private Sub pvSizeExtender(ByVal hBitmap As Long, oExt As VBControlExtender)
733742QH:
734743End Sub
735744
745+ Private Sub pvHandleMouseDown (Button As Integer , Shift As Integer , X As Single , Y As Single )
746+ m_nDownButton = Button
747+ m_nDownShift = Shift
748+ m_sngDownX = X
749+ m_sngDownY = Y
750+ End Sub
751+
752+ '= common ================================================================
753+
736754Private Function pvCreateDib (ByVal hMemDC As Long , ByVal lWidth As Long , ByVal lHeight As Long , hDib As Long ) As Boolean
737755 Const FUNC_NAME As String = "pvCreateDib"
738756 Dim uHdr As BITMAPINFOHEADER
760778 Resume QH
761779End Function
762780
763- Private Function pvTranslateColor (ByVal clrValue As OLE_COLOR , Optional ByVal Alpha As Single = 1 ) As Long
781+ Private Function TranslateColor (ByVal clrValue As OLE_COLOR , Optional ByVal Alpha As Single = 1 ) As Long
764782 Dim uQuad As UcsRgbQuad
765783 Dim lTemp As Long
766784
@@ -776,7 +794,7 @@ Private Function pvTranslateColor(ByVal clrValue As OLE_COLOR, Optional ByVal Al
776794 Else
777795 uQuad.A = lTemp
778796 End If
779- Call CopyMemory (pvTranslateColor , uQuad, 4 )
797+ Call CopyMemory (TranslateColor , uQuad, 4 )
780798End Function
781799
782800Private Function HM2Pix (ByVal Value As Single ) As Long
@@ -867,8 +885,41 @@ End Function
867885' Events
868886'=========================================================================
869887
870- Private Sub UserControl_Click ()
871- RaiseEvent Click
888+ Private Sub UserControl_MouseDown (Button As Integer , Shift As Integer , X As Single , Y As Single )
889+ RaiseEvent MouseDown(Button, Shift, ScaleX(X, ScaleMode, m_eContainerScaleMode), ScaleY(Y, ScaleMode, m_eContainerScaleMode))
890+ pvHandleMouseDown Button, Shift, X, Y
891+ End Sub
892+
893+ Private Sub UserControl_MouseMove (Button As Integer , Shift As Integer , X As Single , Y As Single )
894+ RaiseEvent MouseMove(Button, Shift, ScaleX(X, ScaleMode, m_eContainerScaleMode), ScaleY(Y, ScaleMode, m_eContainerScaleMode))
895+ End Sub
896+
897+ Private Sub UserControl_MouseUp (Button As Integer , Shift As Integer , X As Single , Y As Single )
898+ Const FUNC_NAME As String = "UserControl_MouseUp"
899+
900+ On Error GoTo EH
901+ RaiseEvent MouseUp(Button, Shift, ScaleX(X, ScaleMode, m_eContainerScaleMode), ScaleY(Y, ScaleMode, m_eContainerScaleMode))
902+ If Button = -1 Then
903+ GoTo QH
904+ End If
905+ If Button <> 0 And X >= 0 And X < ScaleWidth And Y >= 0 And Y < ScaleHeight Then
906+ If (m_nDownButton And Button And vbLeftButton) <> 0 Then
907+ RaiseEvent Click
908+ ElseIf (m_nDownButton And Button And vbRightButton) <> 0 Then
909+ RaiseEvent ContextMenu
910+ End If
911+ End If
912+ m_nDownButton = 0
913+ QH:
914+ Exit Sub
915+ EH:
916+ PrintError FUNC_NAME
917+ Resume Next
918+ End Sub
919+
920+ Private Sub UserControl_DblClick ()
921+ pvHandleMouseDown vbLeftButton, m_nDownShift, m_sngDownX, m_sngDownY
922+ RaiseEvent DblClick
872923End Sub
873924
874925Private Sub UserControl_HitTest (X As Single , Y As Single , HitResult As Integer )
0 commit comments