 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Zed Gecko
Joined: 23 Sep 2006 Posts: 82
|
Posted: Sun May 11, 2008 4:56 am Post subject: WM_COPYDATA & Tooltip strangeness |
|
|
I got a problem with OnMessage(), SendMessage, WM_COPYDATA and Tooltip.
I was playing around with the WM_COPYDATA-Script from the OnMessage-Help
I modified them to work with PID rather than window-name and made this 2 scripts:
Receiver: | Code: | ;Receiver-Script
PID := DllCall("GetCurrentProcessId")
OnMessage(0x4a, "Receive_WM_COPYDATA")
MsgBox, RecPID := %PID%
return
Receive_WM_COPYDATA(wParam, lParam)
{
Critical
lpDataAddress := lParam + 8
lpData := 0
Loop 4
{
lpData := lpData | (*lpDataAddress << 8 * (A_Index - 1))
lpDataAddress += 1
}
DataLength := DllCall("lstrlen", UInt, lpData)
if DataLength <= 0
ToolTip %A_ScriptName%`nA blank string was received or there was an error.
else
{
VarSetCapacity(CopyOfData, DataLength)
DllCall("lstrcpy", "str", CopyOfData, "uint", lpData)
ToolTip %A_ScriptName%`nReceived the following string:`n%CopyOfData%
}
return true
} |
Sender: | Code: | ;Sender-Script
RecPID := 1596 ;change this according to the MsgBox in the Receiver-Script
Message := 1111
return
^L::
Message += 1
result := Send_WM_COPYDATA(Message, RecPID)
MsgBox, %result%
return
Send_WM_COPYDATA(ByRef Message, ByRef RecPID)
{
VarSetCapacity(CopyDataStruct, 12, 0)
NumPut(StrLen(Message) + 1, CopyDataStruct, 4)
NumPut(&Message, CopyDataStruct, 8)
Prev_DetectHiddenWindows := A_DetectHiddenWindows
Prev_TitleMatchMode := A_TitleMatchMode
DetectHiddenWindows On
SetTitleMatchMode 2
SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_PID%RecPID%
DetectHiddenWindows %Prev_DetectHiddenWindows%
SetTitleMatchMode %Prev_TitleMatchMode%
return ErrorLevel ;
} |
I start the Receiver first, to get its PID and edit the Sender according to this PID, than i start it as well.
When i now press CTRL+L (the sender-Hotkey) once,
the receiver shows a tooltip with the copied data, it got via SendMessage.
After that, any further press of CTRL+L will still start the SendMessage,
but Sendmessage will fail (return 0), and the Receive_WM_COPYDATA-function in the receiver script is not beeing launched at all, so no new copied data will be shown.
Not odd enough,
when i change the Receiver script like this:
Receiver2: | Code: | ;Receiver-Script
PID := DllCall("GetCurrentProcessId")
OnMessage(0x4a, "Receive_WM_COPYDATA")
MsgBox, RecPID := %PID%
return
Receive_WM_COPYDATA(wParam, lParam)
{
Critical
lpDataAddress := lParam + 8
lpData := 0
Loop 4
{
lpData := lpData | (*lpDataAddress << 8 * (A_Index - 1))
lpDataAddress += 1
}
DataLength := DllCall("lstrlen", UInt, lpData)
if DataLength <= 0
ToolTip %A_ScriptName%`nA blank string was received or there was an error.
else
{
VarSetCapacity(CopyOfData, DataLength)
DllCall("lstrcpy", "str", CopyOfData, "uint", lpData)
ToolTip %A_ScriptName%`nReceived the following string:`n%CopyOfData%
sleep, 1000
Tooltip
}
return true
}
|
everything works fine again, I can copy data as many times i like.
So how come, that a Tooltip, that is displayed, prevents the execution of a OnMessage-function?
And how to overcome this?  _________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there... |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Sun May 11, 2008 3:28 pm Post subject: |
|
|
| The function chokes on destroying/recreating the Tooltip, probably because you added a Critical. |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Sun May 11, 2008 4:12 pm Post subject: |
|
|
| Quote: | | The function chokes on destroying/recreating the Tooltip, probably because you added a Critical. | good idea, but no.
The behavior is the same without the Critical.
Actually the Critical was my first try to fix this problem  |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Mon May 12, 2008 3:43 am Post subject: |
|
|
actually any Tooltip, displayed by the script, will prevent the WM_COPYDATA funtion from running.
Receiver3: | Code: | ;Receiver-Script
PID := DllCall("GetCurrentProcessId")
OnMessage(0x4a, "Receive_WM_COPYDATA")
MsgBox, RecPID := %PID%
Tooltip, Waiting
return
Receive_WM_COPYDATA(wParam, lParam)
{
global BCCCopyOfData
lpDataAddress := lParam + 8
lpData := 0
Loop 4
{
lpData := lpData | (*lpDataAddress << 8 * (A_Index - 1))
lpDataAddress += 1
}
DataLength := DllCall("lstrlen", UInt, lpData)
if DataLength <= 0
ToolTip %A_ScriptName%`nA blank string was received or there was an error.
else
{
VarSetCapacity(CopyOfData, DataLength)
DllCall("lstrcpy", "str", CopyOfData, "uint", lpData)
BCCCopyOfData := CopyOfData
SetTimer, DoTooltip, -1000
}
return true
}
DoTooltip:
ToolTip %A_ScriptName%`nReceived the following string:`n%BCCCopyOfData%
; sleep, 1000
; Tooltip
return |
So, BUMP ! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|