[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

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
0
J_K_M_A_N
Asked:
J_K_M_A_N
2 Solutions
 
BrianGEFF719Commented:
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
0
 
BrianGEFF719Commented:
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
0
 
BrianGEFF719Commented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
BrianGEFF719Commented:
Sorry for all the posts, my browser was going crazy.


0
 
J_K_M_A_NAuthor Commented:
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
0
 
zzzzzoocCommented:
Below will maximize notepad and give it focus. It'll depend on the window caption "Untitled - Notepad" which you can change..

Form1:
=========

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Sub Form_Load()
    Dim lHandle As Long
    lHandle = FindWindow(vbNullString, "Untitled - Notepad")
    Call ShowWindow(lHandle, 3)
    Call SetForegroundWindow(lHandle)
End Sub
0
 
ArkCommented:
If you have handle, you can do anything :)

lHandle = FindWindow(vbNullString, "Untitled - Notepad") 'stolen from above samples :)
PostMessage(lHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
0
 
J_K_M_A_NAuthor Commented:
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
0
 
dassougCommented:
It doesnt work for Internet explorer window. What can be the problem. I double checked the title of the web page.
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now