AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WM_COPYDATA & Tooltip strangeness

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Zed Gecko



Joined: 23 Sep 2006
Posts: 82

PostPosted: Sun May 11, 2008 4:56 am    Post subject: WM_COPYDATA & Tooltip strangeness Reply with quote

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?
Question
_________________
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
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Sun May 11, 2008 3:28 pm    Post subject: Reply with quote

The function chokes on destroying/recreating the Tooltip, probably because you added a Critical.
Back to top
Z Gecko
Guest





PostPosted: Sun May 11, 2008 4:12 pm    Post subject: Reply with quote

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 Confused
Back to top
Z Gecko
Guest





PostPosted: Mon May 12, 2008 3:43 am    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group