/* class NewEnum enumerates all top-level windows, and displays window-text and ProcessID that generated window. Uses inner-class for J/Direct callback class/function. M. Gallant 11/19/2001 */ public class NewEnum { StringBuffer strb = new StringBuffer() ; class NewEnumProc extends com.ms.dll.Callback { // inner class callback public boolean callback(int hwnd, int lparam) { int [] processID = new int[1] ; StringBuffer text = new StringBuffer(50); GetWindowText(hwnd, text, text.capacity()+1); int threadprocessid = GetWindowThreadProcessId(hwnd, processID) ; if (text.length() != 0) { // strb.append("hwnd = " + Integer.toHexString(hwnd) + "h: Text = " + text + " ProcID: " + processID[0] + "\r\n") ; strb.append("Text: " + text + " ProcID: " + processID[0] + "\r\n") ; } return true; // return TRUE to continue enumeration. } } // end inner class public NewEnumProc gen() { // get reference to instance of callback class return new NewEnumProc() ; } public static void main(String args[]) { NewEnum newenum = new NewEnum() ; NewEnumProc mycallback = newenum.gen() ; boolean results = false; results = EnumWindows(mycallback, 1) ; if( ! results ) System.out.println("Problem enumerating windows") ; else System.out.println(newenum.strb) ; } /** @dll.import("USER32") */ private static native int GetWindowText(int hwnd, StringBuffer text, int cch); /** @dll.import("USER32") */ private static native int GetWindowThreadProcessId(int hwnd, int[] lpdwProcessId) ; /** @dll.import("USER32") */ private static native boolean EnumWindows(NewEnumProc myproc, int param); }