Solved

How to tell if a window is minimized or not.

Posted on 2004-04-07
9
793 Views
Last Modified: 2008-02-01
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
Comment
Question by:J_K_M_A_N
9 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10779707
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10779708
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10779712
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10779713
Sorry for all the posts, my browser was going crazy.


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:J_K_M_A_N
ID: 10780361
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
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 25 total points
ID: 10780672
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
 
LVL 27

Assisted Solution

by:Ark
Ark earned 25 total points
ID: 10781550
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
 
LVL 3

Author Comment

by:J_K_M_A_N
ID: 10785406
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
 

Expert Comment

by:dassoug
ID: 12383508
It doesnt work for Internet explorer window. What can be the problem. I double checked the title of the web page.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now