Link to home
Start Free TrialLog in
Avatar of J_K_M_A_N
J_K_M_A_N

asked on

How to tell if a window is minimized or not.

I am making a program that is used for sendkeys. I can appactivate the window I want but it does't actually type if the window is minimized. Is there a way I can check if it is minimized? The code is posted below. I am not using notepad. It is just there for example. Thanks.

J_K_M_A_N


Private Sub LoadInfo_Click()

AppActivate ("Untitled - Notepad")

' I need to check here if it is minimized or not. If not, the keys will not be sent right.

SendKeys Field1.Text
SendKeys "{tab}"
SendKeys Field2.Text
SendKeys "{tab}"
SendKeys Field3.Text
SendKeys "{tab}"
SendKeys Field4.Text
SendKeys "{tab}"
SendKeys Field5.Text

End Sub
Avatar of BrianGEFF719
BrianGEFF719
Flag of United States of America image

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function IsIconic Lib "user32" (ByVal HWND As Long) As Long
Private Declare Function IsZoomed Lib "user32" (ByVal HWND As Long) As Long

Public Function IsNotePadNormal() As Boolean
Dim HWND As Long
HWND = FindWindow(vbNullString, "Untitled - Notepad")
If HWND = 0 Then
    IsNotePadNormal = False
    Exit Function
End If
If IsIconic(HWND) <> 0 Then
   IsNotePadNormal = False
End If
If IsZoomed(HWND) <> 0 Then
   IsNotePadNormal = True
End If
If IsIconic(HWND) = 0 And IsZoomed(HWND) = 0 Then
 IsNotePadNormal = True
End If
End Function
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function IsIconic Lib "user32" (ByVal HWND As Long) As Long
Private Declare Function IsZoomed Lib "user32" (ByVal HWND As Long) As Long

Public Function IsNotePadNormal() As Boolean
Dim HWND As Long
HWND = FindWindow(vbNullString, "Untitled - Notepad")
If HWND = 0 Then
    IsNotePadNormal = False
    Exit Function
End If
If IsIconic(HWND) <> 0 Then
   IsNotePadNormal = False
End If
If IsZoomed(HWND) <> 0 Then
   IsNotePadNormal = True
End If
If IsIconic(HWND) = 0 And IsZoomed(HWND) = 0 Then
 IsNotePadNormal = True
End If
End Function
put this code in a module:



Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function IsIconic Lib "user32" (ByVal HWND As Long) As Long
Private Declare Function IsZoomed Lib "user32" (ByVal HWND As Long) As Long

Public Function IsNotePadNormal() As Boolean
Dim HWND As Long
HWND = FindWindow(vbNullString, "Untitled - Notepad")
If HWND = 0 Then
    IsNotePadNormal = False
    Exit Function
End If
If IsIconic(HWND) <> 0 Then
   IsNotePadNormal = False
End If
If IsZoomed(HWND) <> 0 Then
   IsNotePadNormal = True
End If
If IsIconic(HWND) = 0 And IsZoomed(HWND) = 0 Then
 IsNotePadNormal = True
End If
End Function





now use this code:


AppActivate ("Untitled - Notepad")
if isnotepadnormal = true then
SendKeys Field1.Text
SendKeys "{tab}"
SendKeys Field2.Text
SendKeys "{tab}"
SendKeys Field3.Text
SendKeys "{tab}"
SendKeys Field4.Text
SendKeys "{tab}"
SendKeys Field5.Text
end if




Good Luck
-Brian
Sorry for all the posts, my browser was going crazy.


Avatar of J_K_M_A_N
J_K_M_A_N

ASKER

Well, I haven't tried it yet but, is there a way I could maximize it if it is minimized? I would like to set the window o active and make sure it is maximized. Not just not send keys if minimized. Also, what is the IsNotePadNormal refering to? The program I am trying to send keys to is not notepad. I was just using that as a reference. I am not yet sure what the name of the window is actually. It is some software that we are going to purchase. Thanks for the help.

J_K_M_A_N
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you. When we get our software next week I will try it and Accept and Grade then. Thanks again.

J_K_M_A_N
It doesnt work for Internet explorer window. What can be the problem. I double checked the title of the web page.