Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

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?
0
josmic
Asked:
josmic
1 Solution
 
TheAnswerManCommented:
what is "caption txt"
0
 
josmicAuthor Commented:
the caption of a window to be minimized
0
 
MirkwoodCommented:
What are the declaration used for the API's.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
peterwestCommented:
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
 
josmicAuthor Commented:
Thanks peterwest, that was great.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now