Code: Select all
#Requires AutoHotkey v2.0.2
; Get our own HWND (we have no visible window)
DetectHiddenWindows(true)
G_OwnHWND := WinExist("Ahk_PID " DllCall("GetCurrentProcessId"))
G_OwnHWND += 0
global dataReceived := ""
; Get messages back from XYplorer
OnMessage(0x4a, Receive_WM_COPYDATA)
allTabs := XYGetAllTab()
if(!allTabs)
{
msgbox "XYplorer is not running!"
exitApp
}
;==================================================================================================
; Gui
;==================================================================================================
; Create the MyGui window:
MyGui := Gui("+Resize", "Untitled") ; Make the window resizable.
Edit1 := MyGui.Add("Edit", , StrSplit(allTabs, "|")[1])
Edit2 := MyGui.Add("Edit", "vMyEdit r5", StrSplit(allTabs, "|")[2]) ; r5 means 5 rows tall.
Btn := MyGui.Add("Button", "default xm", "OK") ; xm puts it at the bottom left corner.
Btn.OnEvent("Click", ProcessUserInput)
; Apply events:
MyGui.OnEvent("Close", ProcessUserInput)
MyGui.OnEvent("Escape", ProcessUserInput)
MyGui.OnEvent("Size", Gui_Size)
Edit1.OnEvent("Focus", Ctrl_Focus)
Edit2.OnEvent("Focus", Ctrl_Focus)
MyGui.Opt("AlwaysOnTop")
MyGui.Show()
; Size and Positon
Edit2.GetPos(, , &w2, &h2)
if(w2 < 500)
Edit2.Move(, , 800)
Edit1.GetPos(, , &w, &h)
Edit1.Move(, , w2)
;Btn.GetPos(&Bx, &By)
Btn.Move(, h+h2+20, 80, 30)
;MyGui.GetPos(,, &Gw, &Gh)
MyGui.Move(, , w+w2+22, h+h2+100)
Gui_Size(thisGui, MinMax, Width, Height)
{
if MinMax = -1 ; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
Edit1.Move(,, Width-23)
Edit2.Move(,, Width-23, Height-80)
Btn.Move(, Height-38)
}
; Refresh values
Ctrl_Focus(GuiCtrlObj, Info)
{
allTabs := XYGetAllTab()
Edit1.value := StrSplit(allTabs, "|")[1]
Edit2.value := StrSplit(allTabs, "|")[2]
}
ProcessUserInput(*)
{
Saved := MyGui.Submit() ; Save the contents of named controls into an object.
;MsgBox("You entered:`n" Saved.MyEdit)
exitApp
}
;==================================================================================================
; XYplorer Send and Get functions
;==================================================================================================
F1::
{
allTabs := XYGetAllTab()
path := XYGetPath()
all := XYGetAll()
sel := XYGetSelected()
MsgBox path
MsgBox all
MsgBox sel
MsgBox allTabs
return
}
XYGetAllTab()
{
return XY_Get(true, true)
}
XYGetPath()
{
return XY_Get()
}
XYGetAll()
{
return XY_Get(true)
}
XYGetSelected()
{
return XY_Get(, true)
}
XY_Get(bAll:=false, bSelection:=false)
{
xyQueryScript := '::if (!' bAll ' && !' bSelection ') {$return = "<curpath>"`;} elseif (' bAll '&&' bSelection ') {$return = <curpath> . "|" . get("tabs", "<crlf>", "1") . "<crlf>" . get("tabs", "<crlf>", "2")`;} elseif (' bAll ') {$return = listpane(, , , "<crlf>")`;} elseif (' bSelection ') {$return = get("SelectedItemsPathNames", "<crlf>")`;} copydata ' G_OwnHWND ', "$return", 2`;'
Send_WM_COPYDATA(xyQueryScript)
return dataReceived
}
GetXYHWND() {
static xyClass := 'ahk_class ThunderRT6FormDC'
if hwnd := WinActive(xyClass)
return hwnd
else if WinExist(xyClass)
return WinGetList(xyClass)[1]
}
Send_WM_COPYDATA(message) {
xyHwnd := GetXYHWND()
if !(xyHwnd)
return
size := StrLen(message)
if !(StrLen(Chr(0xFFFF))) {
data := Buffer(size * 2, 0)
StrPut(message, &data, size, "UTF-16")
} else {
data := message
}
COPYDATA := Buffer(A_PtrSize * 3)
NumPut("Ptr", 4194305, COPYDATA, 0)
NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
NumPut("Ptr", StrPtr(data), COPYDATA, A_PtrSize * 2)
return DllCall("User32.dll\SendMessageW", "Ptr", xyHwnd, "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "Ptr")
}
Receive_WM_COPYDATA(wParam, lParam, *) {
global dataReceived := StrGet(
NumGet(lParam + 2 * A_PtrSize, 'Ptr'), ; COPYDATASTRUCT.lpData, ptr to a str presumably
NumGet(lParam + A_PtrSize, 'UInt') / 2 ; COPYDATASTRUCT.cbData, count bytes of lpData, /2 to get count chars in unicode str
)
}
Modify the Gui according to your needs.