Jump to content

Recommended Posts

Posted (edited)

I'm trying to understand why a retrieved handle works and one that is put in from AutoIt v3 Windows Info does not.

The script below illustrates the issue.  Any hint appreciated.  It's got to be something very basic.   My understanding, which may be wrong, is that AutoIt, would type a variable to the correct use.  If this is wrong how do I declare a type to a handle variable type?

;trying to understand handle difference

#AutoIt3Wrapper_run_debug_mode=Y    ;use this to debug in console window <--- LOOK

#include <MsgBoxConstants.au3>
#include <File.au3>

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

;create text file to use
$fpn = _TempFile(@TempDir, "NNN", ".txt", 7)        ;create unique name - already includes full path filename (fpn) into @TempDir
$fn = StringRight($fpn, 14) ;get just filename
_FileCreate($fpn)       ;put it into @Temp directory
Run("Notepad.exe /A " & $fpn)   ;run Notepad
WinWait($fn)        ;substring match set in opt
$hfn = WinGetHandle($fn)    ;get handle
MsgBox($MB_OK + $MB_TOPMOST, "Info", "$hfn = " & $hfn)

$hmanual = InputBox("Input", "Paste in handle from AutoIt v3 Windows Help")

$str = "WinGetHandle = '" & $hfn & "'" & @CRLF & "Manual Input = '" & $hmanual & "'"
MsgBox($MB_OK + $MB_TOPMOST, "Info", $str)

MsgBox($MB_OK + $MB_TOPMOST, "Info", "Flashing window title using handle from WinGetHandle")
WinFlash($hfn)

MsgBox($MB_OK + $MB_TOPMOST, "Info", "Now flashing window title using handle entered by hand")
WinFlash($hmanual)


MsgBox($MB_OK + $MB_TOPMOST, "PAUSE", "Program Paused Before Exit.")

;clean up
WinKill($hfn)   ;close notepad
FileDelete($fpn)    ;delete temp file

Exit

 

Edited by ahha
Posted (edited)

Just show the type of the variables to show the different:

[...]

$str = "WinGetHandle = '" & $hfn & "'" & @CRLF & "Manual Input = '" & $hmanual & "'"
MsgBox($MB_OK + $MB_TOPMOST, "Info", $str)

MsgBox($MB_OK + $MB_TOPMOST, "VarTypes", _
        "Variable Types" & @CRLF & @CRLF & _
        "$hfn     : " & @TAB & @TAB & VarGetType($hfn) & " variable type." & @CRLF & _
        "$hmanual : " & @TAB & @TAB & VarGetType($hmanual) & " variable type." )

MsgBox($MB_OK + $MB_TOPMOST, "Info", "Flashing window title using handle from WinGetHandle")
WinFlash($hfn)

[...]
Edited by ajag

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Posted (edited)

ajag and pixelsearch,

Thanks for both suggestions.  You both are on point. I feel so dumb at times :'(

Edited by ahha

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
×
×
  • Create New...