Solved

minimize by caption

Posted on 1998-10-26
7
339 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now