Jump to content

Converting hwnd to int (long)


4nt1h4cker
 Share

Recommended Posts

Hi,

i want to convert a window handle in int (long), currently i use a little tricky dllstruct.

Is there any way do do this better (a hex to int function)?

; #FUNCTION#;===============================================================================
;
; Name...........: _SpeechDisyplayUI
; Description ...: Creats a UI
; Syntax.........: _SpeechDisplayUI (ByRef $oSpeech, $hWndParent , $sTitle, $sTypeOfUI, $vExtraData = 0)
; Parameters ....: $oSpeech - Speech COM Object
;                  $hWndParent - Specifies the window handle of the owning window
;                  $sTitle - Specifies the caption used for the UI window
;                  $sTypeOfUI - A String specifying the name of the UI to display ($SPDUI_AddRemoveWord...)
;                  $vExtraData - Optional: Specifies the ExtraData
; Return values .: Success - 1
;                 Failure - Returns 0 and Sets @Error:
;                  |1 - $oSpeech is not a COM Object
;                  |2 - $hWndParent is not a Hwnd
;                  |3 - $sTitle is not a String
;                  |4 - $sTypeOfUI is not a String
;                  |5 - $sTypeOfUI is not supported
; Author ........: Tom Schuster
; Modified.......:
; Remarks .......:
; Related .......: 
; Link ..........;
; Example .......; No
;
;;==========================================================================================
func _SpeechDisplayUI (ByRef $oSpeech, $hWndParent , $sTitle, $sTypeOfUI, $vExtraData = 0)
    Local $vDllStruct, $vReturn
    if not IsObj ( $oSpeech ) Then
        Return SetError (1,0,0)
    EndIf
    if not IsHWnd ( $hWndParent ) Then
        Return SetError (2,0,0)
    EndIf
    if not IsString ( $sTitle ) Then
        Return SetError (3,0,0)
    EndIf
    if not IsString ( $sTypeOfUI ) then
        Return SetError (4,0,0)
    EndIf
    if not $oSpeech.IsUISupported ( $sTypeOfUi ) Then
        Return SetError (5,0,0)
    EndIf
;A little bit tricky 
    $vDllStruct = DllStructCreate ( "long windowhandle")
    DllStructSetData ($vDllStruct, "windowhandle", $hWndParent)
    $oSpeech.DisplayUI ( DllStructGetData ( $vDllStruct, "windowhandle"), $sTitle, $sTypeOfUi, $vExtraData )
    Return 1
EndFunc;==>_SpeechDisyplayUI
Link to comment
Share on other sites

Hi,

i want to convert a window handle in int (long), currently i use a little tricky dllstruct.

Is there any way do do this better (a hex to int function)?

; #FUNCTION#;===============================================================================
;
; Name...........: _SpeechDisyplayUI
; Description ...: Creats a UI
; Syntax.........: _SpeechDisplayUI (ByRef $oSpeech, $hWndParent , $sTitle, $sTypeOfUI, $vExtraData = 0)
; Parameters ....: $oSpeech - Speech COM Object
;                  $hWndParent - Specifies the window handle of the owning window
;                  $sTitle - Specifies the caption used for the UI window
;                  $sTypeOfUI - A String specifying the name of the UI to display ($SPDUI_AddRemoveWord...)
;                  $vExtraData - Optional: Specifies the ExtraData
; Return values .: Success - 1
;                 Failure - Returns 0 and Sets @Error:
;                  |1 - $oSpeech is not a COM Object
;                  |2 - $hWndParent is not a Hwnd
;                  |3 - $sTitle is not a String
;                  |4 - $sTypeOfUI is not a String
;                  |5 - $sTypeOfUI is not supported
; Author ........: Tom Schuster
; Modified.......:
; Remarks .......:
; Related .......: 
; Link ..........;
; Example .......; No
;
;;==========================================================================================
func _SpeechDisplayUI (ByRef $oSpeech, $hWndParent , $sTitle, $sTypeOfUI, $vExtraData = 0)
    Local $vDllStruct, $vReturn
    if not IsObj ( $oSpeech ) Then
        Return SetError (1,0,0)
    EndIf
    if not IsHWnd ( $hWndParent ) Then
        Return SetError (2,0,0)
    EndIf
    if not IsString ( $sTitle ) Then
        Return SetError (3,0,0)
    EndIf
    if not IsString ( $sTypeOfUI ) then
        Return SetError (4,0,0)
    EndIf
    if not $oSpeech.IsUISupported ( $sTypeOfUi ) Then
        Return SetError (5,0,0)
    EndIf
;A little bit tricky 
    $vDllStruct = DllStructCreate ( "long windowhandle")
    DllStructSetData ($vDllStruct, "windowhandle", $hWndParent)
    $oSpeech.DisplayUI ( DllStructGetData ( $vDllStruct, "windowhandle"), $sTitle, $sTypeOfUi, $vExtraData )
    Return 1
EndFunc;==>_SpeechDisyplayUI
AutoIt's variant for a handle does not work as an input to Int(), but does for String(), then it can input to Int():
; Get handle to active window
$hActive = WinGetHandle("")
ConsoleWrite("$hActive = " & $hActive & @LF)

; Convert to string
$sActive = String($hActive)
ConsoleWrite("$sActive = " & $sActive & @LF)

; Convert to integer
$iActive = Int($sActive)
ConsoleWrite("$iActive = " & $iActive & @LF)

; Convert back to handle
$hActive = HWnd($iActive)
ConsoleWrite("$hActive = " & $hActive & @LF)

; Test the handle
$sTitle = WinGetTitle($hActive)
ConsoleWrite("$sTitle = " & $sTitle & @LF)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...