Sign in to follow this  
Followers 0
crashdemons

YahELite Extension Example

3 posts in this topic

#1 ·  Posted (edited)

Let me start by saying that I didn't see anything like this integrated into the ChatLion project, as it mostly just interfaces with the YahELite GUI, itself.

This is a very basic example of passing a command from YahELite to an extension program, written in AutoIt, and back. (Uses COPYDATA messages to transfer a signature, ReplyHWnd and a string for commands)

Posted Image

Screenshot

To Use:

1. Start YahELite.

2. Start the Example Program

3. Copy the "/extend ..." line from the Example to YahELite's text and command input and hit enter

4. Confirm YahELite outputs the text "Extension Active"

5. type a random "/ex CommandName Parameters..." line and see if a debug line of text gets printed on the screen.

- - - the occurrence of a debug line shows that the script can receive a COPYDATA message from YahELite, process it in a preferred manner (Preferred manner choice by the user-definable _YHLT_ExtProcess($cmd,$param) ) and then fire back a COPYDATA message to YahELite, containing a command to run, without having to interface with the input control (although, I must click the send button in YahELite)

Link to YahELite Forum thread on same topic

YHLT_Extension_Example.au3 (Note: feel free to edit this for your own needs!)

#Include "YHLTExt.inc.au3"
;-------EXAMPLE-----
$YHLT_GUI=GUICreate("My Extension",200,60)
GUICtrlCreateInput("/extend ExtClass ExtTitle",0,00,200,20)
GUICtrlCreateInput("/ex Command Parameters...",0,20,200,20)
GUISetState (@SW_HIDE,$YHLT_GUI)
If Not YHLT_RegisterExtension($YHLT_GUI,'ExtClass','ExtTitle') Then
    MsgBox(0,'My Extension','Sorry, There was an error registering this extension.')
    Exit
EndIf
GUISetState (@SW_SHOW,$YHLT_GUI)
While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
                ExitLoop
    EndSwitch
WEnd
Exit
Func _YHLT_ExtProcess($c,$p); (strCommand, strParameters)
    ; this is a required function by the Extesion functions for command processing
    YHLT_SendTo("/emit "&@ScriptName&" Debug - Command: '"&$c&"' - Param: '"&$p&"'")
EndFunc


;######### END OF FILE ###################

YHLTExt.inc.au3 (Functions and Constants needed for the extension to occur)

#Include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
;-------------------
Global Const $_YHLT_Send=4537
Global Const $CS_VREDRAW = 1
Global Const $CS_HREDRAW = 2
;Global Const $IDI_APPLICATION = 32512
Global Const $CW_USEDEFAULT = 0x80000000
Global $YHLT_ExtendProc=0
Global $YHLT_hwndReplyTo=0
Global $YHLT_YahELiteExt=0
Global $YHLT_ExtGUI=0
Global $YHLT_ExtFunc="_YHLT_ExtProcess";($strCommand, $strParams)
Func YHLT_SendTo($String)
    Return YHLT_ReplyTo($YHLT_hwndReplyTo,$String)
EndFunc
Func YHLT_ReplyTo($hwndReplyTo, $String);bool
    Global $YHLT_YahELiteExt
    If Not (WinExists($hwndReplyTo) Or StringInStr(_WinAPI_GetClassName($hwndReplyTo),'YahELite:class',2)) Then Return False
    _Send_CopyData($YHLT_ExtGUI,$hwndReplyTo, $YHLT_YahELiteExt,$String)
    PostButtonclick($hwndReplyTo, $_YHLT_Send)
    Return True
