Solved

minimize by caption

Posted on 1998-10-26
7
341 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

832 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