java - how to get window title which is currently maximized means opened? -
java - how to get window title which is currently maximized means opened? -
i making application track record of opened windows on pc. copied code stack overflow. implemented , create executed in every 15 seconds threads.i making application in want top window title means title of window maximized. =============================================================================
final list<windowinfo> infllist=new arraylist<windowinfo>(); final list<integer> order=new arraylist<integer>(); int top = user32.instance.gettopwindow(0); while (top!=0) { order.add(top); top = user32.instance.getwindow(top, user32.gw_hwndnext); } user32.instance.enumwindows(new wndenumproc() { public boolean callback(int hwnd, int lparam) { if (user32.instance.iswindowvisible(hwnd)) { rect r = new rect(); user32.instance.getwindowrect(hwnd, r); if (r.left>-32000) { byte[] buffer = new byte[1024]; user32.instance.getwindowtexta(hwnd, buffer, buffer.length); string title = native.tostring(buffer); if (m.length == count) { // expand list m = arrays.copyof(m, m.length + arraygrowth); } m[count]=native.tostring(buffer); system.out.println("title===="+m[count]); count++; infllist.add(new windowinfo(hwnd, r, title)); } } homecoming true; } }, 0); collections.sort(infllist, new comparator<windowinfo>() { public int compare(windowinfo o1, windowinfo o2) { homecoming order.indexof(o1.hwnd)-order.indexof(o2.hwnd); } }); (windowinfo w : infllist) { system.out.println(w); } } public static interface wndenumproc extends stdcalllibrary.stdcallcallback { boolean callback (int hwnd, int lparam); } public static interface user32 extends stdcalllibrary { final user32 instance = (user32) native.loadlibrary ("user32", user32.class); boolean enumwindows (wndenumproc wndenumproc, int lparam); boolean iswindowvisible(int hwnd); int getwindowrect(int hwnd, rect r); void getwindowtexta(int hwnd, byte[] buffer, int buflen); int gettopwindow(int hwnd); int getwindow(int hwnd, int flag); final int gw_hwndnext = 2; } public static class rect extends construction { public int left,top,right,bottom; } public static class windowinfo { int hwnd; rect rect; string title; public windowinfo(int hwnd, rect rect, string title) { this.hwnd = hwnd; this.rect = rect; this.title = title; } public string tostring() { homecoming string.format("(%d,%d)-(%d,%d) : \"%s\"", rect.left ,rect.top,rect.right,rect.bottom,title); } } output : (0,0)-(0,0) : "" (0,728)-(54,768) : "start" (0,728)-(1366,768) : "" (-8,-8)-(1374,736) : "comp_watch - netbeans ide 7.1.2" (0,0)-(0,0) : "{94f11419-869e-47aa-9563-f48591285cad}" (0,0)-(1366,768) : "program manager" in output, gives current maximized means opened window in 4th line of output i.e. netbeans. how name of window not all. **what these 2 block doing?? while (top!=0) { order.add(top); top = user32.instance.getwindow(top, user32.gw_hwndnext); } ** , ** user32.instance.enumwindows(new wndenumproc() { public boolean callback(int hwnd, int lparam) { if (user32.instance.iswindowvisible(hwnd)) { rect r = new rect(); user32.instance.getwindowrect(hwnd, r); if (r.left>-32000) { // minimized byte[] buffer = new byte[1024]; user32.instance.getwindowtexta(hwnd, buffer, buffer.length); string title = native.tostring(buffer); if (m.length == count) { // expand list m = arrays.copyof(m, m.length + arraygrowth); } m[count]=native.tostring(buffer); system.out.println("title===="+m[count]); count++; infllist.add(new windowinfo(hwnd, r, title)); } } homecoming true; } }, 0); ------------------------------------------------------------------ java
Comments
Post a Comment