1) My working AHK_L (unicode or ansi) WM_COPYData version.
--- I'll likely merge it with my existing TC_SendWMCopyData that does EM's and CDs. They're nearly identical... yet it still had me stumped for a while!
2) Frank8244's WM_COPYData GUI Example.
C++ and other examples in other posts below.
[Original Post]
I can't seem to get a return value with the new WM_COPYDATA feature...
This is my old one - which can send CD and EM's as per the WIKI's info on TCUtils.cpp.
Code: Select all
;;
;; AutoHotkey_L Function
;; cmdType: "CD" or "EM"
;; cmd(1): name of user command, e.g. em_FOO
;; cmd(2): formatted string with path's to CD to,
;; e.g. "C:\`rC:\Users"
;; addParams: for CD only, e.g. ST, S, T
TC_SendWMCopyData( cmdType, byRef cmd, byRef addParams="", aWin="A" )
{
Critical
VarSetCapacity( CopyDataStruct, A_PtrSize * 3 )
if( A_IsUnicode )
{
VarSetCapacity( cmdA, StrPut(cmd, "cp0"))
Loop, % StrLen(cmd)
NumPut( Asc(SubStr(cmd, A_Index, 1)), cmdA, A_Index - 1, "Char")
}
NumPut( Asc(SubStr(cmdType,1,1)) + 256 * Asc(SubStr(cmdType,2,1)), CopyDataStruct )
NumPut( StrLen(cmd) + (cmdType="CD" ? 5 : 1), CopyDataStruct, A_PtrSize )
NumPut((A_IsUnicode ? &cmdA : &cmd), CopyDataStruct, A_PtrSize * 2)
Loop, % (cmdType=="CD" ? 2 : 0)
NumPut( Asc(SubStr(addParams, A_Index, 1)), (A_IsUnicode ? cmdA : cmd), (StrLen(cmd) + A_Index), "Char" )
SendMessage, 0x4A,, &CopyDataStruct,, ahk_id %aWin%
return
}
Code: Select all
TC_EMC( cmd, wID="ahk_class TTOTAL_CMD", activateWin=FALSE, showMsg=FALSE )
{
TC_Activate( wID, activateWin, showMsg, cmd )
TC_SendWMCopyData( "EM", cmd, params:="", wID )
return
}
TC_CD@( wID, src="", trg="", params="", activateWin=TRUE )
{
if( activateWin )
WinActivate, % ( wID+0 ? "ahk_id " wID : wID )
TC_SendWMCopyData( "CD", cmd:=(src " `r" trg " "), params, wID )
return
}
TC_Activate( byRef wID, activateWin=TRUE, showMsg=TRUE, cmd="" )
{
wID:=QueryWinID(wID, TRUE)
if(!activateWin )
return FALSE
if( showMsg )
MsgBox,,%A_ThisFunc%, % "Activating TC" ( cmd ? ", for command: " cmd "`n" : "`n"), 1
WinActivate, ahk_id %wID%
return TRUE
}
QueryWinID( aWin="A", canExist=FALSE, winText="", notTitle="", notText="" )
{
if( !(retVal:=WinActiveA( aWin, winText, notTitle, notText )) )
retVal:=( !canExist ? 0 : WinExistA( aWin, winText, notTitle, notText ))
return retVal
}
WinActiveA( aWin="", winText="", notTitle="", notText="" )
{
return WinActive( (aWin+0 ? "ahk_id " aWin : aWin), winText, notTitle, notText )
}
WinExistA( aWin="", winText="", notTitle="", notText="" )
{
return WinExist( (aWin+0 ? "ahk_id " aWin : aWin), winText, notTitle, notText )
}