parent
ce232739c7
commit
b264029b82
|
@ -0,0 +1,6 @@
|
|||
*.project
|
||||
*.classpath
|
||||
/bin/*
|
||||
/.settings/*
|
||||
/.externalToolBuilders/*
|
||||
*.log
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,71 @@
|
|||
package ru.diowo.activewindowcheck;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinUser;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.Kernel32;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinDef.RECT;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static String lastWindow = "";
|
||||
|
||||
private static final int MAX_TITLE_LENGTH = 1024;
|
||||
|
||||
public interface PsApi extends StdCallLibrary {
|
||||
|
||||
int GetModuleFileNameExA(HANDLE process, HANDLE module, byte[] name, int i);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Timer timer = new Timer();
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
PsApi psapi = (PsApi) Native.loadLibrary("psapi", PsApi.class);
|
||||
|
||||
char[] buffer = new char[MAX_TITLE_LENGTH * 2];
|
||||
HWND hwnd = User32.INSTANCE.GetForegroundWindow();
|
||||
User32.INSTANCE.GetWindowText(hwnd, buffer, MAX_TITLE_LENGTH);
|
||||
String currWindow = Native.toString(buffer);
|
||||
if (! lastWindow.equals(currWindow)) {
|
||||
lastWindow = currWindow;
|
||||
|
||||
System.out.println("Active window title: " + Native.toString(buffer));
|
||||
RECT rect = new RECT();
|
||||
User32.INSTANCE.GetWindowRect(hwnd, rect);
|
||||
System.out.println("rect = " + rect);
|
||||
|
||||
IntByReference pid = new IntByReference();
|
||||
User32.INSTANCE.GetWindowThreadProcessId(hwnd, pid);
|
||||
|
||||
byte[] filename = new byte[1024];
|
||||
|
||||
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010, false, pid.getValue());
|
||||
psapi.GetModuleFileNameExA(process, null, filename, 1024);
|
||||
String filenameString= Native.toString(filename);
|
||||
|
||||
System.out.println("PID "+pid.getValue()+", filename "+filenameString);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
timer.schedule(task, 1000, 500);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project default="create_run_jar" name="Create Runnable Jar for Project ActiveWindowCheck with Jar-in-Jar Loader">
|
||||
<!--this file was created by Eclipse Runnable JAR file Export Wizard-->
|
||||
<!--ANT 1.7 is required-->
|
||||
<!--define folder properties-->
|
||||
<property name="dir.buildfile" value="."/>
|
||||
<property name="dir.workspace" value="${dir.buildfile}/.."/>
|
||||
<property name="dir.jarfile" value="${dir.workspace}"/>
|
||||
<target name="create_run_jar">
|
||||
<jar destfile="${dir.workspace}/ActiveWindowCheck.jar">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
|
||||
<attribute name="Rsrc-Main-Class" value="ru.diowo.activewindowcheck.Main"/>
|
||||
<attribute name="Class-Path" value="."/>
|
||||
<attribute name="Rsrc-Class-Path" value="./ jna-4.3.0.jar jna-platform-4.3.0.jar"/>
|
||||
</manifest>
|
||||
<zipfileset src="jar-in-jar-loader.zip"/>
|
||||
<fileset dir="${dir.buildfile}/bin"/>
|
||||
<zipfileset dir="${dir.buildfile}/lib" includes="jna-4.3.0.jar"/>
|
||||
<zipfileset dir="${dir.buildfile}/lib" includes="jna-platform-4.3.0.jar"/>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
Loading…
Reference in New Issue