Python的Win32Gui自动化 - 发送WM_COPYDATA从BSPlayer获取数据 [英] Python Win32Gui automation - Send WM_COPYDATA to get data from BSPlayer

查看:2720
本文介绍了Python的Win32Gui自动化 - 发送WM_COPYDATA从BSPlayer获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拼命BSPlayer从我的脚本自动化。
我成功地发送简单的命令ID为BSPlayer窗口(音量加/减,播放/暂停等),但我无法得到的文件名后面。

I am desperately trying to automate BSPlayer from my script. I was successful in sending simple command ids to the BSPlayer window(volume up/down, play/pause, etc.), however I am not able to get the file name back.

这里是BSPlayer API。
我能在python效仿第一部分,但是WM_COPYDATA不起作用。

Here is the BSPlayer API. I was able to emulate in python the first parts, however the WM_COPYDATA doesn't work.

下面是我的Python code:

Here is my Python code:

copyDataCmd = COPYDATASTRUCT()
copyDataCmd.dwData = self.BSP_GetFileName
copyDataCmd.lpData = ""
copyDataCmd.cbData = 4                
win32gui.SendMessage(self.playerWindowHandler, win32con.WM_COPYDATA, 
                     ownHandler, copyDataCmd);

显然.lpData返回...

Obviously .lpData returns "" ...

我所试图效仿:

cds:TCOPYDATASTRUCT; 
buf:array[0..MAX_PATH-1] of char; 
adr:pointer; // 
adr:=@buf; 
cds.dwData:=BSP_GetFileName; 
cds.lpData:=@adr; 
cds.cbData:=4; 
SendMessage(bsp_hand,WM_COPYDATA,appHWND,lParam(@cds)); 
// available in BSPlayer version 0.84.484+ // 
// appHWND is calling application window handle 
// File name will be copied to buf // 
// Get open file name 
BSP_GetFileName = $1010B;

要更详细,我试图从一个BSPlayer窗口中的文件名。对于这个,我试图效仿上述code。我希望一些来填充我的期望字符串的缓冲区,但它出现空。
所以,再一次,我要的Python相当于code的正上方。

To be more verbose, I am trying to get the filename from a BSPlayer window. For this I am trying to emulate the code above. I expect a buffer of some sort to be filled with my desired string, but it comes up empty. So, again, I want the Python equivalent of the code just above.

例如这个code已成功效仿:

For example this code was emulated succesfully:

status := SendMessage(bsp_hand,WM_BSP_CMD,BSP_GetStatus,0); 
// available in BSPlayer version 0.84.484+ // 
// Return player status // 0 - STOP // 1 - PAUSE 
// 2 - PLAY // 4 - No movie   open        
BSP_GetStatus = $10102; 

在此先感谢!

推荐答案

您无法复制 WM_COPYDATA 在你的Python code。它只能在进程内使用,例如用于插件。

You cannot replicate that WM_COPYDATA in your Python code. It can only be used in-proc, for example for plugins.

这个例子德尔福code是假设调用 WM_COPYDATA 是从同一个进程,接收消息的窗口进行下写成的。这是因为 WM_COPYDATA 用于复制一个指针和指针只是它分配的内存的进程内有效。你不能跨越进程边界发送一个指针。

The example Delphi code is written under the assumption that the call to WM_COPYDATA is made from the same process as the window which receives the message. That's because the WM_COPYDATA is used to copy a pointer, and pointers are only valid inside the process which allocated the memory. You cannot send a pointer across a process boundary.

在我看来,接口的设计人员滥用 WM_COPYDATA 。它的目的是用来解决进程之间传输的数据的确切的问题。这是最简单最轻薄的进程间通信。为了然后用它来传递一个指针,而失败的过程。

In my opinion, the designers of the interface are abusing WM_COPYDATA. It is meant to be used to solve the exact problem of transferring data between processes. It is the simplest most lightweight inter-process communication available. To then use it to transfer a pointer rather defeats the process.

这篇关于Python的Win32Gui自动化 - 发送WM_COPYDATA从BSPlayer获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