?
Solved

how to capture "window minimize event"

Posted on 2003-03-24
10
Medium Priority
?
308 Views
Last Modified: 2007-12-19
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
Comment
Question by:RameshKanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 8194242
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
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8194247
in form_resize() event:
If Me.WindowState=vbMinimized then
    'your code here.
End If
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8194254
Whoops...Came late...! ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RameshKanna
ID: 8194302
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
 

Expert Comment

by:vipulpatel
ID: 8195225
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
 

Expert Comment

by:CleanupPing
ID: 8531746
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
 

Expert Comment

by:vipulpatel
ID: 8542560
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
 

Expert Comment

by:CleanupPing
ID: 8899932
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9441196
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9495960
This question is PAQed and no points refunded (of 20)

YensidMod
Expert Exchange Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question