Récupéré des ev. de la molette d'une souris sur une PictureBox.

arnaud - 15 juin 2001 à 18:04
 Laurent VOISIN - 3 déc. 2001 à 11:14
Salut,

Je voudrais savoir comment je peux récupérer les évênement de la molette d'une souris envoyés sur une PictureBox afin de zoomer sur l'image comme dans Paint Shop Pro.

Pour l'instant, Je clique gauche ca zoom, je clique droit ca dézoom et ca serait vachement cool si ca marchait avec la molette de la souris :-) .

Merci d'avance...

2 réponses

Si tu as réussi un a faire ca.
Peux tu me dire comment tu peux réagir sur la molette de la souris. Je cherche a faire du code sur cette événement mais je le trouve pas.
0
Laurent VOISIN
3 déc. 2001 à 11:14
Option Explicit
'
' Laurent VOISIN 07/2001
'

'************************************************************
'API Pour mettre en place un CallBack
'************************************************************
Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long


'
' Pour transcrire les coordonnée d'un client (ex: PictureBox) en coordonnées écran
'
Public Type POINTAPI
x As Long
y As Long
End Type
Public Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

'
' Pour savoir si le logiciel en cours est la tâche courante (sélectionnée ds la barre des taches)
'
Public Declare Function GetForegroundWindow Lib "user32" () As Long

'************************************************************
'Constantes
'************************************************************

Global Const MK_CONTROL = &H8
Global Const MK_LBUTTON = &H1
Global Const MK_RBUTTON = &H2
Global Const MK_MBUTTON = &H10
Global Const MK_SHIFT = &H4
Private Const GWL_WNDPROC = -4
Private Const WM_MOUSEWHEEL = &H20A

'************************************************************
'Variables
'************************************************************
Private hControl As Long
Private lPrevWndProc As Long
Global WheelAlreadyHooked As Boolean
Global bIsInIDE As Boolean

'*************************************************************
'WindowProc
'*************************************************************
Private Function WindowProc(ByVal lWnd As Long, ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fwKeys As Long
Dim zDelta As Long
Dim xPos As Long
Dim yPos As Long

'Teste si le message est WM_MOUSEWHEEL
If lMsg = WM_MOUSEWHEEL Then
fwKeys = wParam And 65535
zDelta = wParam / 65536
xPos = lParam And 65535
yPos = lParam / 65536
'On appel la fonction MouseWheel de Form1
Call F_LogScope.MouseWheel(fwKeys, zDelta, xPos, yPos)
End If

' TRES IMPORTANT
' Renvoyer le message à la procédure précédente
WindowProc = CallWindowProc(lPrevWndProc, lWnd, lMsg, wParam, lParam)
End Function

'*************************************************************
'un petit coup de Hook
'*************************************************************
Public Sub Hook(ByVal hControl_ As Long)
hControl = hControl_
lPrevWndProc = SetWindowLong(hControl, GWL_WNDPROC, AddressOf WindowProc)
End Sub

'*******************************************************************************
'un petit coup de UnHook
' ATTENTION, ne pas faire STOP dans l'IDE VB avant de passer par cette routine
'*******************************************************************************
Public Sub UnHook()
Call SetWindowLong(hControl, GWL_WNDPROC, lPrevWndProc)
End Sub

'
' Pour savoir si on tourne dans l'IDE VB ou pas
'
Public Function IsIDE() As Boolean

On Error GoTo ErrHandler
Dim bRet As Boolean

bRet = False
Debug.Print 1 / 0
IsIDE = bRet
Exit Function

ErrHandler:
bRet = True
Resume Next

End Function
0
Rejoignez-nous