selenium测试用JNAUtils2

// 设置窗口最大化
	public static void setMAX(HWND hwnd) {
		if (hwnd == null)
			return;
		while (!isMax(hwnd)) {
			System.out.println("尝试窗口最大化");
			User32.INSTANCE.ShowWindow(hwnd, User32.SW_MAXIMIZE);
		}
		while (!hwnd.equals(getACtiveHwnd())) {
			System.out.println("设焦点");
			User32.INSTANCE.SetForegroundWindow(hwnd);
		}
	}

	public static boolean isMin(HWND hwnd) {
		if (hwnd == null)
			return false;
		RECT rf = getWindowRect(hwnd); // 返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕坐标左上角的屏幕坐标给出。
		if (rf.right < 0 || rf.bottom < 0)
			return true;
		return false;
	}
public static boolean isMax(HWND hwnd) {
		if (hwnd == null)
			return false;
		RECT rf = getWindowRect(hwnd);
		if (rf.left < 0 && rf.top < 0)
			return true;
		return false;
	}

	// 由窗体句柄得到位置信息
	public static RECT getWindowRect(HWND hwnd) {
		if (hwnd == null)
			return null;
		RECT rf = new RECT();
		User32.INSTANCE.GetWindowRect(hwnd, rf);
		return rf;
	}

	// 判断坐标(x,y)是否在rf内
	public static boolean inItem(int x, int y, RECT rf) {
		if (rf.right < 0 || rf.bottom < 0)
			return false;
		if (x < rf.left || x > rf.right || y < rf.top || y > rf.bottom)
			return false;
		return true;
	}
// 判断点是否rf内
	public static boolean inItem(Point mousepoint, RECT rf) {
		return inItem(mousepoint.x, mousepoint.y, rf);
	}

	// 由句柄获取窗口名称
	public static String getTitle(HWND hwnd) {
		if (hwnd == null)
			return null;
		char[] sTitle = new char[255];
		User32.INSTANCE.GetWindowText(hwnd, sTitle, 255);
		String title = char2String(sTitle);
		return title;
	}

	// 获取当前聚焦的窗体的句柄
	public static HWND getACtiveHwnd() {
		HWND hwnd = User32.INSTANCE.GetForegroundWindow();
		return hwnd;
	}
// 获取当期鼠标位置
	public static Point getPoint() {
		Point mousepoint = MouseInfo.getPointerInfo().getLocation();
		return mousepoint;
	}

	// 获取鼠标所在该控件
	public static List<HWND> getCurrentItem() {
		HWND window = JNAUtils.getACtiveHwnd();
		List<HWND> hs = JNAUtils.getItems(window);
		List<HWND> hwnds = new ArrayList<HWND>();
		for (HWND h : hs) {
			RECT rf = JNAUtils.getWindowRect(h);
			Point mousepoint = JNAUtils.getPoint();
			if (JNAUtils.inItem(mousepoint, rf)) {
				hwnds.add(h);
			}
		}
		return hwnds;
	}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值