我编写了以下琐碎的win32gui应用程序:
import win32con, win32api, win32gui, ctypes, ctypes.wintypesclass COPYDATASTRUCT(ctypes.Structure): _fields_ = [ ('dwData', ctypes.wintypes.LPARAM), ('cbData', ctypes.wintypes.DWORD), ('lpData', ctypes.c_void_p) ]PCOPYDATASTRUCT = ctypes.POINTER(COPYDATASTRUCT)class Listener: def __init__(self): message_map = { win32con.WM_COPYdata: self.onCopyData } wc = win32gui.WNDCLASS() wc.lpfnWndProc = message_map wc.lpszClassName = 'MyWindowClass' hinst = wc.hInstance = win32api.GetModuleHandle(None) classAtom = win32gui.RegisterClass(wc) self.hwnd = win32gui.CreateWindow ( classAtom, "win32gui test", 0, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None ) print self.hwnd def onCopyData(self, hwnd, msg, wparam, lparam): print hwnd print msg print wparam print lparam pCDS = ctypes.cast(lparam, PCOPYDATASTRUCT) print pCDS.contents.dwData print pCDS.contents.cbData print ctypes.wstring_at(pCDS.contents.lpData) return 1l = Listener()win32gui.PumpMessages()
然后,我
WM_COPYDATA从另一个应用程序(用Delphi编写)向窗口发送了一条消息:
Text := 'greetings!';CopyData.cbdata:= (Length(Text)+1)*StringElementSize(Text);CopyData.lpdata:= PWideChar(Text);SendMessage(hwnd, WM_COPYDATA, Handle, NativeInt(@CopyData));
输出为:
4615844615847465819026205924222greetings!
因此,它似乎微不足道,就像您编码时一样。
我唯一能想到的是Spotify中的文本
COPYDATASTRUCT不是以空字符结尾的。您应该能够通过读取数据很容易地进行检查。利用该
cbData成员。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)