Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

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
0
RameshKanna
Asked:
RameshKanna
  • 2
  • 2
  • 2
  • +4
1 Solution
 
TimCotteeCommented:
Hi RameshKanna,

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
0
 
CimperialiCommented:
in form_resize() event:
If Me.WindowState=vbMinimized then
    'your code here.
End If
0
 
CimperialiCommented:
Whoops...Came late...! ;-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
RameshKannaAuthor Commented:
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)
0
 
vipulpatelCommented:
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
0
 
CleanupPingCommented:
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.
0
 
vipulpatelCommented:
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.
0
 
CleanupPingCommented:
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?
0
 
GPrentice00Commented:
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
0
 
YensidModCommented:
This question is PAQed and no points refunded (of 20)

YensidMod
Expert Exchange Moderator
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now