Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 6 sept. 2005 à 15:05
le plus sur moyen c'est encore le subclassing
un peu chiant à mettre en oeuvre parce que le moindre problème dans l'IDE fait planter VB
donc sauvegarde obligatoire avant de tester.
sinon dès que c'est compilé ça marche très bien
dans la Form1
Private Sub Form_Load()
'Remplace la procédure de fenêtre par défaut par notre propre procédure
oldWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Remet la procédure de fenêtre par défaut
SetWindowLong hwnd, GWL_WNDPROC, oldWndProc
End Sub
dans un module
Public Const GWL_WNDPROC = (-4)
Private Const WM_MOVE = &H3
Public oldWndProc As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _
ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If msg = WM_MOVE Then
'la form1 a été déplacée
Form1.Cls
Form1.Print "Nouvelle position : " & Form1.Left & ", " & Form1.Top
End If
'Appelle la procédure de fenêtre par défaut pour que Windows puisse traiter l'évènement
WindowProc = CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam)