RameshKanna
asked on
how to capture "window minimize event"
I would like to fire an activity when the application window is being minimized. (ie, on clicking the "-" button in window state control box in the right top of any window)
note : I am using MDI form
Rameshkanna
note : I am using MDI form
Rameshkanna
in form_resize() event:
If Me.WindowState=vbMinimized then
'your code here.
End If
If Me.WindowState=vbMinimized
'your code here.
End If
Whoops...Came late...! ;-)
ASKER
i would like to fire my code when the minimize button is being clicked.(windowstate , which can be attained after the minimized button is clicked)
Hi RameshKanna,
Try This Code
bye
Vipul Patel.
Dim Minimized As Boolean
Public Sub Form_Resize()
If Me.WindowState = vbMinimized And Not Minimized Then
Me.WindowState = vbNormal
Minimized = True
Me.WindowState = vbMinimized
'
'Your Code Here.
'
Else
Minimized = False
End If
End Sub
Try This Code
bye
Vipul Patel.
Dim Minimized As Boolean
Public Sub Form_Resize()
If Me.WindowState = vbMinimized And Not Minimized Then
Me.WindowState = vbNormal
Minimized = True
Me.WindowState = vbMinimized
'
'Your Code Here.
'
Else
Minimized = False
End If
End Sub
Hi RameshKanna,
This old question (QID 20560760) needs to be finalized -- accept an answer, split points, or get a refund. Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
This old question (QID 20560760) needs to be finalized -- accept an answer, split points, or get a refund. Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
Hi RameshKanna,
copy this code in MDIForm
Option Explicit
Private Const GWL_WNDPROC As Long = (-4&)
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _
( _
ByVal hWnd&, _
ByVal nIndex&, _
ByVal dwNewLong& _
)
Private Sub MDIForm_Load()
procOld = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
Call SetWindowLong(Me.hWnd, GWL_WNDPROC, procOld)
End Sub
Private Sub MDIForm_Resize()
If MDIForm1.WindowState = 1 Then
MsgBox "Minimized"
End If
End Sub
'And copy this code in a Module
Option Explicit
Type POINTAPI
x As Long
y As Long
End Type
Public Const WM_GETMINMAXINFO As Long = &H24
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Public procOld As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
( _
lpDest As Any, _
lpSource As Any, _
ByVal cBytes& _
)
Public Declare Function CallWindowProc& Lib "user32" Alias "CallWindowProcA" _
( _
ByVal lpPrevWndFunc&, _
ByVal hWnd&, _
ByVal Msg&, _
ByVal wParam&, _
ByVal lParam& _
)
'WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!!
'
' Do NOT try to step through this function in debug mode!!!!
' You WILL crash!!! Also, do NOT set any break points in this function!!!
' You WILL crash!!!
'
'WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!!
Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_GETMINMAXINFO
WindowProc = False
If MDIForm1.WindowState = 1 Then
MsgBox "Being Minimized"
'
'Your Code Here.
'
End If
Exit Function
End Select
WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
End Function
Bye
Vipul Patel.
copy this code in MDIForm
Option Explicit
Private Const GWL_WNDPROC As Long = (-4&)
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _
( _
ByVal hWnd&, _
ByVal nIndex&, _
ByVal dwNewLong& _
)
Private Sub MDIForm_Load()
procOld = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
Call SetWindowLong(Me.hWnd, GWL_WNDPROC, procOld)
End Sub
Private Sub MDIForm_Resize()
If MDIForm1.WindowState = 1 Then
MsgBox "Minimized"
End If
End Sub
'And copy this code in a Module
Option Explicit
Type POINTAPI
x As Long
y As Long
End Type
Public Const WM_GETMINMAXINFO As Long = &H24
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Public procOld As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
( _
lpDest As Any, _
lpSource As Any, _
ByVal cBytes& _
)
Public Declare Function CallWindowProc& Lib "user32" Alias "CallWindowProcA" _
( _
ByVal lpPrevWndFunc&, _
ByVal hWnd&, _
ByVal Msg&, _
ByVal wParam&, _
ByVal lParam& _
)
'WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!!
'
' Do NOT try to step through this function in debug mode!!!!
' You WILL crash!!! Also, do NOT set any break points in this function!!!
' You WILL crash!!!
'
'WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!!
Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_GETMINMAXINFO
WindowProc = False
If MDIForm1.WindowState = 1 Then
MsgBox "Being Minimized"
'
'Your Code Here.
'
End If
Exit Function
End Select
WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
End Function
Bye
Vipul Patel.
RameshKanna:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
-->PAQ - no points refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER
GPrentice00
Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
-->PAQ - no points refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER
GPrentice00
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to place this in the MDIForm_Resize() event:
Private Sub MDIForm_Resize()
If Me.WindowState = vbMinimized Then
'Do Something
End If
End Sub
Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk
Brainbench MVP for Visual Basic
http://www.brainbench.com
Experts-Exchange Advisory Board Member