Added support for scripting menus, and showing counts for lists, comboboxes, treeviews, listviews

Support for scripting menus and seeing more information about various
list types, and partially working toolbars
This commit is contained in:
Edward Jakubowski
2014-04-19 21:17:35 -04:00
parent dcae627527
commit b5082e2b22
15 changed files with 541 additions and 87 deletions

View File

@@ -129,6 +129,36 @@ public class BaseCommand {
return result;
}
public int findMenuIdWithXpath(String xpath) {
int result = 0;
double secondsFromLastUpdate = ((double)(System.nanoTime() - LAST_UPDATED_XML) / 1000000000);
if (secondsFromLastUpdate > CommandProcessor.XML_UPDATE_THRESHOLD) { //default 5 second threshold
WIN_XML = WindowsEnumeratedXml.getXml();
LAST_UPDATED_XML = System.nanoTime();
}
WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
String resultStr = "";
List<String> resultList = WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
for(String item: resultList) {
if (item.contains("hmenu=")) {
List<String> list = WindowsEnumeratedXml.evaluateXpathGetValues(item, "//@id");
if (list.size() > 0)
resultStr = list.get(0); //get first id;
}
else
resultStr = item;
break;
}
resultStr = resultStr.replaceAll("[^\\d.]", ""); //remove all non-numeric values
//System.out.println("findMenuIdWithXpath: " + resultStr);
if (resultStr.isEmpty())
appendError("Error: Failed to find window handle matching: " + xpath);
else
result = Integer.parseInt(resultStr);
return result;
}
public Point getCenterWindowPosition(WinPtr handle) {
Point p = null;
if (handle.isWin32())

View File

@@ -2,6 +2,9 @@ package org.synthuse.commands;
import org.synthuse.*;
import com.sun.jna.platform.win32.WinDef.LPARAM;
import com.sun.jna.platform.win32.WinDef.WPARAM;
public class WindowsCommands extends BaseCommand {
public WindowsCommands(CommandProcessor cp) {
@@ -108,4 +111,17 @@ public class WindowsCommands extends BaseCommand {
return "";
return api.sendWmGetText(handle.hWnd);
}
public boolean cmdSelectMenu(String[] args) {
if (!checkArgumentLength(args, 1))
return false;
WinPtr handle = findHandleWithXpath(args[0]);
if (handle.isEmpty())
return false;
int id = findMenuIdWithXpath(args[0]);
//LRESULT result =
//System.out.println("PostMessage to " + handle.hWndStr + " for id " + id);
api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0));
return true;
}
}