我试图在python 3.5中处理mspaint.exe,但它不起作用。
这是我所做的过程以及我无法做到的事情:
我能做什么:
这是我目前的代码
获取句柄功能:
# trying to get handle with title parameter
def get_window_hwnd(title):
hwnd = False
list = enum_window_titles();
for a in list:
if title.lower() in a.lower() :
print(a.lower()) # untitled - paint
hwnd = win32gui.FindWindow(None, title)
print(hwnd) # return 0
return hwnd
return hwnd
列出windows函数:
#list all windows list
def enum_window_titles():
def callback(handle, data):
titles.append(win32gui.GetWindowText(handle))
titles = []
win32gui.EnumWindows(callback, None)
return titles
过程的一部分:
# core
hwnd = -1
hwnd = get_window_hwnd("paint") # get handle window
print(hwnd) # 0
if(hwnd != -1 or hwnd != False): # enter here
a = win32api.SendMessage(hwnd, win32con.WM_MOUSEMOVE, 0, win32api.MAKELONG(200, 200));
b = win32api.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON,0);
c = win32api.SendMessage(hwnd, win32con.WM_MOUSEMOVE, 0, win32api.MAKELONG(400, 400));
d = win32api.PostMessage(hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,0);
print(a); #
print(b);
print(c);
print(d);
完整的打印结果:
untitled - paint
0
0
# here is the Post Message and Send Message
0
None
0
None
任何想法为什么我无法处理我的mspaint?
还有什么想法知道句柄是否像PostMessage和SendMessage之后一样工作?
谢谢
答案 0 :(得分:1)
窗口的名称为new_klass = Class.new ActiveRecord::Base do
cattr_accessor :model_name
self.abstract_class = false
self.table_name = "items"
validate do
errors.add :base, "not good"
end
end
> instance = new_klass.new
> instance.valid?
=> false
> instance.errors.full_messages
=> ["not good"]
,但您将"Untitled - Paint"
传递给"paint"
。如果要打电话给FindWindow
,您需要传递正确的窗口名称。这样称呼:
FindWindow
然而,调用win32gui.FindWindow(None, a)
没有意义。当您致电FindWindow
时,您的回调会收到窗口句柄。请记住窗口句柄以及名称。这样,一旦找到匹配的名称,您就可以使用句柄了。像这样:
EnumWindows