Jump to content

_API_FindWindow_2


Recommended Posts

I wouldve posted in Example Scripts if the forum would let me...

Anyway, I feel this may be helpful for someone....

I noticed that the Auto3Lib _API_FindWindow() function didnt support Null title (I saw this option used in VB scripts)

and that it only exported as hwnd and not long...

Now, the documentation for the original function SAYS that if the title is blank it will match all titles, however i could not get this to work.....

So, to help myself and make a couple of my own scripts easier I added the features.

Syntax for the below code:

_API_FindWindow_2 ( $sClassName [, $sReturn [, $sWindowName] ] )

$sClassName A string that specifies the class name...

$sReturn Optional: Set Return Type

0 for hwnd return value (default)

1 for long return value

$sWindowName Optional: A string that specifies the window name.

If $sWindowName equals a float with a value of -1 or is exluded will default to a VB-style null

which WILL match all titles and get the find the window based on the ClassName alone.

Return Types

HWND or LONG (user-specified)

Global $vbNullString = chr(0)
Func _API_FindWindow_2($sClassName, $sReturn=0, $sWindowName=-1)
    Dim $sWindowName
    Dim $sReturn
    Global $vbNullString
    Local $sWindNameType
    
    $sWindNameType="str"
    If $sReturn==0 Then $sReturn="hwnd"
    If $sReturn==1 Then $sReturn="long"
    If $sWindowName==-1 Then
        $sWindowName=$vbNullString
        $sWindNameType="ptr"
    EndIf
  Local $aResult

  $aResult = DllCall("User32.dll", $sReturn, "FindWindow", "str", $sClassName, $sWindNameType, $sWindowName)
  Return $aResult[0]
EndFunc
Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

  • Moderators

Func _WinFindByClass($sClassName, $sReturn = 0)
    Local $bWTMM = Opt('WinTitleMatchMode', 4)
    Local $hWnd = WinGetHandle('classname=' & $sClassName)
    Opt('WinTitleMatchMode', $bWTMM)
    If $sReturn Then Return Execute($hWnd)
    Return $hWnd
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

_API_FindWindowEx_2 ( $hParent , $hChildAfter, $className [ , $sReturn [ , $wTitle ] ] )

$hParent - Handle of parent window

$hChildAfter - Handle of child window

$className - String specifying a class name

$sReturn - Optional: Return Type

0 (default) specifies hWnd return

1 specifies Long return

$wTitle - String specifying a window title

-1 will pass a Vb-type null matching all window titles (default)

Return:

HWND or LONG (user-specified)

Global $vbNullString = chr(0)
Func _API_FindWindowEx_2($hParent, $hChildAfter, $className, $sReturn=0, $wTitle=-1)
    Dim $wTitle
    Dim $sReturn
    Global $vbNullString
    
    $sWindNameType="str"
    If $sReturn==0 Then $sReturn="hwnd"
    If $sReturn==1 Then $sReturn="long"
    If $wTitle==-1 Then
        $wTitle=$vbNullString
        $sWindNameType="ptr"
    EndIf
        
  Local $aResult
  $aResult = DllCall("User32.dll", $sReturn, "FindWindowEx", "hwnd", $hParent, "hwnd",$hChildAfter, "str", $className, $sWindNameType, $wTitle)
  Return $aResult[0]
EndFunc

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...