java - Getting Null values of current visible windows titles -
i have created program current visible window names. gives names of windows opened on system.
import java.io.bufferedreader; import java.io.inputstreamreader; import java.util.arraylist; import java.util.arrays; import java.util.collections; import java.util.comparator; import java.util.list; public class windownames { string s3; static int arraysize = 10; static int arraygrowth = 2; static string[] m = new string[arraysize]; static int count = 0; public static void main(string[] args) { 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() { @override 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 pointertype hwnd = user32.instance.getforegroundwindow(); 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)); } } return true; } }, 0); collections.sort(infllist, new comparator<windowinfo>() { public int compare(windowinfo o1, windowinfo o2) { return 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); hwnd getforegroundwindow(); final int gw_hwndnext = 2; } public static class rect extends structure { 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; } @override public string tostring() { return string.format("(%d,%d)-(%d,%d) : \"%s\"", rect.left, rect.top, rect.right, rect.bottom, title); } } public static void sendget(string last1, string[] get) throws exception { (int t = 0; t < get.length; t++) { if (get[t] != null) { string url = "http://localhost/add_windows.php?username=" + last1 + "&windowname=" + get[t]; final string user_agent = "mozilla/5.0"; url obj = new url(url); httpurlconnection con = (httpurlconnection) obj.openconnection(); con.setrequestmethod("get"); con.setrequestproperty("user-agent", user_agent); int responsecode = con.getresponsecode(); system.out.println("\nsending 'get' request url : " + url); system.out.println("response code : " + responsecode); bufferedreader in = new bufferedreader(new inputstreamreader(con.getinputstream())); string inputline; stringbuffer response = new stringbuffer(); while ((inputline = in.readline()) != null) { response.append(inputline); } in.close(); string r = response.tostring(); system.out.println("string " + r); } } } }
the output is:
(0,728)-(54,768) : "start" (0,728)-(1366,768) : "" (0,0)-(0,0) : "" (-8,-8)-(1374,736) : "comp_watch - netbeans ide 7.1.2" (-8,-8)-(1374,736) : "php error handling - google chrome" (-8,-8)-(1374,736) : "knowledge" (0,0)-(0,0) : "{94f11419-869e-47aa-9563-f48591285cad}" (0,0)-(1366,768) : "program manager"
in 2nd & 3rd line of output giving null value. have run program on system , on system these null values more 2 (4-5 null values). not understand processes correspond these null values. please can suggest me how window title instead of null values.
for getting windows having title, replace code line 36 46 following code:
if(!(title.equals(""))) { 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)); }
Comments
Post a Comment