python 向其他程序listview发送消息,选中某一行

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 向其他程序listview发送消息,选中某一行相关的知识,希望对你有一定的参考价值。

目前项目要求有一个自动化的控制软件,需要对其他程序的状态控制。要求使用python。尝试了多次很多的功能都可以实现,选中指定某一行非常困难。希望得到帮助。

procedure ListViewOperator.SetItemSelected(nItemIndex: Integer ); //选中某一个ITEM
var
lvitem: LVITEM; // 静态结构
nRet: Integer;
hRet: HRESULT;
begin
lvitem.mask := LVIF_STATE;
lvitem.iSubItem := 0;
lvitem.state := LVIS_SELECTED or LVIS_FOCUSED;
lvitem.stateMask := LVIS_SELECTED or LVIS_FOCUSED;

nRet := WriteProcessMemory( m_hProcess, m_pLVItem, @lvitem, sizeof(LVITEM), Nil); // 将本地进程中的结构写入到目标进程
Assert( (nRet == 0), 'Write Process memory failed' );

hRet := SendMessage( m_hwnd, LVM_SETITEMSTATE, WPARAM(nItemIndex), LPARAM(m_pLVItem) );//发送消息
Assert( FAILED(hRet), 'Send message failed' );

end;追问

需要python版本的,这个答案以及在网络上看过了。

参考技术A 状态控制,编码用python 参考技术B 具体一点,说明白详细要求, 参考技术C 没有问题我帮你。追问

有完全的Python代码?不要调用其他语言的?

如何在python中从客户端向服务器发送消息

【中文标题】如何在python中从客户端向服务器发送消息【英文标题】:How to send a message from client to server in python 【发布时间】:2016-09-10 15:56:45 【问题描述】:

我正在阅读带有客户端和服务器的 Python 2.7.10 中的两个程序。如何修改这些程序以便将消息从客户端发送到服务器?

server.py:

#!/usr/bin/python           # This is server.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.
s.bind((host, port))        # Bind to the port

s.listen(5)                 # Now wait for client connection.
while True:
   c, addr = s.accept()     # Establish connection with client.
   print 'Got connection from', addr
   c.send('Thank you for connecting')
   c.close()                # Close the connection

client.py:

#!/usr/bin/python           # This is client.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 80              # Reserve a port for your service.

s.connect((host, port))
print s.recv(1024)
s.close                     # Close the socket when done

【问题讨论】:

【参考方案1】:

TCP 套接字是双向的。所以,连接后,服务器和客户端没有区别,你只有一个流的两端:

import socket               # Import socket module

s = socket.socket()         # Create a socket object
s.bind(('0.0.0.0', 12345))        # Bind to the port

s.listen(5)                 # Now wait for client connection.
while True:
   c, addr = s.accept()     # Establish connection with client.
   print 'Got connection from', addr
   print c.recv(1024)
   c.close()                # Close the connection

和客户:

import socket               # Import socket module

s = socket.socket()         # Create a socket object
s.connect(('localhost', 12345))
s.sendall('Here I am!')
s.close()                     # Close the socket when done

【讨论】:

【参考方案2】:

以上答案抛出错误:TypeError: a bytes-like object is required, not 'str' 但是,以下代码对我有用:

server.py

import socket
import sys

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 3125
s.bind(('0.0.0.0', port))
print ('Socket binded to port 3125')
s.listen(3)
print ('socket is listening')

while True:
    c, addr = s.accept()
    print ('Got connection from ', addr)
    print (c.recv(1024))
    c.close()

client.py:

import socket

s = socket.socket()
port = 3125
s.connect(('localhost', port))
z = 'Your string'
s.sendall(z.encode())    
s.close()

【讨论】:

以上是关于python 向其他程序listview发送消息,选中某一行的主要内容,如果未能解决你的问题,请参考以下文章

关于 使用python向qq好友发送消息(对爬虫的作用----当程序执行完毕或者报错无限给自己qq发送消息,直到关闭)

Python:通过 cog 和后台任务向 Discord 中的特定频道发送消息

更改任何模型字段时如何向其他网页发送警报消息

通过命令行向程序发送消息

python Socket.IO 客户端,用于向 TornadIO2 服务器发送广播消息

向所有连接的客户端/资源发送 xmpp 消息