Solved

How to tell if a window is minimized or not.

Posted on 2004-04-07
9
796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

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


0
 
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 28

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 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