Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is much easier to do with ctypes. This code has been tested with a simple Delphi application that receives and displays the string that is sent via <code>WM_COPYDATA</code>.</p> <pre><code>import win32con import ctypes import ctypes.wintypes FindWindow = ctypes.windll.user32.FindWindowW SendMessage = ctypes.windll.user32.SendMessageW class COPYDATASTRUCT(ctypes.Structure): _fields_ = [ ('dwData', ctypes.wintypes.LPARAM), ('cbData', ctypes.wintypes.DWORD), ('lpData', ctypes.c_wchar_p) #formally lpData is c_void_p, but we do it this way for convenience ] hwnd = FindWindow('TheNameOfMyWindowClass', None) cds = COPYDATASTRUCT() cds.dwData = 0 str = 'boo' cds.cbData = ctypes.sizeof(ctypes.create_unicode_buffer(str)) cds.lpData = ctypes.c_wchar_p(str) SendMessage(hwnd, win32con.WM_COPYDATA, 0, ctypes.byref(cds)) </code></pre> <p>This assumes that the recipient expects a UTF-16 encoded payload. If the recipient is expecting ANSI encoded payload then you need to use this variant.</p> <pre><code>import win32con import ctypes import ctypes.wintypes FindWindow = ctypes.windll.user32.FindWindowW SendMessage = ctypes.windll.user32.SendMessageW class COPYDATASTRUCT(ctypes.Structure): _fields_ = [ ('dwData', ctypes.wintypes.LPARAM), ('cbData', ctypes.wintypes.DWORD), ('lpData', ctypes.c_char_p) #formally lpData is c_void_p, but we do it this way for convenience ] hwnd = FindWindow('TheNameOfMyWindowClass', None) cds = COPYDATASTRUCT() cds.dwData = 0 str = b'boo' cds.cbData = ctypes.sizeof(ctypes.create_string_buffer(str)) cds.lpData = ctypes.c_char_p(str) SendMessage(hwnd, win32con.WM_COPYDATA, 0, ctypes.byref(cds)) </code></pre> <hr> <p>Now, looking at the Stickies link that you posted, you need to use the ANSI variant. If you want to receive notification, you'll need to pass a window handle in you SendMessage call instead of 0 as above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload