Change log:
Version 1.0 dated: 10-Feb-2013 Add ability to send message to XYplorer
Version 2.0 dated: 24-Apr-2013 Add ability to receive message from XYplorer (require XYplorer
12.30.0103)
Version 2.1 dated: 2-Jun-2014 Global Datareceived allow AHK to do more things with the message received from XYplorer
-------------------------
[Part 1: Send message to XYplorer]
If you need to control XYplorer from 3rd party software, Macro made one using AutoIT here: http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9216.
However, I would publish another one using Autohotkey because I'm experienced with this language and can customize/fix bug thouroughly. My code does these things:
+ Send message to XYplorer (such as ::load script.xys)
+ If XYplorer is not running, then run XYplorer, wait for the program to start then send the message
Here is the code:
Code: Select all
#notrayicon
MessagetoXYplorer = %1%
SetTitleMatchMode, 2
Ifwinexist XYplorer ahk_class ThunderRT6FormDC
FunctionMessagetoXYplorer(MessagetoXYplorer)
Else
{
Run E:\7Utilities\XYplorer\XYplorer.exe
winwait, XYplorer ahk_class ThunderRT6FormDC
FunctionMessagetoXYplorer(MessagetoXYplorer)
return
}
FunctionMessagetoXYplorer(MessagetoXYplorer) ;Send message to XYplorer
{
SetTitleMatchMode, 2
HWND := WinExist("XYplorer ahk_class ThunderRT6FormDC")
Size := StrLen(MessagetoXYplorer)
If !(A_IsUnicode)
{
VarSetCapacity(Data, Size * 2, 0)
StrPut(MessagetoXYplorer, &Data, Size, "UTF-16")
}
Else
Data := MessagetoXYplorer
VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
NumPut(4194305, COPYDATA, 0, "Ptr")
NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
SendMessage, 0x4a, 0, ©DATA, , ahk_id %HWND%
}
- Scenario A: You need to pass command-line parameter to XYplorer
+ Modify Run E:\7Utilities\XYplorer\XYplorer.exe
+ Save as .ahk file
+ Compile to exe using attached AHK complier
+ Create a shortcut pointing to the newly created exe with a parameter, which should look like this:
Code: Select all
"C:\path\xyplorer_messenger.exe" ::msg Hello
- Scenario B: The complied exe carries the command itself
+ Modify the second-line-code above to MessagetoXYplorer := "::msg Hello"
+ Save as .ahk file
+ Complied using attached AHK complier
- Scenario C: You need to keep this tiny code running in the background and send message every 0.5 second
+ Save the following code as .ahk file:
Code: Select all
#notrayicon
#Persistent
Settimer, RenameXYplorer, 500
return
RenameXYplorer:
SetTitleMatchMode, 2
Ifwinactive XYplorer ahk_class ThunderRT6FormDC
{
MessagetoXYplorer := "::msg Hello"
HWND := WinExist("XYplorer ahk_class ThunderRT6FormDC")
Size := StrLen(MessagetoXYplorer)
If !(A_IsUnicode)
{
VarSetCapacity(Data, Size * 2, 0)
StrPut(MessagetoXYplorer, &Data, Size, "UTF-16")
}
Else
Data := MessagetoXYplorer
VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
NumPut(4194305, COPYDATA, 0, "Ptr")
NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
SendMessage, 0x4a, 0, ©DATA, , ahk_id %HWND%
}
+ Modify Settimer, RenameXYplorer, 500
+ Complie to exe using attached AHK complier
-------------------------
[Part 2: Receive message from XYplorer]
To receive message from XYplorer (i.e: retrieve full path of <curiem>):
Code: Select all
#notrayicon
SenderHWND := A_ScriptHwnd + 0 ;Return this script's hidden hwdn id. +0 to convert from Hex to Dec
MessagetoXYplorer := "::CopyData " SenderHWND ", ""<curitem>"", 2" ;resolved to sth like this: ::CopyData 7409230, "<curitem>",2
Global Datareceived
OnMessage(0x4a, "Function_Receive_WM_COPYDATA") ; 0x4a is WM_COPYDATA. This onhold and wait for the WM_Copydata from XYplorer then execute Function_Receive_WM_COPYDATA(wParam, lParam) below
FunctionMessagetoXYplorer(MessagetoXYplorer)
msgbox %Datareceived%
FunctionMessagetoXYplorer(MessagetoXYplorer) ;Send message to XYplorer
{
SetTitleMatchMode, 2
HWND := WinExist("XYplorer ahk_class ThunderRT6FormDC")
Size := StrLen(MessagetoXYplorer)
If !(A_IsUnicode)
{
VarSetCapacity(Data, Size * 2, 0)
StrPut(MessagetoXYplorer, &Data, Size, "UTF-16")
}
Else
Data := MessagetoXYplorer
VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
NumPut(4194305, COPYDATA, 0, "Ptr")
NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
SendMessage, 0x4a, 0, ©DATA, , ahk_id %HWND%
}
Function_Receive_WM_COPYDATA(wParam, lParam)
{
StringAddress := NumGet(lParam + 2*A_PtrSize) ;lParam+8 is the address of CopyDataStruct's lpData member.
CopyOfData := StrGet(StringAddress) ;May also specify CP0 (default) or UTF-8 or UTF-16: StrGet(StringAddress, NumGet(lParam+A_PtrSize), "UTF-16")
cbData := NumGet(lParam+A_PtrSize)/2 ;cbData/2 = String length
StringLeft, Datareceived, CopyOfData, cbData
}