Déplacement de Form !

guilleto Messages postés 256 Date d'inscription jeudi 23 octobre 2003 Statut Membre Dernière intervention 20 mars 2013 - 6 sept. 2005 à 14:35
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 - 7 sept. 2005 à 01:57
Salut à toutes et à tous !

C'est encore moi !

J'ai une petite question (et oui) :
Comment détecter qu'une form est déplacée par l'utilisateur ?

Existe une petite API qui donne les nouvelles coordonnées en X et en Y de la dite Form ?

Par avance !

Merci !

Olivier

P.S. : C'est toujours aussi urgent !

2 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
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)

End Function



Daniel
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
7 sept. 2005 à 01:57
SVP, utilisez le moteur de recherche avant de poster.
http://www.vbfrance.com/code.aspx?id=5562
PCPT
0
Rejoignez-nous