Python下Pywin32的使用教程

Python下Pywin32的使用教程,第1张

你可以直接到lib的site-packages下面的win32目录下,有一个demos。另外几个win32开头的目录里也有demos子目录。进去看他们写好的例子。

几个简单的教程:

使用

查询句柄

# 根据类名及标题名查询句柄,

hwnd = win32guiFindWindow("Tfrm_YzzPlayer","叶子猪手游模拟器")

# 查找指定句柄的子句柄,后两个参数为子类的类名与标题,如果没有或不确定,可以写None

hwnd = win32guiFindWindow(hwnd,None,"sub_class","sub_title")

修改窗口大小

# 没有直接修改窗口大小的方式,但可以曲线救国,几个参数分别表示句柄,起始点坐标,宽高度,是否重绘界面 ,如果想改变窗口大小,就必须指定起始点的坐标,没果对起始点坐标没有要求,随便写就可以;如果还想要放在原先的位置,就需要先获取之前的边框位置,再调用该方法即可

win32guiMoveWindow(hwnd,20,20,405,756,True)

前台后台

# 指定句柄设置为前台,也就是激活

win32guiSetForegroundWindow(hwnd)

# 设置为后台

win32guiSetBkMode(hwnd, win32conTRANSPARENT)

我只是给你一些提示,详细的使用方法和说明 ,你还是查下MSDN吧,当然,如果有什么疑问我也乐意给你解答 。

1

lResult = SendMessage( // returns LRESULT in lResult

(HWND) hWndControl, // handle to destination control

(UINT) LVM_GETITEM, // message ID

(WPARAM) wParam, // = 0; not used, must be zero

(LPARAM) lParam // = (LPARAM)

(LPLVITEM) pitem; );

Parameters

wParam

Must be zero

pitem

Pointer to an LVITEM structure that specifies the information to retrieve and receives information about the list-view item

Returns TRUE if successful, or FALSE otherwise

2

lResult = SendMessage( // returns LRESULT in lResult

(HWND) hWndControl, // handle to destination control

(UINT) LVM_SETHOTITEM, // message ID

(WPARAM) wParam, // = (WPARAM) (int) iIndex;

(LPARAM) lParam // = 0; not used, must be zero );

Returns the index of the item that was previously hot

3

lResult = SendMessage( // returns INT in lResult

(HWND) hWndControl, // handle to destination control

(UINT) LVM_GETFOCUSEDGROUP, // message ID

(WPARAM) wParam, // = 0; not used, must be zero

(LPARAM) lParam // = 0; not used, must be zero );

Returns the index of the group with state of LVGS_FOCUSED, or -1 if there is no group with state of LVGS_FOCUSED

import comsunjnaplatformwin32User32;

import comsunjnaplatformwin32WinDefHWND;

public class Demo1 {

public static void main(String[] args) {

name();

}

//窗体句柄的截获

public static void name() {

// HWND hwnd = User32INSTANCEFindWindow(null, "打印");

String zh="打印";

HWND hwndDialog = User32INSTANCEFindWindow(null,zh);

if(hwndDialog==null) {

Systemerrprintln("没有找到窗体");

}else {

Systemerrprintln("找到窗体"+hwndDialog);

//HWND root, String className, long timeout, TimeUnit unit,String caption

// List<HWND> hwndButton= Win32UtilfindHandleByClassNameJKSD(hwndDialog,"Button", 10, TimeUnitSECONDS,"打印");

// for (HWND hwnd : hwndButton) {

// Systemerrprintln(hwnd);

// }

以上就是关于Python下Pywin32的使用教程全部的内容,包括:Python下Pywin32的使用教程、WIN32中列表控件的用法、请问在java中怎么使用jna 获取说有的窗口句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9610262.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存