From 405b63ca86450da0e0f047b86138e6dec16e5ca3 Mon Sep 17 00:00:00 2001 From: Edward Jakubowski Date: Fri, 20 Jun 2014 19:59:43 -0400 Subject: [PATCH] Added Percent and Carrot special keys sendKeys, take screen shot command, select list index command --- src/org/synthuse/Api.java | 237 ++++++++++++++---- src/org/synthuse/CommandPopupMenu.java | 12 + src/org/synthuse/CommandProcessor.java | 17 +- src/org/synthuse/MessageHookFrame.java | 10 +- src/org/synthuse/RobotMacro.java | 8 + src/org/synthuse/SynthuseDlg.java | 10 +- src/org/synthuse/WindowInfo.java | 34 +-- src/org/synthuse/WindowsEnumeratedXml.java | 6 +- src/org/synthuse/XpathManager.java | 4 +- src/org/synthuse/commands/MainCommands.java | 34 ++- .../synthuse/commands/WindowsCommands.java | 20 +- src/org/synthuse/test/WinApiTest.java | 26 +- 12 files changed, 328 insertions(+), 90 deletions(-) diff --git a/src/org/synthuse/Api.java b/src/org/synthuse/Api.java index 231e4db..3a66602 100644 --- a/src/org/synthuse/Api.java +++ b/src/org/synthuse/Api.java @@ -12,13 +12,18 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import javax.swing.JOptionPane; + +import org.synthuse.Api.WinDefEx.*; import com.sun.jna.Callback; +import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.platform.win32.WinDef.*; import com.sun.jna.platform.win32.Advapi32Util; import com.sun.jna.platform.win32.BaseTSD.LONG_PTR; +import com.sun.jna.platform.win32.BaseTSD.SIZE_T; import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR; import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO; import com.sun.jna.platform.win32.WinDef; @@ -81,6 +86,8 @@ public class Api { public static int PROCESS_QUERY_INFORMATION = 0x0400; public static int PROCESS_VM_READ = 0x0010; + public static int PROCESS_VM_WRITE = 0x0020; + public static int PROCESS_VM_OPERATION = 0x0008; public static int PS_SOLID = 0x0; public static int PS_DASH = 0x1; @@ -111,8 +118,18 @@ public class Api { public static int LVM_GETITEMCOUNT = LVM_FIRST + 4; public static int LVM_GETITEM = LVM_FIRST + 75; public static int LVIF_TEXT = 0x0001; + public static int LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50); + public static int LVM_SETITEMSTATE = (LVM_FIRST + 43); + public static int LVM_GETITEMSTATE = (LVM_FIRST + 44); + public static int LVIS_SELECTED = 0x0002; + public static int LVIS_FOCUSED = 0x0001; public static int LB_GETCOUNT = 0x18B; + public static int LB_GETCURSEL = 0x0188; + public static int LB_SETCURSEL = 0x0186; + public static int LB_GETTEXT = 0x0189; + public static int LB_GETTEXTLEN = 0x018A; + public static int LB_SELECTSTRING = 396; public static int CB_GETCOUNT = 0x146; @@ -133,10 +150,18 @@ public class Api { public static int MN_GETHMENU = 0x01E1; public static int CWP_ALL = 0x0000; // Does not skip any child windows + + public static int PAGE_READWRITE = 0x04; + + public static int MEM_COMMIT = 0x1000; + public static int MEM_RESERVE = 0x2000; + public static int MEM_RELEASE = 0x8000; + public static int MEM_FREE = 0x10000; + public static int MEM_DECOMMIT = 0x4000; - public User32 user32; - public Psapi psapi; - public Kernel32 kernel32; + public User32Ex user32; + public PsapiEx psapi; + public Kernel32Ex kernel32; public static final int POINT_Y(long i) { @@ -153,7 +178,7 @@ public class Api { return ((long)(((short)((int)(low) & 0xffff)) | ((int)((short)((int)(high) & 0xffff))) << 16)); } - public interface WinDefExt extends WinDef { + public interface WinDefEx extends WinDef { //Structures public class MENUITEMINFO extends Structure { public static final int MFS_CHECKED = 0x00000008; @@ -205,6 +230,35 @@ public class Api { public HBITMAP hbmpItem; //A handle to the bitmap to be displayed, or it can be one of the values in the following table. } + + //64bit LVITEM size 88 + //32bit LVITEM size 60 + public static class LVITEM_VISTA extends Structure { + public int mask; + public int iItem; + public int iSubItem; + public int state; + public int stateMask; + public Pointer pszText; + public int cchTextMax; + public int iImage; + public LPARAM lParam; + public int iIndent; + public int iGoupId; + public int cColumns; + public Pointer puColumns; + //NTDDI_VERSION >= NTDDI_VISTA + public Pointer piColFmt; + public int iGroup; + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { + "mask", "iItem", "iSubItem", "state", "stateMask", "pszText", "cchTextMax", "iImage", "lParam", "iIndent", "iGoupId", "cColumns", "puColumns", "piColFmt", "iGroup" }); + } + } + + + public static class COPYDATASTRUCT extends Structure { //The by-reference version of this structure. public static class ByReference extends COPYDATASTRUCT implements Structure.ByReference { } @@ -240,8 +294,8 @@ public class Api { } - public interface User32 extends W32APIOptions { - User32 instance = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS); + public interface User32Ex extends W32APIOptions { + User32Ex instance = (User32Ex) Native.loadLibrary("user32", User32Ex.class, DEFAULT_OPTIONS); int SetWindowLongPtr(HWND hWnd, int nIndex, Callback callback); LRESULT CallWindowProc(LONG_PTR proc, HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam); @@ -254,6 +308,7 @@ public class Api { HWND FindWindow(String winClass, String title); LRESULT PostMessage(HWND hWnd, int Msg, WPARAM wParam, LPARAM lParam); LRESULT SendMessage(HWND hWnd, int Msg, WPARAM wParam, LPARAM lParam); + LRESULT SendMessage(HWND hWnd, int Msg, WPARAM wParam, LVITEM_VISTA lParam); LRESULT SendMessageA(HWND editHwnd, int wmGettext, long l, byte[] lParamStr); boolean DestroyWindow(HWND hWnd); @@ -299,7 +354,7 @@ public class Api { int GetMenuItemCount(HMENU hMenu); int GetMenuItemID(HMENU hMenu, int nPos); //BOOL WINAPI GetMenuItemInfo(_In_ HMENU hMenu, _In_ UINT uItem, _In_ BOOL fByPosition, _Inout_ LPMENUITEMINFO lpmii); - boolean GetMenuItemInfoA(HMENU hMenu, int uItem, boolean fByPosition, WinDefExt.MENUITEMINFO mii); //MENUITEMINFO + boolean GetMenuItemInfoA(HMENU hMenu, int uItem, boolean fByPosition, WinDefEx.MENUITEMINFO mii); //MENUITEMINFO boolean TrackPopupMenu(HMENU hMenu, int uFlags, int x, int y, int nReserved, HWND hWnd, long prcRect); boolean GetMenuItemRect(HWND hWnd, HMENU hMenu, int uItem, RECT rect); @@ -307,34 +362,51 @@ public class Api { int GetDlgItemText(HWND hDlg, int nIDDlgItem, byte[] buffer, int nMaxCount); } - public interface Gdi32 extends W32APIOptions { - Gdi32 instance = (Gdi32) Native.loadLibrary("gdi32", Gdi32.class, DEFAULT_OPTIONS); + public interface Gdi32Ex extends W32APIOptions { + Gdi32Ex instance = (Gdi32Ex) Native.loadLibrary("gdi32", Gdi32Ex.class, DEFAULT_OPTIONS); HANDLE SelectObject(HDC hdc, HANDLE hgdiobj); HANDLE GetStockObject(int fnObject); boolean Rectangle(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); HPEN CreatePen(int fnPenStyle, int nWidth, int crColor); } - public interface Psapi extends W32APIOptions { - Psapi instance = (Psapi) Native.loadLibrary("psapi", Psapi.class, DEFAULT_OPTIONS); + public interface PsapiEx extends W32APIOptions { + PsapiEx instance = (PsapiEx) Native.loadLibrary("psapi", PsapiEx.class, DEFAULT_OPTIONS); int GetModuleBaseNameW(Pointer hProcess, Pointer hmodule, char[] lpBaseName, int size); } - public interface Kernel32 extends W32APIOptions { - Kernel32 instance = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class, DEFAULT_OPTIONS); + public interface Kernel32Ex extends W32APIOptions { + Kernel32Ex instance = (Kernel32Ex) Native.loadLibrary("kernel32", Kernel32Ex.class, DEFAULT_OPTIONS); boolean GetDiskFreeSpaceEx(String lpDirectoryName, LARGE_INTEGER.ByReference lpFreeBytesAvailable, LARGE_INTEGER.ByReference lpTotalNumberOfBytes, LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes); int GetLastError(); Pointer OpenProcess(int dwDesiredAccess, boolean bInheritHandle, Pointer pointer); + //int OpenProcess(int dwDesiredAccess, boolean bInheritHandle, Pointer pointer); boolean CloseHandle(HANDLE hObject); void GetNativeSystemInfo(SYSTEM_INFO lpSystemInfo); boolean IsWow64Process(HANDLE hProcess, IntByReference Wow64Process); + //LPVOID VirtualAllocEx(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect); + + //int VirtualAllocEx(HANDLE hProcess, int lpAddress, int dwSize, DWORD flAllocationType, DWORD flProtect); + IntByReference VirtualAllocEx(HANDLE hProc, IntByReference addr, SIZE_T size, int allocType, int prot); + Pointer VirtualAllocEx(HANDLE hProc, int i, int lngMemLen2, int allocType, int pAGE_READWRITE); + boolean VirtualFreeEx(HANDLE hProcess, IntByReference lpAddress, SIZE_T dwSize, DWORD dwFreeType); + boolean WriteProcessMemory(HANDLE hProcess, IntByReference lpBaseAddress, Pointer lpBuffer, int len, IntByReference bytesWritten); + + //boolean WriteProcessMemory(Pointer p, long address, Pointer buffer, int size, IntByReference written); + boolean ReadProcessMemory(Pointer hProcess, long inBaseAddress, Pointer outputBuffer, int nSize, IntByReference outNumberOfBytesRead); + int WriteProcessMemory(HANDLE handle, Pointer lngMemVar2, LVITEM_VISTA lvi, + int lngMemLen2, IntByReference byteIO); + int ReadProcessMemory(HANDLE handle, Pointer lngMemVar1, + Pointer lngVarPtr1, int lngMemLen1, IntByReference byteIO); + int VirtualFreeEx(HANDLE hProcess, Pointer lngMemVar1, int i, + int mEM_RELEASE); } public Api() { - user32 = User32.instance; - psapi = Psapi.instance; - kernel32 = Kernel32.instance; + user32 = User32Ex.instance; + psapi = PsapiEx.instance; + kernel32 = Kernel32Ex.instance; } public static Long GetHandleAsLong(HWND hWnd) { @@ -365,14 +437,14 @@ public class Api { public static String getWindowClassName(HWND hWnd) { char[] buffer = new char[1026]; - User32.instance.GetClassName(hWnd, buffer, 1026); + User32Ex.instance.GetClassName(hWnd, buffer, 1026); return Native.toString(buffer); } public static String getWindowText(HWND hWnd) { String text = ""; byte[] buffer = new byte[1024]; - User32.instance.GetWindowTextA(hWnd, buffer, buffer.length); + User32Ex.instance.GetWindowTextA(hWnd, buffer, buffer.length); text = Native.toString(buffer); if (text.isEmpty()) text = new Api().sendWmGetText(hWnd); @@ -382,15 +454,15 @@ public class Api { public static Point getCursorPos() { long[] getPos = new long [1]; - User32.instance.GetCursorPos(getPos); + User32Ex.instance.GetCursorPos(getPos); return new Point(POINT_X(getPos[0]), POINT_Y(getPos[0])); } public static HWND getWindowFromCursorPos() { long[] getPos = new long [1]; - User32.instance.GetCursorPos(getPos); - HWND hwnd = User32.instance.WindowFromPoint(getPos[0]); + User32Ex.instance.GetCursorPos(getPos); + HWND hwnd = User32Ex.instance.WindowFromPoint(getPos[0]); HWND childHwnd = getHiddenChildWindowFromPoint(hwnd, getPos[0]); hwnd = childHwnd; //System.out.println(getPos[0] + "," + getPos[1] + " int: " + x + ", " + y); @@ -408,11 +480,11 @@ public class Api { //x = POINT_X(getPos[0]);y = POINT_Y(getPos[0]); //System.out.println("ClientToScreen " + GetHandleAsString(inHwnd) + ", " + x + ", " + y); - if (!User32.instance.ScreenToClient(inHwnd, getPos)) return inHwnd; // if point is not correct use original hwnd. + if (!User32Ex.instance.ScreenToClient(inHwnd, getPos)) return inHwnd; // if point is not correct use original hwnd. //x = POINT_X(getPos[0]);y = POINT_Y(getPos[0]); //System.out.println("ScreenToClient " + GetHandleAsString(inHwnd) + ", " + x + ", " + y); - HWND childHwnd = User32.instance.ChildWindowFromPointEx(inHwnd, getPos[0], CWP_ALL); + HWND childHwnd = User32Ex.instance.ChildWindowFromPointEx(inHwnd, getPos[0], CWP_ALL); //System.out.println("ChildWindowFromPointEx2 " + GetHandleAsString(inHwnd) + ", " + x + ", " + y + " = " + GetHandleAsString(childHwnd)); if (childHwnd == null) // if childHwnd is not correct use original hwnd. @@ -562,7 +634,7 @@ public class Api { LARGE_INTEGER.ByReference lpFreeBytesAvailable = new LARGE_INTEGER.ByReference(); LARGE_INTEGER.ByReference lpTotalNumberOfBytes = new LARGE_INTEGER.ByReference(); LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes = new LARGE_INTEGER.ByReference(); - Kernel32.instance.GetDiskFreeSpaceEx(target, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); + Kernel32Ex.instance.GetDiskFreeSpaceEx(target, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); double freeBytes = lpTotalNumberOfFreeBytes.getValue(); double totalBytes = lpTotalNumberOfBytes.getValue(); //System.out.println("freespace " + humanReadableByteCount(freeBytes) + "/ totalspace " + humanReadableByteCount(totalBytes)); @@ -580,7 +652,7 @@ public class Api { public static void highlightWindow(HWND hwnd){ RECT rect = new RECT(); - User32.instance.GetWindowRect(hwnd, rect); + User32Ex.instance.GetWindowRect(hwnd, rect); //System.out.println("RECT: " + rect.left + "," + rect.top + "," + (rect.right - rect.left) + "," + (rect.bottom - rect.top)); highlightWindow(hwnd, 0, 0, rect.right - rect.left, rect.bottom - rect.top); } @@ -589,31 +661,31 @@ public class Api { public static void highlightWindow(HWND hwnd, int x, int y, int x2, int y2){ //COLORREF i.e. 0x00804070 Red = 0x70 green = 0x40 blue = 0x80 //g_hRectanglePen = CreatePen (PS_SOLID, 3, RGB(256, 0, 0)); - HPEN rectPen = Gdi32.instance.CreatePen(PS_SOLID, 3, 0x00000099); //RGB(255, 0, 0) - HDC dc = User32.instance.GetWindowDC(hwnd); + HPEN rectPen = Gdi32Ex.instance.CreatePen(PS_SOLID, 3, 0x00000099); //RGB(255, 0, 0) + HDC dc = User32Ex.instance.GetWindowDC(hwnd); if (dc != null) { // Select our created pen into the DC and backup the previous pen. - HANDLE prevPen = Gdi32.instance.SelectObject(dc, rectPen); + HANDLE prevPen = Gdi32Ex.instance.SelectObject(dc, rectPen); // Select a transparent brush into the DC and backup the previous brush. - HANDLE prevBrush = Gdi32.instance.SelectObject(dc, Gdi32.instance.GetStockObject(HOLLOW_BRUSH)); + HANDLE prevBrush = Gdi32Ex.instance.SelectObject(dc, Gdi32Ex.instance.GetStockObject(HOLLOW_BRUSH)); // Draw a rectangle in the DC covering the entire window area of the found window. - Gdi32.instance.Rectangle (dc, x, y, x2, y2); + Gdi32Ex.instance.Rectangle (dc, x, y, x2, y2); // Reinsert the previous pen and brush into the found window's DC. - Gdi32.instance.SelectObject(dc, prevPen); - Gdi32.instance.SelectObject(dc, prevBrush); + Gdi32Ex.instance.SelectObject(dc, prevPen); + Gdi32Ex.instance.SelectObject(dc, prevBrush); // Finally release the DC. - User32.instance.ReleaseDC(hwnd, dc); + User32Ex.instance.ReleaseDC(hwnd, dc); } } public static void refreshWindow(HWND hwnd) { - User32.instance.InvalidateRect(hwnd, 0, true); - User32.instance.UpdateWindow(hwnd); - User32.instance.RedrawWindow(hwnd, 0, 0, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); + User32Ex.instance.InvalidateRect(hwnd, 0, true); + User32Ex.instance.UpdateWindow(hwnd); + User32Ex.instance.RedrawWindow(hwnd, 0, 0, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); } public static boolean isDotNet4Installed() { @@ -636,21 +708,21 @@ public class Api { { try { SYSTEM_INFO lpSystemInfo = new SYSTEM_INFO(); - Kernel32.instance.GetNativeSystemInfo(lpSystemInfo); + Kernel32Ex.instance.GetNativeSystemInfo(lpSystemInfo); if (lpSystemInfo.processorArchitecture.dwOemID.intValue() == 0) { System.out.println("intel x86"); //not a 64 bit os return false; } - Pointer process = Kernel32.instance.OpenProcess(Api.PROCESS_QUERY_INFORMATION | Api.PROCESS_VM_READ, false, new Pointer(pid)); + Pointer process = Kernel32Ex.instance.OpenProcess(Api.PROCESS_QUERY_INFORMATION | Api.PROCESS_VM_READ, false, new Pointer(pid)); IntByReference isWow64 = new IntByReference(0); - if (!Kernel32.instance.IsWow64Process(new HANDLE(process), isWow64)) + if (!Kernel32Ex.instance.IsWow64Process(new HANDLE(process), isWow64)) { //handle error } //System.out.println("isProcess64bit " + pid + " = " + isWow64.getValue()); - Kernel32.instance.CloseHandle(new HANDLE(process)); + Kernel32Ex.instance.CloseHandle(new HANDLE(process)); if (isWow64.getValue() == 1) return false; return true; @@ -669,7 +741,7 @@ public class Api { @Override public boolean callback(HWND hWnd, Pointer lParam) { PointerByReference pointer = new PointerByReference(); - User32.instance.GetWindowThreadProcessId(hWnd, pointer); + User32Ex.instance.GetWindowThreadProcessId(hWnd, pointer); long pid = pointer.getPointer().getInt(0); if (pid == targetProcessId) if (resultList.isEmpty()) @@ -678,10 +750,91 @@ public class Api { } } - Api.User32.instance.EnumWindows(new ParentWindowCallback(), 0); + Api.User32Ex.instance.EnumWindows(new ParentWindowCallback(), 0); if (!resultList.isEmpty()) return resultList.get(0); return null; } + public static void GetListViewItemByIndex(HWND listViewHwnd, int index) + { + LVITEM_VISTA lvi; + int strSize = 255; + int result = 0; + Pointer lngVarPtr1 = null;Pointer lngMemVar1 = null; + Pointer lngVarPtr2 = null;Pointer lngMemVar2 = null; + Pointer lviVarPtr = null;Pointer lviVar = null; + int lngMemLen1; int lngMemLen2; + PointerByReference lngProcID = new PointerByReference(); + int ThreadId = User32Ex.instance.GetWindowThreadProcessId(listViewHwnd, lngProcID); + + Pointer lngProcHandle = Kernel32Ex.instance.OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, lngProcID.getValue()); + lvi = new LVITEM_VISTA(); + lngMemLen1 = strSize; + lngMemLen2 = lvi.size(); + lngMemVar2 = Kernel32Ex.instance.VirtualAllocEx(new HANDLE(lngProcHandle), 0, lngMemLen2, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + lvi.cchTextMax = strSize; + lvi.iItem = index; + lvi.iSubItem = 0; + lvi.mask = LVIF_TEXT; + //lvi.pszText = lngMemVar1; + //result = Kernel32.WriteProcessMemory(lngProcHandle, lngMemVar1, lngVarPtr1, lngMemLen1, byteswritten1); + IntByReference byteIO = new IntByReference(); + result = Kernel32Ex.instance.WriteProcessMemory(new HANDLE(lngProcHandle), lngMemVar2, lvi, lngMemLen2, byteIO); + LRESULT sresult = User32Ex.instance.SendMessage(listViewHwnd, LVM_GETITEM, new WPARAM(0), new LPARAM(lngMemVar2.getLong(0))); + lngVarPtr1 = new Memory(strSize + 1); + result = Kernel32Ex.instance.ReadProcessMemory(new HANDLE(lngProcHandle), lngMemVar1, lngVarPtr1, lngMemLen1, byteIO); + result = Kernel32Ex.instance.VirtualFreeEx (new HANDLE(lngProcHandle), lngMemVar1, 0, MEM_RELEASE); + result = Kernel32Ex.instance.VirtualFreeEx (new HANDLE(lngProcHandle), lngMemVar2, 0, MEM_RELEASE); + boolean cresult = Kernel32Ex.instance.CloseHandle(new HANDLE(lngProcHandle)); + System.out.println(lngVarPtr1.getString(0)); + } + + public static void SelectListViewItemByIndex(HWND listViewHwnd, int index) + { + /* + HANDLE hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, 0x0000c130); + LPVOID epLvi = VirtualAllocEx(hProcess, NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + LVITEM lvi; + lvi.state = LVIS_FOCUSED | LVIS_SELECTED; + lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED; + SIZE_T cbWritten = 0; + WriteProcessMemory(hProcess, epLvi, &lvi, sizeof(lvi), &cbWritten); + DWORD dw = SendMessage((HWND)0x00020C4C, LVM_SETITEMSTATE, 1, (LPARAM)epLvi); + + VirtualFreeEx(hProcess, epLvi, 4096, MEM_DECOMMIT | MEM_RELEASE); + CloseHandle(hProcess); + */ + PointerByReference pointer = new PointerByReference(); + User32Ex.instance.GetWindowThreadProcessId(listViewHwnd, pointer); + int pid = pointer.getPointer().getInt(0); + Pointer process = Kernel32Ex.instance.OpenProcess(Api.PROCESS_VM_WRITE | Api.PROCESS_VM_OPERATION, false, new Pointer(pid)); + IntByReference addr = new IntByReference(0); + SIZE_T size = new SIZE_T(4096); + IntByReference epLvi = Kernel32Ex.instance.VirtualAllocEx(new HANDLE(process), addr, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + LVITEM_VISTA lvitem = new LVITEM_VISTA(); + lvitem.stateMask = LVIS_FOCUSED | LVIS_SELECTED; + lvitem.state = LVIS_FOCUSED | LVIS_SELECTED; + IntByReference bytesWritten = new IntByReference(); + Api.Kernel32Ex.instance.WriteProcessMemory(new HANDLE(process), epLvi, lvitem.getPointer(), lvitem.size(),bytesWritten); + Api.User32Ex.instance.SendMessage(listViewHwnd, LVM_SETITEMSTATE, new WPARAM(index), lvitem); + + Api.Kernel32Ex.instance.VirtualFreeEx(new HANDLE(process), epLvi, new SIZE_T(4096), new DWORD(MEM_DECOMMIT | MEM_RELEASE)); + Api.Kernel32Ex.instance.CloseHandle(new HANDLE(process)); + } + + public static void SelectListItemByIndex(HWND listHwnd, int index) + { + //com.sun.jna.platform.win32.User32.INSTANCE + Api.User32Ex.instance.SendMessage(listHwnd, LB_SETCURSEL, new WPARAM(index), new LPARAM(0)); + SelectListViewItemByIndex(listHwnd, index); + //GetListViewItemByIndex(listHwnd, index); + //LVITEM lvitem = new LVITEM(); + //lvitem.stateMask = LVIS_FOCUSED | LVIS_SELECTED; + //lvitem.state = LVIS_FOCUSED | LVIS_SELECTED; + //JOptionPane.showMessageDialog(null, "lvitem size: " + lvitem.size()); + + } } diff --git a/src/org/synthuse/CommandPopupMenu.java b/src/org/synthuse/CommandPopupMenu.java index e4e52cb..5feaefb 100644 --- a/src/org/synthuse/CommandPopupMenu.java +++ b/src/org/synthuse/CommandPopupMenu.java @@ -150,9 +150,18 @@ public class CommandPopupMenu extends JPopupMenu { CommandMenuItem mntmGetwindowclass = new CommandMenuItem("getWindowClass", 2); mnWinMessages.add(mntmGetwindowclass); + CommandMenuItem mntmSelectListIndex = new CommandMenuItem("selectListIndex", 3); + mnWinMessages.add(mntmSelectListIndex); + + CommandMenuItem mntmSelectListString = new CommandMenuItem("selectListString", 3); + mnWinMessages.add(mntmSelectListString); + CommandMenuItem mntmDisplayText = new CommandMenuItem("displayText", 3, false); add(mntmDisplayText); + CommandMenuItem mntmDisableStatus = new CommandMenuItem("disableStatus", 2, false); + add(mntmDisableStatus); + CommandMenuItem mntmForceRefresh = new CommandMenuItem("forceRefresh", 1, false); add(mntmForceRefresh); @@ -174,6 +183,9 @@ public class CommandPopupMenu extends JPopupMenu { CommandMenuItem mntmSetUpdateThreshold = new CommandMenuItem("setUpdateThreshold", 2, false); add(mntmSetUpdateThreshold); + CommandMenuItem mntmTakeScreenCapture = new CommandMenuItem("takeScreenCapture", 2, false); + add(mntmTakeScreenCapture); + CommandMenuItem mntmTargetRefresh = new CommandMenuItem("targetRefresh", 2); add(mntmTargetRefresh); diff --git a/src/org/synthuse/CommandProcessor.java b/src/org/synthuse/CommandProcessor.java index be41135..ce794b3 100644 --- a/src/org/synthuse/CommandProcessor.java +++ b/src/org/synthuse/CommandProcessor.java @@ -64,6 +64,13 @@ public class CommandProcessor implements Runnable{ public void setQuiet(boolean val) { isQuiet = val; + if (val) + { + if (currentStatusWin != null) + currentStatusWin.dispose(); + currentStatusWin = null; + } + } public CommandProcessor () { @@ -245,7 +252,11 @@ public class CommandProcessor implements Runnable{ if (command.equals("setWindowText")) return win.cmdSetText(args); if (command.equals("getWindowText")) - return win.cmdGetText(args); + return win.cmdGetText(args); + if (command.equals("selectListIndex")) + return win.cmdSelectListIndex(args); + if (command.equals("selectListString")) + return win.cmdSelectListString(args); // Misc Command and Test/Sample command if (command.equals("delay") || command.equals("pause")) { @@ -264,6 +275,8 @@ public class CommandProcessor implements Runnable{ return main.cmdOpen(args); if (command.equals("displayText")) return main.cmdDisplayText(args); + if (command.equals("disableStatus")) + return main.cmdDisableStatus(args); if (command.equals("forceRefresh")) return main.cmdForceRefresh(args); if (command.equals("setSpeed")) @@ -276,6 +289,8 @@ public class CommandProcessor implements Runnable{ return main.cmdVerifyElementNotPresent(args); if (command.equals("verifyElementPresent")) return main.cmdVerifyElementPresent(args); + if (command.equals("takeScreenCapture")) + return main.cmdTakeScreenCapture(args); if (command.equals("targetRefresh")) return main.cmdTargetRefresh(args); if (command.equals("waitForTitle")) diff --git a/src/org/synthuse/MessageHookFrame.java b/src/org/synthuse/MessageHookFrame.java index 4fef6ad..6df678d 100644 --- a/src/org/synthuse/MessageHookFrame.java +++ b/src/org/synthuse/MessageHookFrame.java @@ -118,13 +118,13 @@ public class MessageHookFrame extends JFrame { } else System.out.println("MESSAGE: " + uMsg); - return Api.User32.instance.CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); + return Api.User32Ex.instance.CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); //return new LRESULT(0); //return User32.INSTANCE.DefWindowProc(hWnd, uMsg, wParam, lParam); } }; - Api.User32.instance.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, wndProc); + Api.User32Ex.instance.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, wndProc); } }); toolBar.add(btnPause); @@ -225,7 +225,7 @@ public class MessageHookFrame extends JFrame { // memcpy(&Event, (HEVENT*)pCopyDataStruct->lpData, sizeof(HEVENT)); // transfer data to internal variable //} - Api.WinDefExt.COPYDATASTRUCT cds = new Api.WinDefExt.COPYDATASTRUCT(lParam.longValue()); + Api.WinDefEx.COPYDATASTRUCT cds = new Api.WinDefEx.COPYDATASTRUCT(lParam.longValue()); HEVENT he = new HEVENT(cds.lpData); appendLine("msg: WM_COPYDATA" + cds.cbData); appendLine("hwnd: " + he.hWnd + ", msg: " + he.nCode + ", wParam: " + he.wParam + ", lParam: " + he.lParam); @@ -235,13 +235,13 @@ public class MessageHookFrame extends JFrame { //else // System.out.println("MESSAGE: " + uMsg); - return Api.User32.instance.CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); + return Api.User32Ex.instance.CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); //return User32.INSTANCE.DefWindowProc(hWnd, uMsg, wParam, lParam); } }; //Set the wndproc callback on this MessageHookFrame so we can process Windows Messages - Api.User32.instance.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, wndProc); + Api.User32Ex.instance.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, wndProc); IntByReference intByRef = new IntByReference(0); final int threadId = User32.INSTANCE.GetWindowThreadProcessId(Api.GetHandleFromString(txtTarget.getText()), intByRef); diff --git a/src/org/synthuse/RobotMacro.java b/src/org/synthuse/RobotMacro.java index aeaabe9..dfb6bf9 100644 --- a/src/org/synthuse/RobotMacro.java +++ b/src/org/synthuse/RobotMacro.java @@ -420,6 +420,14 @@ ALT % specialKeyFlag = false; pressKeyCodes(robot, new int[]{KeyEvent.VK_DIVIDE} ); } + else if (specialKey.equals("{PERCENT}")) { + specialKeyFlag = false; + pressKeyCodes(robot, new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_5} ); + } + else if (specialKey.equals("{CARROT}")) { + specialKeyFlag = false; + pressKeyCodes(robot, new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_6} ); + } else if (specialKey.equals("{INSERT}")) { specialKeyFlag = false; pressKeyCodes(robot, new int[]{KeyEvent.VK_INSERT} ); diff --git a/src/org/synthuse/SynthuseDlg.java b/src/org/synthuse/SynthuseDlg.java index 7c80a37..48b0398 100644 --- a/src/org/synthuse/SynthuseDlg.java +++ b/src/org/synthuse/SynthuseDlg.java @@ -41,7 +41,7 @@ import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; -import org.synthuse.Api.User32; +import org.synthuse.Api.User32Ex; import org.synthuse.DragTarget.dragEvents; @@ -51,7 +51,7 @@ public class SynthuseDlg extends JFrame { /** * */ - public static String VERSION_STR = "1.2.2"; + public static String VERSION_STR = "1.2.4"; public static String RES_STR_MAIN_ICON = "/org/synthuse/img/gnome-robots.png"; public static String RES_STR_REFRESH_IMG = "/org/synthuse/img/rapidsvn.png"; @@ -520,9 +520,9 @@ public class SynthuseDlg extends JFrame { HWND hwnd = Api.getWindowFromCursorPos();//new Point(targetX,targetY) String handleStr = Api.GetHandleAsString(hwnd); String classStr = WindowsEnumeratedXml.escapeXmlAttributeValue(Api.getWindowClassName(hwnd)); - String parentStr = Api.GetHandleAsString(User32.instance.GetParent(hwnd)); + String parentStr = Api.GetHandleAsString(User32Ex.instance.GetParent(hwnd)); PointerByReference pointer = new PointerByReference(); - User32.instance.GetWindowThreadProcessId(hwnd, pointer); + User32Ex.instance.GetWindowThreadProcessId(hwnd, pointer); int pid = pointer.getPointer().getInt(0); String enumProperties = ""; @@ -549,7 +549,7 @@ public class SynthuseDlg extends JFrame { //lastDragHwnd = (hwnd + ""); if (framework.equals(UiaBridge.FRAMEWORK_ID_WPF) || framework.equals(UiaBridge.FRAMEWORK_ID_SILVER)) {// WPF and Silverlight apps don't expose their child windows boundaries the same as win32 apps - Api.highlightWindow(Api.User32.instance.GetDesktopWindow(), rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); + Api.highlightWindow(Api.User32Ex.instance.GetDesktopWindow(), rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); } else Api.highlightWindow(hwnd); diff --git a/src/org/synthuse/WindowInfo.java b/src/org/synthuse/WindowInfo.java index e9a0ece..6c574fd 100644 --- a/src/org/synthuse/WindowInfo.java +++ b/src/org/synthuse/WindowInfo.java @@ -59,7 +59,7 @@ public class WindowInfo { public WindowInfo(HWND hWnd, boolean isChild) { this.framework = "win32"; byte[] buffer = new byte[1024]; - User32.instance.GetWindowTextA(hWnd, buffer, buffer.length); + User32Ex.instance.GetWindowTextA(hWnd, buffer, buffer.length); text = Native.toString(buffer); if (text.isEmpty()) text = new Api().sendWmGetText(hWnd); @@ -70,7 +70,7 @@ public class WindowInfo { text = text.substring(0, MAX_TEXT_SIZE); //Get item count depending on what type of control it is - LRESULT tbCount = Api.User32.instance.SendMessage(hWnd, Api.TB_BUTTONCOUNT, new WPARAM(0), new LPARAM(0)); + LRESULT tbCount = Api.User32Ex.instance.SendMessage(hWnd, Api.TB_BUTTONCOUNT, new WPARAM(0), new LPARAM(0)); if (tbCount.intValue() > 0) { // toolbar button count //System.out.println("TB_BUTTONCOUNT: " + tbCount.intValue()); if (extra == null) @@ -79,25 +79,25 @@ public class WindowInfo { //Api.User32.instance.SendMessageA(hWnd, Api.TB_GETTOOLTIPS, 0, buffer); //text = Native.toString(buffer); } - LRESULT lvCount = Api.User32.instance.SendMessage(hWnd, Api.LVM_GETITEMCOUNT, new WPARAM(0), new LPARAM(0)); + LRESULT lvCount = Api.User32Ex.instance.SendMessage(hWnd, Api.LVM_GETITEMCOUNT, new WPARAM(0), new LPARAM(0)); if (lvCount.intValue() > 0) { // listview item count if (extra == null) extra = new LinkedHashMap(); extra.put("lvCount", lvCount.intValue() + ""); } - LRESULT lbCount = Api.User32.instance.SendMessage(hWnd, Api.LB_GETCOUNT, new WPARAM(0), new LPARAM(0)); + LRESULT lbCount = Api.User32Ex.instance.SendMessage(hWnd, Api.LB_GETCOUNT, new WPARAM(0), new LPARAM(0)); if (lbCount.intValue() > 0) { // listbox item count if (extra == null) extra = new LinkedHashMap(); extra.put("lbCount", lbCount.intValue() + ""); } - LRESULT cbCount = Api.User32.instance.SendMessage(hWnd, Api.CB_GETCOUNT, new WPARAM(0), new LPARAM(0)); + LRESULT cbCount = Api.User32Ex.instance.SendMessage(hWnd, Api.CB_GETCOUNT, new WPARAM(0), new LPARAM(0)); if (cbCount.intValue() > 0) { // listbox item count if (extra == null) extra = new LinkedHashMap(); extra.put("cbCount", cbCount.intValue() + ""); } - LRESULT tvCount = Api.User32.instance.SendMessage(hWnd, Api.TVM_GETCOUNT, new WPARAM(0), new LPARAM(0)); + LRESULT tvCount = Api.User32Ex.instance.SendMessage(hWnd, Api.TVM_GETCOUNT, new WPARAM(0), new LPARAM(0)); if (tvCount.intValue() > 0) { //treeview node count if (extra == null) extra = new LinkedHashMap(); @@ -105,13 +105,13 @@ public class WindowInfo { } char[] buffer2 = new char[1026]; - User32.instance.GetClassName(hWnd, buffer2, 1026); + User32Ex.instance.GetClassName(hWnd, buffer2, 1026); className = Native.toString(buffer2); //check if window has a menu - HMENU hmenu = Api.User32.instance.GetMenu(hWnd); + HMENU hmenu = Api.User32Ex.instance.GetMenu(hWnd); if (hmenu != null) { //menu item count - int menuCount = Api.User32.instance.GetMenuItemCount(hmenu); + int menuCount = Api.User32Ex.instance.GetMenuItemCount(hmenu); if (menuCount > 0) { this.menus = menuCount; this.menu = hmenu; @@ -120,12 +120,12 @@ public class WindowInfo { else // if (className.equals("#32768")) //check if its a popup menu window { //LRESULT result = Api.User32.instance.PostMessage(hWnd, Api.MN_GETHMENU, new WPARAM(0), new LPARAM(0)); - LRESULT result = Api.User32.instance.SendMessage(hWnd, Api.MN_GETHMENU, new WPARAM(0), new LPARAM(0)); + LRESULT result = Api.User32Ex.instance.SendMessage(hWnd, Api.MN_GETHMENU, new WPARAM(0), new LPARAM(0)); if (result.longValue() != 1) { //System.out.println("MN_GETHMENU: " + result.longValue()); hmenu = new HMENU(new Pointer(result.longValue())); - int menuCount = Api.User32.instance.GetMenuItemCount(hmenu); + int menuCount = Api.User32Ex.instance.GetMenuItemCount(hmenu); if (menuCount > 0) { //System.out.println("Popup Win: " + menuCount); @@ -137,11 +137,11 @@ public class WindowInfo { rect = new RECT(); - User32.instance.GetWindowRect(hWnd, rect); + User32Ex.instance.GetWindowRect(hWnd, rect); this.isChild = isChild; if (isChild) { - parent = User32.instance.GetParent(hWnd); + parent = User32Ex.instance.GetParent(hWnd); parentStr = Api.GetHandleAsString(parent); // test to see if uiaBridge should be used on this child if (this.className.startsWith("HwndWrapper") || this.className.startsWith("MicrosoftSilverlight") || this.className.startsWith("GeckoPluginWindow")) @@ -149,7 +149,7 @@ public class WindowInfo { } else { PointerByReference pointer = new PointerByReference(); - User32.instance.GetWindowThreadProcessId(hWnd, pointer); + User32Ex.instance.GetWindowThreadProcessId(hWnd, pointer); pid = pointer.getPointer().getInt(0); getProcessInfo(); //test to see if uiaBridge should be used on this parent @@ -258,10 +258,10 @@ public class WindowInfo { if (pid == 0) return; char[] buffer = new char[1026]; - Pointer process = Kernel32.instance.OpenProcess(Api.PROCESS_QUERY_INFORMATION | Api.PROCESS_VM_READ, false, new Pointer(pid)); - Psapi.instance.GetModuleBaseNameW(process, null, buffer, 512); + Pointer process = Kernel32Ex.instance.OpenProcess(Api.PROCESS_QUERY_INFORMATION | Api.PROCESS_VM_READ, false, new Pointer(pid)); + PsapiEx.instance.GetModuleBaseNameW(process, null, buffer, 512); processName = Native.toString(buffer); - Kernel32.instance.CloseHandle(new HANDLE(process)); + Kernel32Ex.instance.CloseHandle(new HANDLE(process)); is64bit = Api.isProcess64bit((int)pid); } diff --git a/src/org/synthuse/WindowsEnumeratedXml.java b/src/org/synthuse/WindowsEnumeratedXml.java index 52b135e..6320995 100644 --- a/src/org/synthuse/WindowsEnumeratedXml.java +++ b/src/org/synthuse/WindowsEnumeratedXml.java @@ -80,7 +80,7 @@ public class WindowsEnumeratedXml implements Runnable{ public static String getXml() { final Map infoList = new LinkedHashMap(); - HWND desktopRootHwnd = Api.User32.instance.GetDesktopWindow(); + HWND desktopRootHwnd = Api.User32Ex.instance.GetDesktopWindow(); WindowInfo wi = new WindowInfo(desktopRootHwnd, false); wi.controlType = "DesktopRoot"; infoList.put(wi.hwndStr, wi); @@ -94,7 +94,7 @@ public class WindowsEnumeratedXml implements Runnable{ return true; } } - Api.User32.instance.EnumWindows(new ParentWindowCallback(), 0); + Api.User32Ex.instance.EnumWindows(new ParentWindowCallback(), 0); //process all windows that have been flagged for uiaBridge (useUiaBridge == true) appendUiaBridgeWindows(infoList); @@ -132,7 +132,7 @@ public class WindowsEnumeratedXml implements Runnable{ } } - Api.User32.instance.EnumChildWindows(parentHwnd, new ChildWindowCallback(), new Pointer(0)); + Api.User32Ex.instance.EnumChildWindows(parentHwnd, new ChildWindowCallback(), new Pointer(0)); return infoList; } diff --git a/src/org/synthuse/XpathManager.java b/src/org/synthuse/XpathManager.java index b00ad18..3e0ac0e 100644 --- a/src/org/synthuse/XpathManager.java +++ b/src/org/synthuse/XpathManager.java @@ -14,7 +14,7 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextPane; -import org.synthuse.Api.User32; +import org.synthuse.Api.User32Ex; import com.sun.jna.platform.win32.WinDef.HWND; @@ -126,7 +126,7 @@ public class XpathManager implements Runnable{ List resultList = WindowsEnumeratedXml.evaluateXpathGetValues(xml, builtXpath); //int matches = nextXpathMatch(builtXpath, textPane, true); if (resultList.size() > 1) { // if there are multiple results with the simple xpath then include parent class and text with the xpath statement. - HWND parent = User32.instance.GetParent(hwnd); + HWND parent = User32Ex.instance.GetParent(hwnd); String parentClassStr = WindowsEnumeratedXml.escapeXmlAttributeValue(Api.getWindowClassName(parent)); String parentTxtOrig = Api.getWindowText(parent); String parentTxtStr = WindowsEnumeratedXml.escapeXmlAttributeValue(parentTxtOrig); diff --git a/src/org/synthuse/commands/MainCommands.java b/src/org/synthuse/commands/MainCommands.java index af63554..da4bb63 100644 --- a/src/org/synthuse/commands/MainCommands.java +++ b/src/org/synthuse/commands/MainCommands.java @@ -8,8 +8,13 @@ package org.synthuse.commands; import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.Robot; import java.awt.Toolkit; -import java.io.IOException; +import java.awt.image.BufferedImage; +import java.io.*; + +import javax.imageio.ImageIO; import org.synthuse.*; @@ -196,5 +201,32 @@ public class MainCommands extends BaseCommand { return false; } } + + public boolean cmdDisableStatus(String[] args) { + if (!checkArgumentLength(args, 1)) + return false; + boolean val = args[0].toUpperCase().equals("TRUE"); + parentProcessor.setQuiet(val); + return true; + } + public boolean cmdTakeScreenCapture(String[] args) { + if (!checkArgumentLength(args, 1)) + return false; + try { + String saveName = args[0]; + if (!saveName.toLowerCase().endsWith(".png")) + saveName += ".png"; + //LOG.debug("take Screen Capture " + new File(saveName).getAbsolutePath()); + Robot robot = new Robot(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + BufferedImage image = robot.createScreenCapture(new Rectangle(screenSize)); + ImageIO.write(image, "png", new File(saveName)); + } + catch(Exception e) { + //e.printStackTrace(); + appendError(e); + } + return true; + } } diff --git a/src/org/synthuse/commands/WindowsCommands.java b/src/org/synthuse/commands/WindowsCommands.java index 738aa1a..bf1b517 100644 --- a/src/org/synthuse/commands/WindowsCommands.java +++ b/src/org/synthuse/commands/WindowsCommands.java @@ -194,5 +194,23 @@ public class WindowsCommands extends BaseCommand { return true; } -} + + public boolean cmdSelectListIndex(String[] args) { + if (!checkArgumentLength(args, 2)) + return false; + WinPtr handle = findHandleWithXpath(args[0]); //xpath to HWND is first argument + if (handle.isEmpty()) + return false; + handle.convertToNativeHwnd(); + int index = Integer.parseInt(args[1]); + Api.SelectListItemByIndex(handle.hWnd, index); + return true; + } + + public boolean cmdSelectListString(String[] args) { + //CB_SELECTSTRING + return true; + + } +} \ No newline at end of file diff --git a/src/org/synthuse/test/WinApiTest.java b/src/org/synthuse/test/WinApiTest.java index fa0c2c5..1155a4a 100644 --- a/src/org/synthuse/test/WinApiTest.java +++ b/src/org/synthuse/test/WinApiTest.java @@ -13,9 +13,9 @@ import static org.junit.Assert.*; import org.synthuse.Api; import org.synthuse.WindowInfo; import org.synthuse.WindowsEnumeratedXml; -import org.synthuse.Api.Kernel32; -import org.synthuse.Api.Psapi; -import org.synthuse.Api.User32; +import org.synthuse.Api.Kernel32Ex; +import org.synthuse.Api.PsapiEx; +import org.synthuse.Api.User32Ex; import com.sun.jna.Native; import com.sun.jna.Pointer; @@ -57,7 +57,7 @@ public class WinApiTest { byte[] buffer = new byte[1024]; output("Calling GetWindowTextA"); - User32.instance.GetWindowTextA(hWnd, buffer, buffer.length); + User32Ex.instance.GetWindowTextA(hWnd, buffer, buffer.length); text = Native.toString(buffer); output("GetWindowTextA returned: " + text); if (text.isEmpty()) { @@ -68,14 +68,14 @@ public class WinApiTest { char[] buffer2 = new char[1026]; output("Calling GetClassName"); - User32.instance.GetClassName(hWnd, buffer2, 1026); + User32Ex.instance.GetClassName(hWnd, buffer2, 1026); className = Native.toString(buffer2); output("GetClassName returned: " + className); - HMENU hmenu = Api.User32.instance.GetMenu(hWnd); + HMENU hmenu = Api.User32Ex.instance.GetMenu(hWnd); //hmenu = Api.User32.instance.GetSubMenu(hmenu, 0); if (hmenu != null) { //menu item count - int menuCount = Api.User32.instance.GetMenuItemCount(hmenu); + int menuCount = Api.User32Ex.instance.GetMenuItemCount(hmenu); if (menuCount > 0) { if (extra == null) extra = new LinkedHashMap(); @@ -93,12 +93,12 @@ public class WinApiTest { rect = new RECT(); output("Calling GetWindowRect"); - User32.instance.GetWindowRect(hWnd, rect); + User32Ex.instance.GetWindowRect(hWnd, rect); output("GetWindowRect returned: " + rect.toString()); if (isChild) { output("Calling GetParent"); - parent = User32.instance.GetParent(hWnd); + parent = User32Ex.instance.GetParent(hWnd); parentStr = Api.GetHandleAsString(parent); output("GetParent returned: " + parentStr); } @@ -107,13 +107,13 @@ public class WinApiTest { //IntByReference pointer = new IntByReference(); PointerByReference pointer = new PointerByReference(); output("Calling GetWindowThreadProcessId"); - User32.instance.GetWindowThreadProcessId(hWnd, pointer); + User32Ex.instance.GetWindowThreadProcessId(hWnd, pointer); pid = pointer.getPointer().getInt(0); output("GetWindowThreadProcessId returned: " + pid); - Pointer process = Kernel32.instance.OpenProcess(Api.PROCESS_QUERY_INFORMATION | Api.PROCESS_VM_READ, false, pointer.getPointer()); + Pointer process = Kernel32Ex.instance.OpenProcess(Api.PROCESS_QUERY_INFORMATION | Api.PROCESS_VM_READ, false, pointer.getPointer()); //output("OpenProcess returned: " + process.getLong(0)); output("Calling GetModuleBaseNameW"); - Psapi.instance.GetModuleBaseNameW(process, null, buffer2, 512); + PsapiEx.instance.GetModuleBaseNameW(process, null, buffer2, 512); processName = Native.toString(buffer2); output("GetModuleBaseNameW returned: " + processName); //processName = Native.toString(path); @@ -137,7 +137,7 @@ public class WinApiTest { return true; } } - Api.User32.instance.EnumWindows(new ParentWindowCallback(), 0); + Api.User32Ex.instance.EnumWindows(new ParentWindowCallback(), 0); output("enumerateParentWindowsTest size: " + infoList.size()); assertTrue(infoList.size() > 0); }