001package org.vishia.windows; 002 003import java.io.BufferedReader; 004import java.io.File; 005import java.io.IOException; 006import java.io.InputStreamReader; 007import java.util.Map; 008import java.util.TreeMap; 009 010import org.vishia.mainCmd.MainCmd_ifc; 011import org.vishia.mainCmd.Report; 012 013public class WindowMng 014{ 015 016 static{ 017 //NOTE: it isn't used currently, the dll doesn't exists. 018 File fileDll = new File("exe/windowMng.dll"); 019 if(fileDll.exists()){ 020 //System.load(fileDll.getAbsolutePath()); 021 } 022 023 } 024 025 final MainCmd_ifc cmdIfc; 026 027 public final static native void listAllWindows(); 028 029 public static class WindowPropertied 030 { 031 String title; 032 int pid; 033 int window_id; 034 } 035 036 037 038 public WindowMng(MainCmd_ifc cmdIfc) 039 { 040 this.cmdIfc = cmdIfc; 041 } 042 043 044 045 /**Searches the windows-handler (hWnd) for the given title of window. 046 * It works with a executable written in C, which produces a list of all windows 047 * with its hWind. 048 * @param sTitle The title, or the start of title. 049 * @return 0 if not found, elsewhere the hWnd. 050 */ 051 public static int getWindowsHandler(String sTitle) 052 { 053 //listAllWindows(); 054 //Map<String, WindowPropertied> list = new TreeMap<String, WindowPropertied>(); 055 int hWnd = 0; 056 057 ProcessBuilder processBuilder = new ProcessBuilder("exe/getListWindow.exe"); 058 //ClassLoader loader = getClass().getClassLoader(); 059 //getClass().getPackage(). 060 061 StringBuffer uOut = new StringBuffer(); 062 try 063 { Process process = processBuilder.start(); 064 BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream())); 065 String sOut; 066 while( (sOut = output.readLine()) != null) 067 { String[] s1 = sOut.split(";"); 068 if(s1.length >=4){ 069 String sTitleWin = s1[3].trim().substring(1); //without " 070 if(sTitleWin.startsWith(sTitle) 071 ){ //|| s1[3].contains("Editor") ) 072 hWnd = Integer.parseInt(s1[0].trim()); 073 } 074 if(uOut!=null) uOut.append(sOut + "\n"); 075 076 } 077 } 078 } 079 catch(Exception exception){ System.out.println(exception.toString()); } 080 //System.out.println("***** ende **********"); 081 082 //cmdIfc.executeCmdLine(processBuilder, "getListWindow", null, 0, out, null); 083 //while(processBuilder.) 084 //return list; 085 return hWnd; 086 } 087 088}