Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Evenement sur le déplacement d'une fenetre?

2 réponses
Avatar
ThunderMusic
Bonjour,
Je cherche l'évenement qui est déclanché lorsqu'une fenêtre est
déplacée. Parce que je sais déjà lorsque la fenetre est redimensionnée
(Form_Resize), mais je voudrais savoir lorsqu'elle est déplacée. Est-ce
qu'un tel événement existe en vb6? si oui, lequel? si non, comment puis-je
savoir quand la fenêtre a été déplacée?

Merci Beaucoup

ThunderMusic

2 réponses

Avatar
Zoury
Bonjour Mr. Latulippe!

Tu dois subclasser le message WM_MOVING.

Voici un exemple qui empeche le formulaire de quitter les bordures de
l'écran.
'***
' Form1
Option Explicit

Private Sub Form_Load()
SubClass Me.hWnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnSubClass Me.hWnd
End Sub

' Module1
'*********************************************
'Écrit par Yanick "Zoury" Lefebvre
'*********************************************
Option Explicit

Private Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef
lpvParam As Any, ByVal fuWinIni 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As
Any, pSrc As Any, ByVal ByteLen As Long)

Private Const SPI_GETWORKAREA = &H30
Private Const WM_MOVING As Long = &H216
Private Const GWL_WNDPROC As Long = -4

Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type

Private Type POINTAPI
x As Long
y As Long
End Type

Private m_lOldProc As Long
Private m_rc As RECT

Public Sub SubClass(ByRef hWnd As Long)

m_rc.bottom = (Form1.top + Form1.Height) / Screen.TwipsPerPixelY
m_rc.top = Form1.top / Screen.TwipsPerPixelY
m_rc.left = Form1.left / Screen.TwipsPerPixelX
m_rc.right = (Form1.left + Form1.Width) / Screen.TwipsPerPixelX

m_lOldProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnSubClass(ByRef hWnd As Long)
SetWindowLong hWnd, GWL_WNDPROC, m_lOldProc
End Sub

Function WindowProc(ByVal hWnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

If uMsg = WM_MOVING Then

Dim rc As RECT
Dim WorkArea As RECT

SystemParametersInfo SPI_GETWORKAREA, ByVal 0&, WorkArea, ByVal
0&

CopyMemory rc, ByVal lParam, Len(rc)

If (rc.bottom >= WorkArea.bottom) Or _
(rc.left <= WorkArea.left) Or _
(rc.right >= WorkArea.right) Or _
(rc.top <= WorkArea.top) Then
rc = m_rc
Else
m_rc = rc
End If

CopyMemory ByVal lParam, rc, Len(rc)

WindowProc = 0&
Exit Function
End If

WindowProc = CallWindowProc(m_lOldProc, hWnd, uMsg, wParam, lParam)

End Function
'***

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/

Merci de poster les réponses au groupe afin d'en faire profiter à tous
"ThunderMusic" wrote in message
news:etZH%
Bonjour,
Je cherche l'évenement qui est déclanché lorsqu'une fenêtre


est
déplacée. Parce que je sais déjà lorsque la fenetre est redimensionnée
(Form_Resize), mais je voudrais savoir lorsqu'elle est déplacée. Est-ce
qu'un tel événement existe en vb6? si oui, lequel? si non, comment puis-je
savoir quand la fenêtre a été déplacée?

Merci Beaucoup

ThunderMusic




Avatar
ThunderMusic
merci, je vais essayer. ;)

"Zoury" wrote in message
news:
Bonjour Mr. Latulippe!

Tu dois subclasser le message WM_MOVING.

Voici un exemple qui empeche le formulaire de quitter les bordures de
l'écran.
'***
' Form1
Option Explicit

Private Sub Form_Load()
SubClass Me.hWnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnSubClass Me.hWnd
End Sub

' Module1
'*********************************************
'Écrit par Yanick "Zoury" Lefebvre
'*********************************************
Option Explicit

Private Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long,


ByRef
lpvParam As Any, ByVal fuWinIni 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As


Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst


As
Any, pSrc As Any, ByVal ByteLen As Long)

Private Const SPI_GETWORKAREA = &H30
Private Const WM_MOVING As Long = &H216
Private Const GWL_WNDPROC As Long = -4

Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type

Private Type POINTAPI
x As Long
y As Long
End Type

Private m_lOldProc As Long
Private m_rc As RECT

Public Sub SubClass(ByRef hWnd As Long)

m_rc.bottom = (Form1.top + Form1.Height) / Screen.TwipsPerPixelY
m_rc.top = Form1.top / Screen.TwipsPerPixelY
m_rc.left = Form1.left / Screen.TwipsPerPixelX
m_rc.right = (Form1.left + Form1.Width) / Screen.TwipsPerPixelX

m_lOldProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnSubClass(ByRef hWnd As Long)
SetWindowLong hWnd, GWL_WNDPROC, m_lOldProc
End Sub

Function WindowProc(ByVal hWnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

If uMsg = WM_MOVING Then

Dim rc As RECT
Dim WorkArea As RECT

SystemParametersInfo SPI_GETWORKAREA, ByVal 0&, WorkArea,


ByVal
0&

CopyMemory rc, ByVal lParam, Len(rc)

If (rc.bottom >= WorkArea.bottom) Or _
(rc.left <= WorkArea.left) Or _
(rc.right >= WorkArea.right) Or _
(rc.top <= WorkArea.top) Then
rc = m_rc
Else
m_rc = rc
End If

CopyMemory ByVal lParam, rc, Len(rc)

WindowProc = 0&
Exit Function
End If

WindowProc = CallWindowProc(m_lOldProc, hWnd, uMsg, wParam, lParam)

End Function
'***

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/

Merci de poster les réponses au groupe afin d'en faire profiter à tous
"ThunderMusic" wrote in message
news:etZH%
> Bonjour,
> Je cherche l'évenement qui est déclanché lorsqu'une fenêtre
est
> déplacée. Parce que je sais déjà lorsque la fenetre est redimensionnée
> (Form_Resize), mais je voudrais savoir lorsqu'elle est déplacée. Est-ce
> qu'un tel événement existe en vb6? si oui, lequel? si non, comment


puis-je
> savoir quand la fenêtre a été déplacée?
>
> Merci Beaucoup
>
> ThunderMusic
>
>