EndFunc
Func YHLT_oncopyData($dlg, $id, $hwndReplyTo, $pcds);bool
    Global $YHLT_hwndReplyTo;
    Global $YHLT_YahELiteExt
    $hwndReplyTo=HWnd($hwndReplyTo)
    $YHLT_hwndReplyTo=$hwndReplyTo
    ConsoleWrite('+>WM_COPYDATA'&@CRLF)
    ConsoleWrite('  dlg:'&@TAB&$dlg&@CRLF)
    ConsoleWrite('  id:'&@TAB&$id&@CRLF)
    ConsoleWrite('  hwndReplyTo:'&@TAB&$hwndReplyTo&@CRLF)
    ConsoleWrite('  pcds:'&@TAB&$pcds&@CRLF)
    Local $Data
    Local $dw
    _Read_CopyData($pcds, $dw, $Data)
    If Not ($dw==$YHLT_YahELiteExt) Then Return False
    
    Local $Command=$Data
    Local $Parms=""
    
    Local $Len=StringLen($Data)
    Local $fspace=StringInStr($Data,' ')
    If $fspace>0 And $fspace<$Len Then
        $Command=StringMid($Data,1,$fspace-1)
        $Parms=StringMid($Data,$fspace+1)
    EndIf
    
    
    Call($YHLT_ExtFunc,$Command,$Parms); call the Extension's own processing function (defined later)
    
    Return True
EndFunc
Func YHLT_WndProc($hWnd, $uMsg, $wParam, $lParam)
    Switch $uMsg
        Case $WM_COPYDATA
            Return YHLT_oncopyData($hWnd, $uMsg, $wParam, $lParam)
        Case Else
            Return _WinAPI_DefWindowProc($hWnd, $uMsg, $wParam, $lParam); Set default window processing
    EndSwitch
    Return 0
EndFunc




Func YHLT_RegisterExtension($Parent,$Class,$Title)
    Global $YHLT_ExtendProc
    Global $YHLT_YahELiteExt
    Global $YHLT_ExtGUI
    $YHLT_YahELiteExt=_WinAPI_RegisterWindowMessage('WM_YahELiteExt')
    If $YHLT_YahELiteExt>0 Then
        If Not _RegisterClass($Class, $YHLT_ExtendProc, "YHLT_WndProc") Then Return 0
        $YHLT_ExtGUI=_WinAPI_CreateWindowEx(0,$Class,$Title,0,$CW_USEDEFAULT,$CW_USEDEFAULT,$CW_USEDEFAULT,$CW_USEDEFAULT,$Parent,0,_WinAPI_GetModuleHandle(""))
        _WinAPI_ShowWindow($YHLT_ExtGUI,@SW_HIDE)
    EndIf
    Return $YHLT_YahELiteExt
EndFunc
Func YHLT_UnRegisterExtension($Class); - Don't Use this, it doesn't work
    Global $YHLT_ExtendProc
    GUIDelete($YHLT_ExtGUI)
    _UnregisterClass($Class,$YHLT_ExtendProc)
EndFunc




Func _Read_CopyData($Ptr,Byref $Signature, ByRef $Data)
    Local $stcCOPYDATA = "dword dwData;dword cbData;ptr lpData"
    Local $sCDS=DllStructCreate($stcCOPYDATA,$Ptr)
    Local $dwData=DllStructGetData($sCDS,'dwData')
    Local $cbData=DllStructGetData($sCDS,'cbData')
    Local $lpData=DllStructGetData($sCDS,'lpData')
    $Signature=$dwData
    Local $stcData=DllStructCreate('char Data['&int($cbData)&']',$lpData)
    $Data=DllStructGetData($stcData,'Data')
    ConsoleWrite('~CDS Debug~'&@CRLF)
    ConsoleWrite('  dwData '&$dwData&@CRLF)
    ConsoleWrite('  cbData '&$cbData&@CRLF)
    ConsoleWrite('  lpData '&$lpData&@CRLF)
    ConsoleWrite('    Data '&$Data&@CRLF)
EndFunc
Func _Send_CopyData($hWndFrom, $hWndTo, ByRef $Signature, ByRef $Data)
    Local $stcCOPYDATA = "dword dwData;dword cbData;ptr lpData"
    Local $sCDS=DllStructCreate($stcCOPYDATA)
    Local $dwData=$Signature
    Local $cbData=StringLen($Data)
        Local $stcData=DllStructCreate('char Data['&int($cbData)+1&']')
        DllStructSetData($stcData,'Data',$Data)
    Local $lpData=DllStructGetPtr($stcData)
    DllStructSetData($sCDS,'dwData',$dwData)
    DllStructSetData($sCDS,'cbData',$cbData)
    DllStructSetData($sCDS,'lpData',$lpData)
