MRU with ahk

Discuss and share scripts and script files...
Post Reply
binocular222
Posts: 1423
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

MRU with ahk

Post by binocular222 »

An Autohotkey script to open list of files recently opened-by-XYplorer, even when XYplorer window is not actived

Code: Select all

#SingleInstance force
#NoEnv
#notrayicon
Settitlematchmode, 2

;^+r::    ;Uncomment this line to enable keyboard shortcut Ctrl+Shift+R

SenderHWND := A_ScriptHwnd + 0  ;Return this script's hidden hwdn id.  +0 to convert from Hex to Dec
MessagetoXYplorer := "::CopyData " SenderHWND ", get(""list_recentlyopenedfiles""), 2"    ;resolved to sth like this:   ::CopyData 7409230, "get("list_recentlyopenedfiles")",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)

Loop, Parse, Datareceived, `n, `r`n
{
	Menu, MRUmenu, Add, %A_LoopField%, MenuHandler
	;↓ Add icons↓
	SplitPath, A_LoopField,,,FileExtension
	if (FileExtension = "exe")
		IconPath := A_LoopField
	Else if (FileExtension != "exe")
		IconPath := AssocQueryApp(FileExtension)
	Try    Menu, MRUmenu, Icon, %A_LoopField%, %IconPath%,1
	Catch
		{
		if(FileExtension in exe,bat)
			Menu, MRUmenu, Icon, %A_LoopField%, shell32.dll,3
		else
			Menu, MRUmenu, Icon, %A_LoopField%, shell32.dll,1
		}
	If(A_Index > 8)
		break
}
Menu, MRUmenu, Show
return

MenuHandler:
Run, %A_ThisMenuItem%
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, &COPYDATA, , 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 = String length
	StringLeft, Datareceived, CopyOfData, cbData
}

AssocQueryApp(ext) {
	RegRead, type, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%Ext%, Application
	If !ErrorLevel { ;Current user has overridden default setting
		RegRead, act, HKCU, Software\Classes\Applications\%type%\shell
		If ErrorLevel
			act = open
		RegRead, cmd, HKCU, Software\Classes\Applications\%type%\shell\%act%\command
		}
	Else {           ;Default setting
		RegRead, type, HKCR, .%Ext%
		RegRead, act , HKCR, %type%\shell
		If ErrorLevel
			act = open
	RegRead, cmd , HKCR, %type%\shell\%act%\command
	If ErrorLevel
		RegRead, cmd , HKCR, .%ext%\ShellNew, ItemName
	EXEPosition := InStr(cmd,".exe",false,0,1)
	exepath := LTrim(Trim(SubStr(cmd,1,EXEPosition+3),""""),"@")
}
 Return, exepath
}
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: MRU with ahk

Post by klownboy »

Thanks binocular222, this will be very useful for obtaining the MRU or other listings in XY. We can "get" quite a few things. :appl:

Post Reply