Il faut exécuter ton code dans l'événement Resize et effectuer un test sur la propriété WindowState.
-- François Picalausa (MVP VB) http://faq.vb.free.fr --- http://msdn.microsoft.com http://apisvb.europe.webmatrixhosting.net
"zorro" a écrit dans le message de news:2926301c464f8$ef195ba0$
Peut-on créer une sub qui s'exécute à l'événement: "minimize d'une form." ( clic sur MinButton ) et comment?
Ce type d'événement n'est pas dans la liste des événements d'une form.
Merci
A+
Zoury
Salut! :O)
Voici deux techniques ..
non APIs, cela perme tde détecté quand le formulaire *à été* réduit '*** ' Form1 Option Explicit
Private m_lOldWindowState As Long
Private Sub Form_Load() m_lOldWindowState = Me.WindowState End Sub
Private Sub Form_Resize() If (m_lOldWindowState <> Me.WindowState) Then If (Me.WindowState = vbMinimized) Then Call MsgBox("la formulaire à été réduit") End If m_lOldWindowState = Me.WindowState End If End Sub '***
APIs, cela permet de déterminer quand le formulaire *sera* réduit et quand il *à été* réduit '*** ' Form1 Option Explicit
Private Sub Form_Load() Call SubClass(Me.hwnd) End Sub
Private Sub Form_Unload(Cancel As Integer) Call UnSubClass(Me.hwnd) End Sub '*** '*** ' Module1 Option Explicit
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 Const WM_SYSCOMMAND As Long = &H112& Private Const WM_MOVE As Long = &H3& Private Const SC_MINIMIZE As Long = &HF020&
Private Const GWL_WNDPROC As Long = -4& Private m_lOldProc As Long
Public Sub SubClass(ByRef hwnd As Long) m_lOldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc) End Sub
Public Sub UnSubClass(ByRef hwnd As Long) Call SetWindowLong(hwnd, GWL_WNDPROC, m_lOldProc) End Sub
Public Function WindowProc _ ( _ ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long _ ) As Long
Static bMinimized As Boolean Select Case uMsg Case WM_SYSCOMMAND If (wParam = SC_MINIMIZE) Then bMinimized = True Call MsgBox("Le formulaire sera réduit") End If Case WM_MOVE If (bMinimized) Then Call MsgBox("Le formulaire à été réduit") bMinimized = False End If End Select
non APIs, cela perme tde détecté quand le formulaire *à été* réduit
'***
' Form1
Option Explicit
Private m_lOldWindowState As Long
Private Sub Form_Load()
m_lOldWindowState = Me.WindowState
End Sub
Private Sub Form_Resize()
If (m_lOldWindowState <> Me.WindowState) Then
If (Me.WindowState = vbMinimized) Then
Call MsgBox("la formulaire à été réduit")
End If
m_lOldWindowState = Me.WindowState
End If
End Sub
'***
APIs, cela permet de déterminer quand le formulaire *sera* réduit et
quand il *à été* réduit
'***
' Form1
Option Explicit
Private Sub Form_Load()
Call SubClass(Me.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnSubClass(Me.hwnd)
End Sub
'***
'***
' Module1
Option Explicit
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 Const WM_SYSCOMMAND As Long = &H112&
Private Const WM_MOVE As Long = &H3&
Private Const SC_MINIMIZE As Long = &HF020&
Private Const GWL_WNDPROC As Long = -4&
Private m_lOldProc As Long
Public Sub SubClass(ByRef hwnd As Long)
m_lOldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnSubClass(ByRef hwnd As Long)
Call SetWindowLong(hwnd, GWL_WNDPROC, m_lOldProc)
End Sub
Public Function WindowProc _
( _
ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long _
) As Long
Static bMinimized As Boolean
Select Case uMsg
Case WM_SYSCOMMAND
If (wParam = SC_MINIMIZE) Then
bMinimized = True
Call MsgBox("Le formulaire sera réduit")
End If
Case WM_MOVE
If (bMinimized) Then
Call MsgBox("Le formulaire à été réduit")
bMinimized = False
End If
End Select
non APIs, cela perme tde détecté quand le formulaire *à été* réduit '*** ' Form1 Option Explicit
Private m_lOldWindowState As Long
Private Sub Form_Load() m_lOldWindowState = Me.WindowState End Sub
Private Sub Form_Resize() If (m_lOldWindowState <> Me.WindowState) Then If (Me.WindowState = vbMinimized) Then Call MsgBox("la formulaire à été réduit") End If m_lOldWindowState = Me.WindowState End If End Sub '***
APIs, cela permet de déterminer quand le formulaire *sera* réduit et quand il *à été* réduit '*** ' Form1 Option Explicit
Private Sub Form_Load() Call SubClass(Me.hwnd) End Sub
Private Sub Form_Unload(Cancel As Integer) Call UnSubClass(Me.hwnd) End Sub '*** '*** ' Module1 Option Explicit
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 Const WM_SYSCOMMAND As Long = &H112& Private Const WM_MOVE As Long = &H3& Private Const SC_MINIMIZE As Long = &HF020&
Private Const GWL_WNDPROC As Long = -4& Private m_lOldProc As Long
Public Sub SubClass(ByRef hwnd As Long) m_lOldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc) End Sub
Public Sub UnSubClass(ByRef hwnd As Long) Call SetWindowLong(hwnd, GWL_WNDPROC, m_lOldProc) End Sub
Public Function WindowProc _ ( _ ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long _ ) As Long
Static bMinimized As Boolean Select Case uMsg Case WM_SYSCOMMAND If (wParam = SC_MINIMIZE) Then bMinimized = True Call MsgBox("Le formulaire sera réduit") End If Case WM_MOVE If (bMinimized) Then Call MsgBox("Le formulaire à été réduit") bMinimized = False End If End Select