different code for maximize and minimize?

Happy YN

Registered User.
Local time
Today, 06:46
Joined
Jan 27, 2002
Messages
425
I have code which runs on the forms resize event. However I only want it to run when maximized not when minimized. Any way to trap this?
Thanks
 
Real quick and off hand...the best way I can think of do this successfully is to use a Windows API function. The IsZoomed() API function to be exact and it's really quite simple.

First you will need to Declare the Function and you will need to Declare it in a Database code module(not a Form code module). While we're at it we might as well the IsIconic API function as well so as to detect when the Form is Minimized (you never know when that may come in handy):

Code:
Public Declare Function IsZoomed Lib "User32" (ByVal hWnd As Long) As Integer
Public Declare Function IsIconic Lib "User32" (ByVal hWnd As Long) As Integer

Next, just use an IF statement in the Form's OnResize event (where you have been coding anyways) similar to what is shown below:

Code:
Private Sub Form_Resize()
  Dim a$
  [COLOR="DarkGreen"]'Let us know when Form is Maximized...[/COLOR]
  If CBool(IsZoomed(Me.hWnd)) = True Then a$ = "It's Maximized"

[COLOR="DarkGreen"]  'Let us know when Form is Minimized...[/COLOR]
  If CBool(IsIconic(Me.hWnd)) = True Then a$ = "It's Minimized!"
  If a$ <> "" Then MsgBox a$
End Sub

I think you get the picture :)

.
 
Thanks! will test it out
If it works - its just what I needed:)
Thanks again
 
You can actually simplify that a little bit by declaring the functions as Boolean in the first place, thereby avoiding the conversion to Boolean (CBool).

Code:
Public Declare Function IsZoomed Lib "User32" (ByVal hWnd As Long) As [COLOR="red"]Boolean[/COLOR]
Public Declare Function IsIconic Lib "User32" (ByVal hWnd As Long) As [COLOR="Red"]Boolean[/COLOR]

Then:

Code:
Private Sub Form_Resize()

  Dim strA As String

  If IsZoomed(Me.hWnd) Then strA = "It's Maximized"
  If IsIconic(Me.hWnd) Then strA = "It's Minimized"
  If strA <> "" Then MsgBox strA

End Sub

One less step never hurts. :)
 

Users who are viewing this thread

Back
Top Bottom