Solved

How to tell if a window is minimized or not.

Posted on 2004-04-07
9
790 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

23 Experts available now in Live!

Get 1:1 Help Now