Jump to content

SciTE-DirectorExtension: Solve problem with several SciTe instances


BugFix
 Share

Recommended Posts

There is an issue, while using the function SendSciTE_Command by @Jos, if more than one instance of SciTE is open. Each instance of SciTE has its own DirectorExtension window, so we must choose the right one.

Here is a way to solve this:

; by BugFix
Func _GetHwndDirectorExtension()
    Local $hActive = WinGetHandle('[ACTIVE]')
    Local $PIDActive = WinGetProcess($hActive)
    Local $aExtension = WinList("DirectorExtension")
    Local $PIDExt
    For $i = 1 To $aExtension[0][0]
        $PIDExt = WinGetProcess($aExtension[$i][1])
        If $PIDExt = $PIDActive Then Return $aExtension[$i][1]
    Next
EndFunc

; by Jos
Func SendSciTE_Command($_sCmd) 
    Local $WM_COPYDATA = 74
    Local $WM_GETTEXT = 0x000D
    Local $WM_GETTEXTLENGTH = 0x000E224
    Local Const $SCI_GETLINE = 2153
;~     Local $Scite_hwnd = WinGetHandle("DirectorExtension") ; Get SciTE DIrector Handle
    Local $Scite_hwnd = _GetHwndDirectorExtension() ; Get SciTE DIrector Handle
    Local $My_Hwnd = GUICreate("AutoIt3-SciTE interface") ; Create GUI to receive SciTE info
    Local $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) ; Convert my Gui Handle to decimal
    $_sCmd = ":" & $My_Dec_Hwnd & ":" & $_sCmd              ; Add dec my gui handle to commandline to tell SciTE where to send the return info
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($_sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $_sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($_sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
            'Ptr', DllStructGetPtr($COPYDATA))
    GUIDelete($My_Hwnd)
EndFunc   ;==>SendSciTE_Command

Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    Local $SciTECmdLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char[' & $SciTECmdLen+1 & ']',DllStructGetData($COPYDATA, 3))
;~  Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
EndFunc   ;==>MY_WM_COPYDATA

 

Best Regards BugFix  

Link to comment
Share on other sites

  • 5 weeks later...

A little safer is ...

; by BugFix
Func _GetHwndDirectorExtension()
    Local $hActive = WinGetHandle('[ACTIVE]')
    If _WinAPI_GetClassName($hActive) <> 'SciTEWindow' Then $hActive = WinGetHandle('[CLASS:SciTEWindow]') ; Determine the last active SciTeWindow.
    If IsHWnd($hActive) Then
        Local $PIDActive = WinGetProcess($hActive), $aExtension = WinList("DirectorExtension"), $PIDExt
        For $i = 1 To $aExtension[0][0]
            $PIDExt = WinGetProcess($aExtension[$i][1])
            If $PIDExt = $PIDActive Then Return $aExtension[$i][1]
        Next
    EndIf
    Return SetError(1, 0, False)
EndFunc  ;==>_GetHwndDirectorExtension

 

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

×
×
  • Create New...