How to debug for sending WM_COPYDATA?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
valuex
Junior Member
Junior Member
Posts: 25
Joined: 2014-12-25, 13:53 UTC

How to debug for sending WM_COPYDATA?

Post by *valuex »

I would like to preview the corresponding file when select a cell in Excel.
And have tried to modify the variable's type and value, none of them works.
Modified items:Image: https://i.ibb.co/hfnhX0K/Snipaste-2024-02-03-23-02-01.png
There is no error message and no correct operation excuted by TC.
Got stucked for short function.
Any help would be appreciated.

If there is any method that can get some return value after sending message, that would be helpful.
Here it has been discussed before but seems no progress in this point.
viewtopic.php?t=51249



Setting in usercmd.ini

Code: Select all

cmd=CD
param=D:\SoftX\AHK_Scripts_V2\Lib\
VBA code

Code: Select all

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPtr
        
Public Type CopyDataStruct
    dwData As LongPtr
    cbData As Long
    lpData As LongPtr
End Type
Private Const WM_COPYDATA = &H4A



Sub TC_SendUserCMD()
    Dim UserCMD As String
    UserCMD = "em_focusfile"
    
    Dim cds As CopyDataStruct, result As LongPtr
    Dim hwndTC As LongPtr
    Dim wParam As Long
    wParam = 0
    hwndTC = FindWindow("TTOTAL_CMD", vbNullString)
    
    cds.dwData = Asc("E") + 256 * Asc("M")
    cds.cbData = Len(UserCMD) * 2 + 2  'The size, in bytes
    cds.lpData = StrPtr(UserCMD)
    result = SendMessage(hwndTC, WM_COPYDATA, wParam, cds)
End Sub

Post Reply