;---CopyData Struct created
    $Ptr=DllStructGetPtr($sCDS)
    _SendMessageA($hWndTo,$WM_COPYDATA,$hWndFrom,$Ptr)
    ConsoleWrite('Sent '&$Data&' to '&$hwndTo&@CRLF)
    _Read_CopyData($Ptr,$Signature,$Data)
EndFunc
Func PostButtonclick($hWnd, $nCtrlID)
    DllCall("user32.dll", "int", "PostMessage", _
            "hwnd", $hWnd, _
            "int", $WM_COMMAND, _
            "int", BitAND($nCtrlID, 0x0000FFFF), _
            "hwnd", GUICtrlGetHandle($nCtrlID))
EndFunc;==>PostButtonclick
;amel27 - UDF to create and register our class
Func _RegisterClass($sClassName, ByRef $hWndProc,$sHWndProc)
; selecting icons and cursors (there is many choices)
;Local $aIcon = DllCall("user32.dll", "hwnd", "LoadIcon", "hwnd", 0, "int", $IDI_APPLICATION)
;Local $aCursor = DllCall("user32.dll", "hwnd", "LoadCursor", "hwnd", 0, "int", 0);$IDC_ARROW)
; Registering window processing as CallBack-function
    $hWndProc = DLLCallbackRegister ($sHWndProc, "int", "hwnd;int;wparam;lparam")
;Creating and initializing class structures
    Local $tWndClassEx = DllStructCreate("uint cbSize;uint style;ptr lpfnWndProc;int cbClsExtra;int cbWndExtra;hwnd hInstance;hwnd hIcon;hwnd hCursor;hwnd hbrBackground;ptr lpszMenuName;ptr lpszClassName;hwnd hIconSm")
    Local $tClassName = DllStructCreate("char["& StringLen($sClassName)+1 &"]")
    DllStructSetData($tClassName, 1, $sClassName)

    DllStructSetData($tWndClassEx, "cbSize", DllStructGetSize($tWndClassEx) )
    DllStructSetData($tWndClassEx, "style", BitOR($CS_VREDRAW, $CS_HREDRAW) )
    DllStructSetData($tWndClassEx, "lpfnWndProc", DllCallbackGetPtr($hWndProc))
    DllStructSetData($tWndClassEx, "hInstance", _WinAPI_GetModuleHandle(""))
;DllStructSetData($tWndClassEx, "hIcon", $aIcon[0])
;DllStructSetData($tWndClassEx, "hCursor", $aCursor[0])
    DllStructSetData($tWndClassEx, "hbrBackground", _WinAPI_GetStockObject($WHITE_BRUSH))
    DllStructSetData($tWndClassEx, "lpszClassName", DllStructGetPtr($tClassName))
;DllStructSetData($tWndClassEx, "hIconSm", $aIcon[0])
; Registering process
    Local $aRet = DllCall("user32.dll", "dword", "RegisterClassExA", "ptr", DllStructGetPtr($tWndClassEx) )
    Return $aRet[0]
EndFunc
Func _UnregisterClass($sClassName, ByRef $hWndProc)
    DllCallbackFree($hWndProc)
    Local $aRet = DllCall("user32.dll", "int", "UnregisterClassA", "str", $sClassName, "hwnd", _WinAPI_GetModuleHandle(""))
    Return $aRet[0]
EndFunc 

;######### END OF FILE ###################

Citations:

--UDF Includes:

-------WinAPI.au3

-------WindowsConstants.au3

-------GUIConstants.au3

--Other:

-------Amel27? - _RegisterClass($sClassName, ByRef $hWndProc,$sHWndProc)

