minimize by caption


rew = FindWindow(vbNullString, "caption txt")
rew = ShowWindow(rew, SW_SHOWMINNOACTIVE)
 
Why wont this minimize the window caption txt?
That what I need?
josmicAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
peterwestConnect With a Mentor Commented:
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
 
TheAnswerManCommented:
what is "caption txt"
0
 
josmicAuthor Commented:
the caption of a window to be minimized
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
MirkwoodCommented:
What are the declaration used for the API's.
0
 
peterwestCommented:
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
 
josmicAuthor Commented:
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
 
josmicAuthor Commented:
Thanks peterwest, that was great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.