Solved

minimize by caption

Posted on 1998-10-26
7
342 Views
Last Modified: 2010-04-30

rew = FindWindow(vbNullString, "caption txt")
rew = ShowWindow(rew, SW_SHOWMINNOACTIVE)
 
Why wont this minimize the window caption txt?
That what I need?
0
Comment
Question by:josmic
7 Comments
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1441667
what is "caption txt"
0
 

Author Comment

by:josmic
ID: 1441668
the caption of a window to be minimized
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1441669
What are the declaration used for the API's.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:peterwest
ID: 1441670
Hi,

I've tested the above code and it appears to work ok for me - however, a couple of suggestions.

1) Have you declared the variable rew in your code?  Start by adding the line 'Dim rew As Long' before the API calls.

2) The declarations for the API calls and constants should be as follows (assuming you're using VB5 or 6):

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Const SW_SHOWMINNOACTIVE = 7

3) Look at the results of the first API call by putting a 'Debug.Print rew' command after it.  You should get a value <> 0; if you don't it can't find the window - probably because the window caption is wrong!!

Hope these tips help - let me know how you get on.

Pete


0
 

Author Comment

by:josmic
ID: 1441671
Thanks to all who gave comment

peterwest please answer for points your data helped.

Can I use Findwindow with only partial name of caption,
something like  caption nam*?


0
 
LVL 2

Accepted Solution

by:
peterwest earned 70 total points
ID: 1441672
Hi again,

Thanks - glad to hear it helped.  Just another bit of info - there is no easy way to use FindWindow with only a partial caption - however, here's a routine that i've written that should do the job.  It's not very graceful as it uses a couple of globals to pass the window to search for in and get the hwnd value back out - only way I could do it though.

Ok then - put the following in a module:


-----------------------------------------------------------------

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public sWindowName As String
Public lHwndFound As Long

Public Function FindWindowEnum(ByVal lHwnd As Long, ByVal lParam As Long) As Boolean

    'Declare local variables
    Dim lTitleLength As Long
    Dim sWindowTitle As String
    Dim lRetVal As Long
   
    'Get the length of the caption for the current enumerated window
    lTitleLength = GetWindowTextLength(lHwnd)
   
    'Preinitialise the variable to hold the caption, adding 1 character for
    'the null terminator
    sWindowTitle = Space$(lTitleLength + 1)
   
    'Get the window caption
    lRetVal = GetWindowText(lHwnd, sWindowTitle, lTitleLength + 1)
   
    'If the window caption matches the global window variable then load the
    'hwnd into the global variable and return false to the EnumWindow routine.  This
    'will stop the EnumWindow call from continueing.  Returning True causes
    'it to skip to the next window in the system.
    If sWindowTitle Like sWindowName Then
        lHwndFound = lHwnd
        FindWindowEnum = False
    Else
        FindWindowEnum = True
    End If
   
End Function

Public Function FindWindowLike(sName As String) As Long

    'Declare local variables
    Dim lRetVal As Boolean
   
    'Reset the lHwnd variable
    lHwndFound = 0
   
    'Load the variable into the public variable; this is the only
    'way that it can be accessed by the routine being called from the EnumWindows
    'API call - at least, as far as I know
    sWindowName = sName
   
    'Call the routine to check for a matching window - this is the API bit
    lRetVal = EnumWindows(AddressOf FindWindowEnum, 0)
   
    'Pass the result back to calling routine
    FindWindowLike = lRetVal  
   
End Function

-----------------------------------------------------------------

Then - simply call the function thus-

    'Declare local variables
    Dim lRetVal As Long
   
    'Call the routine - we're looking for a window caption like 'Error*'
    lRetVal = FindWindowLike("Error*")
   
    'If the lRetVal is 0 then a window was found so display the hWnd value
    If lRetVal = 0 Then MsgBox "The hWnd is: " + Str$(lHwndFound)


Remember that this will find ALL windows, including hidden and system windows.  As everything in windows is technically a window it will find all sorts of weird an wonderful things - you can confirm that you've found the correct window by using GetClassName and IsWindow.  Hope this helps.

Pete

0
 

Author Comment

by:josmic
ID: 1441673
Thanks peterwest, that was great.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 90
Child Form in front 4 49
Powerpoint 2013: Change cell reference in excel link 3 85
Collapse and expand table in Word 2010 2 39
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

821 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