-------Unknown Author - PostButtonclick($hWnd, $nCtrlID)

Notes:

- Tested with Au3.2.12.1

- I edited this post twice, let me know if the [ AutoIt ] block gets corrupted.

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.)

Share this post


Link to post
Share on other sites



Nice!

I made Chat Lion, and have been thinking about rebuilding it since I lost all of my source files to my almost complete version.

This should come in real handy!


It is really sad to see a family torn apart by something as simple as a pack of wolves.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You might also find this useful, It could be cleaned up minorly - but for now it does exactly what needs to be done.

This script extracts the YahELite /command list (even unlisted commands such as /func and /dbg etc...) and saves it to cmd.txt in the current folder. (Good to see if something changes between versions)

There's also probably a more technical way of doing this (... yeah.), but the command list is just null-delimited once decompressed.

The program relies on Zoom being the last command and Act being on the first command - this of course, may be subject to change.

$upx=_ProgramLocate('upx.exe','C:\Program Files\AutoIt3\Aut2Exe',True)
$yhlt=_ProgramLocate('yahelite.exe','C:\Program Files\yahelite',False,False)
$outfile=@ScriptDir&"\cmd.txt"
$firstCmd="zoom"
$lastCmd="act"

$null=Chr(0)
$yhltmp=@ScriptDir&"\_yhltTmp.exe"
FileCopy($yhlt,$yhltmp,1)
Sleep(500)
ShellExecuteWait($upx,'-d "'&$yhltmp&'"');  decompress temp copy of YahELite
Sleep(500)

$d=FileReadFull($yhltmp)
FileDelete($yhltmp)
$start=StringInStr($d,$null&$firstCmd&$null,1)
$end=StringInStr($d,$null&$lastCmd&$null,1)+StringLen($lastCmd)+1
$count=$end-$start+1
$d=StringMid($d,$start,$count)



;$d=FileReadFull($file)
$d=StringReplace($d,$null,@CRLF)

;Clean up below cleaning...
$d=StringReplace($d,@CRLF&@CRLF,@CRLF)
$d=StringReplace($d,@CRLF&@CRLF,@CRLF)
$d=StringReplace($d,@CRLF&@CRLF,@CRLF)

$d=StringReplace($d,@CRLF&@LF,@CRLF)
$d=StringReplace($d,@CRLF&@LF,@CRLF)
$d=StringReplace($d,@CRLF&@LF,@CRLF)

$d=StringReplace($d,@CR&@CRLF,@CRLF)
$d=StringReplace($d,@CR&@CRLF,@CRLF)
$d=StringReplace($d,@CR&@CRLF,@CRLF)



FileOverwrite($outfile,$d)
$d=''





Func _ProgramLocate($filename,$dir=@ScriptDir,$LocalTest=false,$AutoCheck=True)
    If $LocalTest Then
        ShellExecuteWait($filename)
        If @error==0 Then Return $filename
    EndIf
    Local $locat=$dir&'\'&$filename
    Local $found=false
    If $AutoCheck Then
        If FileExists($locat) Then $found=true
    EndIf
    While (Not $found)
        If 2==MsgBox(64+1,"File Needed...","This program requires the following file: "&@CRLF&" "&$filename&@CRLF&@CRLF&"Press OK to select an equivalent file.") Then Exit
        $locat=FileOpenDialog("Find "&$filename&" ...",$dir,"All Files (*.*)",1,$filename)
        $found=true
        If @error>0 Then Exit;$found=false
    WEnd
    Return $locat
EndFunc
Func FileReadFull($file)
    $fh = FileOpen($file, 16)
    $d = BinaryToString(FileRead($fh))
    FileClose($fh)
    Return $d
EndFunc ;==>FileReadFull
Func FileOverwrite($file, $data)
    $fh = FileOpen($file, 2 + 16)
    $d = FileWrite($fh, StringToBinary($data))
    FileClose($fh)
    Return $d
EndFunc ;==>FileOverwrite
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.)

Share this post


Link to post
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
Sign in to follow this  
Followers 0