com.jacob.com.Variant Java Examples

The following examples show how to use com.jacob.com.Variant. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FindStr.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 指定区域内读取文字
 * 		<li>须提前设置好点阵字库 {@link Com#setDict(int, String)}
 * @param xStart 区域的左上X坐标
 * @param yStart 区域的左上Y坐标
 * @param xEnd 区域的右下X坐标
 * @param yEnd 区域的右下Y坐标
 * @param colorFormat 颜色格式串
 * 			<li>RGB单色识别:"9f2e3f-000000"
 * 			<li>RGB单色差色识别:"9f2e3f-030303"
 * 			<li>RGB多色识别(最多支持10种,每种颜色用"|"分割):"9f2e3f-030303|2d3f2f-000000|3f9e4d-100000"
 * 			<li>HSV多色识别(最多支持10种,每种颜色用"|"分割):"20.30.40-0.0.0|30.40.50-0.0.0"
 * 			<li>背景色识别:"b@ffffff-000000"
 * @param lineBreak 换行符,为空或者null则不使用换行符分割。读取的文字每行换行时会加上此字符串作为换行分割
 * @param sim 相似度,取值范围0.1-1.0 , 一般情况下0.9即可。越大,查找的越精准,误差越小,速度越快
 * @param useDict 字库的序号,以此来设定使用哪个字库.   {@link Com#setDict(int, String)} 便是此设置的int序号
 * @return String 若是没找到,返回null
 */
public String readStr(int xStart,int yStart,int xEnd,int yEnd,String colorFormat,String lineBreak, double sim,int useDict){
	String xnx3_result="";
	try {
		active.invoke("UseDict",useDict);
		Variant[] var=new Variant[6];
		var[0]=new Variant(xStart);
		var[1]=new Variant(yStart);
		var[2]=new Variant(xEnd);
		var[3]=new Variant(yEnd);
		var[4]=new Variant(colorFormat);
		var[5]=new Variant(sim);
		xnx3_result=active.invoke("Ocr",var).getString();
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this,"readStr","读取文字异常捕获:"+e.getMessage());
	}
	
	if(xnx3_result.length()==0){
		xnx3_result=null;
	}
	
	return xnx3_result;
}
 
Example #2
Source File: Color.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
 * 判断某点颜色是否跟指定的相同或相似
 * @param color:要判断的颜色(FFFFFF)
    * @return 若颜色匹配,此点是这颜色,则返回true
 */
public boolean findColor(int x,int y,String color){
	boolean xnx3_result=false;
	try {
		Variant[] var=new Variant[4];
		var[0]=new Variant(x);
		var[1]=new Variant(y);
		var[2]=new Variant(color+"-"+Command.dianColor);
		var[3]=new Variant(Command.dianSim);
		
		int cmpColor=activeDm.invoke("CmpColor",var).getInt();
		var=null;

		if(cmpColor==0){
			xnx3_result=true;
		}
		cmpColor=0;
	} catch (Exception e) {
		new Func.File().log("获取颜色findColor异常捕获:"+e.getMessage());
	}
	return xnx3_result;
}
 
Example #3
Source File: FindStr.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
 * 读取文字
 * <li>xStart,xEnd,yStart,yEnd   读取文字所在的区域
 * <li>colorFormat:文字颜色及范围,如ffd800-888888,多个用|分割
 * <li>sim:相似度,最大为1,一般0.9便可
 * @return:若是没找到,返回""
 * 
 */
public String readStr(int xStart,int yStart,int xEnd,int yEnd,String colorFormat,double sim,int useDict){
	String xnx3_result="";
	try {
		activeDm.invoke("UseDict",useDict);
		Variant[] var=new Variant[6];
		var[0]=new Variant(xStart);
		var[1]=new Variant(yStart);
		var[2]=new Variant(xEnd);
		var[3]=new Variant(yEnd);
		var[4]=new Variant(colorFormat);
		var[5]=new Variant(sim);
		xnx3_result=activeDm.invoke("Ocr",var).getString();
	} catch (Exception e) {
		e.printStackTrace();
		new Func.File().log("读取文字异常捕获:"+e.getMessage());
	}
	
	return xnx3_result;
}
 
Example #4
Source File: OfficeHtmlUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * EXCEL转HTML
 * 
 * @param xlsfile
 *            EXCEL文件全路径
 * @param htmlfile
 *            转换后HTML存放路径
 */
public void excelToHtml(String xlsfile, String htmlfile) {
	ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
	try {
		app.setProperty("Visible", new Variant(false));
		Dispatch excels = app.getProperty("Workbooks").toDispatch();
		Dispatch excel = Dispatch.invoke(excels, "Open", Dispatch.Method, new Object[] { xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
		Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
		Variant f = new Variant(false);
		Dispatch.call(excel, "Close", f);
		org.jeecgframework.core.util.LogUtil.info("wordtohtml转换成功");
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		app.invoke("Quit", new Variant[] {});
	}
}
 
Example #5
Source File: Window.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
 * 屏幕坐标与窗口坐标互相转化
 * 
 * @param type 转换类型
 * 		<li>0表示屏幕转化为窗口(整个窗口的范围矩形,窗口的边框、标题栏、滚动条及菜单等都在这个矩形内)
    * 		<li>1表示窗口转化成屏幕
    * 		<li>2表示屏幕转化为窗口客户区(不包括窗口的边框、标题栏、滚动条及菜单)
    * 		<li>3表示窗口客户区转化为屏幕
    * 		<li>4表示窗口转化为窗口客户区(不包括窗口的边框、标题栏、滚动条及菜单)
    * 		<li>5表示窗口客户区转化为窗口
    * 
    * @return int[2] 返回x、y坐标。若是出错,返回-1,-1
 */
public int[] windowPosition(int hwnd,int x,int y,int type){
	int[] xnx3_result={-1,-1};
	
	Variant[] var=new Variant[4];
	int[] getResult=null;
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(x);
		var[2]=new Variant(y);
		var[3]=new Variant(type);
		getResult=this.activeDbWindow.invoke("CoordinateFtoB",var).toSafeArray().toIntArray();
		xnx3_result[0]=getResult[0];
		xnx3_result[1]=getResult[1];
	} catch (Exception e) {
		e.printStackTrace();
		new Func.File().log("窗口坐标转换windowPosition异常捕获:"+e.getMessage());
	}finally{
		var=null;
		getResult=null;
	}
	
	return xnx3_result;
}
 
Example #6
Source File: OfficeHtmlUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * WORD转HTML
 * 
 * @param docfile
 *            WORD文件全路径
 * @param htmlfile
 *            转换后HTML存放路径
 */
public void wordToHtml(String docfile, String htmlfile) {
	ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
	try {
		app.setProperty("Visible", new Variant(false));
		Dispatch docs = app.getProperty("Documents").toDispatch();
		Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method, new Object[] { docfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
		Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(WORD_HTML) }, new int[1]);
		Variant f = new Variant(false);
		Dispatch.call(doc, "Close", f);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		app.invoke("Quit", new Variant[] {});
	}
}
 
Example #7
Source File: LanAnswer.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
 * 截取这个范围内,3秒动画,图像质量为中等50,动画帧率间隔为100ms
 * faqCapture(0,2,72,12,50,100,3000)
 * 
 * @param xStart 左上角X坐标
 * @param yStart 左上角Y坐标
 * @param xEnd 右下角X坐标
 * @param yEnd 右下角Y坐标
 * @param quality 图像或动画品质,或者叫压缩率,此值越大图像质量越好 取值范围(1-100)
 * @param delay 截取动画时用,表示相隔两帧间的时间间隔,单位毫秒 (如果只是截取静态图像,这个参数必须是0)
 * @param time 表示总共截取多久的动画,单位毫秒 (如果只是截取静态图像,这个参数必须是0)
 * 
 * @return 整数型,图像或者动画句柄,0为失败 
 */
public int faqCapture(int xStart, int yStart, int xEnd, int yEnd, int quality, int delay, int time){
	int xnx3_result = 0;

	try {
		Variant[] var=new Variant[7];
		var[0]=new Variant(xStart);
		var[1]=new Variant(yStart);
		var[2]=new Variant(xEnd);
		var[3]=new Variant(yEnd);
		var[4]=new Variant(quality);
		var[5]=new Variant(delay);
		var[6]=new Variant(time);
		
		xnx3_result=activeDm.invoke("FaqCapture",var).getInt();
		var=null;

	} catch (Exception e) {
		e.printStackTrace();
		new Func.File().log("局域网答题faqCapture异常捕获:"+e.getMessage());
	}
	
	return xnx3_result;
}
 
Example #8
Source File: LanAnswer.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
 * 发送指定的图像句柄到指定的服务器,并等待返回结果(同步等待)
 * @param server 字符串: 服务器地址以及端口,格式为(ip:port),例如 "192.168.1.100:12345" 多个地址可以用"|"符号连接。比
 * @param handle 由FaqCapture获取到的句柄
 * @param request_type 整形数: 取值定义如下 <li>0 : 要求获取坐标<li>1 : 要求获取选项,比如(ABCDE)<li>2 : 要求获取文字答案
 * @param time_out 整形数: 表示等待多久,单位是毫秒
 * @return String 包含"Error"为失败,否则返回结果  OK:答案<li>当request_type 为0时,答案的格式为"x,y" (不包含引号)<li>当request_type 为1时,答案的格式为"1" "2" "3" "4" "5" "6" (不包含引号)<li>当request_type 为2时,答案就是要求的答案 比如 "李白" (不包含引号)
 */
public String faqSend(String server, long handle, int request_type, int time_out){
	String xnx3_result="Error";
	try {
		Variant[] var=new Variant[4];
		var[0]=new Variant(server);
		var[1]=new Variant(handle);
		var[2]=new Variant(request_type);
		var[3]=new Variant(time_out);
		
		xnx3_result=activeDm.invoke("FaqSend",var).getString();
		var=null;

	} catch (Exception e) {
		new Func.File().log("局域网答题faqSend异常捕获:"+e.getMessage());
	}
	
	return xnx3_result;
}
 
Example #9
Source File: File.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
	 * 截图保存日志记录,同时添加时间
	 * @param message
	 */
	public void screenImage(String message){
		try {
			int enableDisplayDebug=activeDm.invoke("EnableDisplayDebug",1).getInt();
			if(enableDisplayDebug==0){
				log("EnableDisplayDebug-截图开启失败");
			}
			
			Variant[] var=new Variant[5];
			var[0]=new Variant(0);
			var[1]=new Variant(0);
			var[2]=new Variant(1024);
			var[3]=new Variant(768);
			var[4]=new Variant(Command.thisFilePath+"\\"+Command.screenNoteFile+"\\"+message+"-"+include.Module.Now_date.xnx3_time().replaceAll(":", ":")+".bmp");
			activeDm.invoke("CapTure",var);
			int capTurePre=activeDm.invoke("CapturePre",var[4]).getInt();
			var=null;
//			log("截图-->"+(capTurePre==0? "失败":"成功"));
			
			activeDm.invoke("EnableDisplayDebug",0);
		} catch (Exception e) {
			log("截图保存日志Func.screenImage()异常捕获:"+e.getMessage());
		}
	}
 
Example #10
Source File: File.java    From xunxian with Apache License 2.0 6 votes vote down vote up
/**
	 * 保存出bmp格式图片
	 * @param message:截图
	 * @param filePath
	 */
	public void screenImage(String message,int xStart,int yStart,int xEnd,int yEnd){
		try {
			int enableDisplayDebug=activeDm.invoke("EnableDisplayDebug",1).getInt();
			if(enableDisplayDebug==0){
				log("EnableDisplayDebug-截图开启失败");
			}
			
			Variant[] var=new Variant[5];
			var[0]=new Variant(xStart);
			var[1]=new Variant(yStart);
			var[2]=new Variant(xEnd);
			var[3]=new Variant(yEnd);
			var[4]=new Variant(Command.thisFilePath+"\\"+Command.screenNoteFile+"\\"+message+".bmp");
			activeDm.invoke("CapTure",var);
			int capTurePre=activeDm.invoke("CapturePre",var[4]).getInt();
			var=null;
//			log(message+"截图-->"+(capTurePre==0? "失败":"成功"));
			
			activeDm.invoke("EnableDisplayDebug",0);
		} catch (Exception e) {
			log("截图保存日志Func.screenImage()异常捕获:"+e.getMessage());
		}
	}
 
Example #11
Source File: OfficeHtmlUtil.java    From jeecg with Apache License 2.0 6 votes vote down vote up
/**
 * EXCEL转HTML
 * 
 * @param xlsfile
 *            EXCEL文件全路径
 * @param htmlfile
 *            转换后HTML存放路径
 */
public void excelToHtml(String xlsfile, String htmlfile) {
	ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
	try {
		app.setProperty("Visible", new Variant(false));
		Dispatch excels = app.getProperty("Workbooks").toDispatch();
		Dispatch excel = Dispatch.invoke(excels, "Open", Dispatch.Method, new Object[] { xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
		Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
		Variant f = new Variant(false);
		Dispatch.call(excel, "Close", f);
		org.jeecgframework.core.util.LogUtil.info("wordtohtml转换成功");
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		app.invoke("Quit", new Variant[] {});
	}
}
 
Example #12
Source File: IiTunes.java    From The-5zig-Mod with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the currently targetd track.
 *
 * @return An ITTrack object corresponding to the currently targeted track.
 * Will be set to NULL if there is no currently targeted track.
 */
public IITTrack getCurrentTrack() {
	Variant variant = iTunes.getProperty("CurrentTrack");
	if (variant.isNull()) {
		return null;
	}
	Dispatch item = variant.toDispatch();
	IITTrack track = new IITTrack(item);
	if (track.getKind() == IITTrackKind.ITTrackKindFile) {
		return new IITFileOrCDTrack(item);
	} else if (track.getKind() == IITTrackKind.ITTrackKindCD) {
		return new IITFileOrCDTrack(item);
	} else if (track.getKind() == IITTrackKind.ITTrackKindURL) {
		return new ITURLTrack(item);
	} else {
		return track;
	}
}
 
Example #13
Source File: IiTunes.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
/**
 * Returns the currently targetd track.
 *
 * @return An ITTrack object corresponding to the currently targeted track.
 * Will be set to NULL if there is no currently targeted track.
 */
public IITTrack getCurrentTrack() {
	Variant variant = iTunes.getProperty("CurrentTrack");
	if (variant.isNull()) {
		return null;
	}
	Dispatch item = variant.toDispatch();
	IITTrack track = new IITTrack(item);
	if (track.getKind() == IITTrackKind.ITTrackKindFile) {
		return new IITFileOrCDTrack(item);
	} else if (track.getKind() == IITTrackKind.ITTrackKindCD) {
		return new IITFileOrCDTrack(item);
	} else if (track.getKind() == IITTrackKind.ITTrackKindURL) {
		return new ITURLTrack(item);
	} else {
		return track;
	}
}
 
Example #14
Source File: SystemUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 弹出托盘气泡
 * <li>要有托盘才能弹出气泡,可使用 {@link #addTray(int, String)} 创建一个托盘
 * @param hwnd 窗口句柄
 * @param title 气泡标题
 * @param message 气泡信息的内容
 * @param mode 气泡显示模式,分为以下:
 * 				<li>0 : 没有图标
 * 				<li>1 : 信息图标
 * 				<li>2 : 警告图标
 * 				<li>3 : 错误图标
 * 				<li>4 : 程序图标
 * @return 成功|失败
 */
public boolean showTipTray(int hwnd,String title,String message,int mode){
	boolean result=true;
	
	Variant[] var=new Variant[4];
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(message);
		var[2]=new Variant(title);
		var[3]=new Variant(mode);
		this.activePlugin365.invoke("TipTray",var);
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this, "showTipTray", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result;
}
 
Example #15
Source File: SystemUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 将某个窗口装载到托盘(创建托盘,只是生成一个托盘,鼠标放上显示title文字,托盘图标为运行程序的图标,也就是java的图标)
 * @param hwnd 窗口句柄
 * @param title 鼠标放上显示的文字
 * @return 成功|失败
 */
public boolean addTray(int hwnd,String title){
	boolean result=true;
	
	Variant[] var=new Variant[2];
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(title);
		this.activePlugin365.invoke("AddTray",var);
	} catch (Exception e) {
		result=false;
		e.printStackTrace();
		log.debug(this, "addTray", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result;
}
 
Example #16
Source File: SystemUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 卸载已装载的托盘
 * @param hwnd 窗口句柄
 * @return 成功|失败
 */
public boolean delTray(int hwnd){
	boolean result=true;
	
	Variant[] var=new Variant[1];
	try {
		var[0]=new Variant(hwnd);
		this.activePlugin365.invoke("DelTray",var);
	} catch (Exception e) {
		result=false;
		e.printStackTrace();
		log.debug(this, "delTray", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result;
}
 
Example #17
Source File: Com.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置点阵字库
 * @param num 字库的序号,取值为0-9,目前最多支持10个字库,序号设置不可以重复
 * @param fileName 字库文件名,如 mapPositionDict.txt ,此文件须位于设置的 {@link Com#setResourcePath(String)} 资源路径里,也就是资源路径必须于此函数之前先设置好
 * @return boolean true:成功
 */
public boolean setDict(int num,String fileName){
	boolean xnx3_result=false;
	
	Variant[] var=new Variant[2];
	try {
		var[0]=new Variant(num);
		var[1]=new Variant(fileName);
		if(activeBean.getDm().invoke("SetDict",var).getInt()==1){
			xnx3_result=true;
		}
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this, "setDict", "异常:"+e.getMessage());
	}finally{
		var=null;
	}
	return xnx3_result;
}
 
Example #18
Source File: SystemUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置系统的分辨率、系统色深
 * @param width 屏幕分辨率宽度
 * @param height 屏幕分辨率高度
 * @param depth 系统色深
 * @return true:成功
 */
public boolean setScreen(int width,int height,int depth){
	Variant[] var=new Variant[3];
	int result=0;
	try {
		var[0]=new Variant(width);
		var[1]=new Variant(height);
		var[2]=new Variant(depth);
		result=this.activeDm.invoke("SetScreen",var).getInt();
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this, "setScreen", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result==1; 
}
 
Example #19
Source File: Color.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 判断某点颜色是否跟指定的相同或相似
 * @param x X坐标
 * @param y Y坐标
 * @param color 颜色字符串,可以支持偏色,多色,例如 "ffffff-202020|000000-000000" 这个表示白色偏色为202020,和黑色偏色为000000.颜色最多支持10种颜色组合.
 * @param similarity 相似度(0.1-1.0)
    * @return 若颜色匹配,此点是这颜色,则返回true
 */
public boolean findColor(int x,int y,String color,float similarity){
	boolean xnx3_result=false;
	try {
		Variant[] var=new Variant[4];
		var[0]=new Variant(x);
		var[1]=new Variant(y);
		var[2]=new Variant(color);
		var[3]=new Variant(similarity);
		
		int cmpColor=activeDm.invoke("CmpColor",var).getInt();
		var=null;

		if(cmpColor==0){
			xnx3_result=true;
		}
		cmpColor=0;
	} catch (Exception e) {
		log.debug(this,"findColor","获取颜色异常捕获:"+e.getMessage());
	}
	return xnx3_result;
}
 
Example #20
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 移动窗口到屏幕指定坐标点
 * @param hwnd 移动窗口的句柄
 * @return 成功:true
 */
public boolean moveWindow(int hwnd,int x, int y){
	boolean xnx3_result=false;
	Variant[] var=new Variant[3];
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(x);
		var[2]=new Variant(y);
		int getResult=active.invoke("MoveWindow",var).getInt();
		if(getResult==1){		//成功
			xnx3_result=true;
		}
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this,"MoveWindow","移动窗口时异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return xnx3_result;
}
 
Example #21
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置指定窗口的大小
 * @param hwnd 窗口句柄
 * @param width 要设置成的宽度
 * @param height 要设置成的高度
 * @return 设置成功返回true
 */
public boolean setWindowSize(int hwnd,int width,int height){
	Variant[] var=new Variant[3];
	int result=0;
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(width);
		var[2]=new Variant(height);
		result=this.active.invoke("SetClientSize",var).getInt();
	} catch (Exception e) {
		log.debug(this, "setWindowSize", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	return result==1; 
}
 
Example #22
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置窗口的标题
 * @param hwnd 指定的窗口句柄
 * @param title 新标题
 * @return boolean true:成功
 */
public boolean setWindowTitle(int hwnd,String title){
	Variant[] var=new Variant[2];
	int result=0;
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(title);
		result=this.active.invoke("SetWindowText",var).getInt();
	} catch (Exception e) {
		log.debug(this, "SetWindowText", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result==1; 
}
 
Example #23
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置窗口的透明度
 * @param hwnd 指定的窗口句柄
 * @param trans 透明度取值(0-255) 越小透明度越大 0为完全透明(不可见) 255为完全显示(不透明)
 * @return boolean true:成功
 */
public boolean setWindowTransparent(int hwnd,int trans){
	Variant[] var=new Variant[2];
	int result=0;
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(trans);
		result=this.active.invoke("setWindowTransparent",var).getInt();
	} catch (Exception e) {
		log.debug(this, "setWindowTransparent", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result==1; 
}
 
Example #24
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 判断窗口的状态,获得一些窗口的属性,可直接使用  可直接使用 {@link Window#windowIsExist(int)} 、 {@link Window#windowIsVisible(int)} ...
 * @param hwnd 指定的窗口句柄
 * @param type 查询的状态:<li>0 : 判断窗口是否存在
 * 						<li>1 : 判断窗口是否处于激活
 * 						<li>2 : 判断窗口是否可见
 * 						<li>3 : 判断窗口是否最小化
 * 						<li>4 : 判断窗口是否最大化
 * 						<li>5 : 判断窗口是否置顶
 * 						<li>6 : 判断窗口是否无响应
 * @return boolean true:是
 */
public boolean windowState(int hwnd,int type){
	Variant[] var=new Variant[2];
	int result=0;
	try {
		var[0]=new Variant(hwnd);
		var[1]=new Variant(type);
		result=this.active.invoke("GetWindowState",var).getInt();
	} catch (Exception e) {
		log.debug(this, "windowState", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result==1; 
}
 
Example #25
Source File: SystemUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 蜂鸣器,进行发音蜂鸣
 * @param frequency 频率,50到10000之间便可,数值越大越尖越刺耳,一般情况500就可
 * @param time 蜂鸣时间,单位为毫秒
 * @return true:成功
 */
public boolean beep(int frequency,int time){
	Variant[] var=new Variant[2];
	int result=0;
	try {
		var[0]=new Variant(frequency);
		var[1]=new Variant(time);
		result=this.activeDm.invoke("Beep",var).getInt();
	} catch (Exception e) {
		log.debug(this, "beep", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result==1; 
}
 
Example #26
Source File: File.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 截图保存,保存为png格式
 * @param xStart 区域的左上X坐标
 * @param yStart 区域的左上Y坐标
 * @param xEnd 区域的右下X坐标
 * @param yEnd 区域的右下Y坐标
 * @param fileName 保存的文件名
 * 		<li>只有文件名,如 "xnx3.png" 保存的地方为 {@link Com#setResourcePath(String)} 中设置的目录
 * 		<li>也可以指定全路径名,如"c:\\xunxian\\xnx3.png"
 */
public void screenImage(int xStart,int yStart,int xEnd,int yEnd, String fileName){
	try {
		int enableDisplayDebug=active.invoke("EnableDisplayDebug",1).getInt();
		if(enableDisplayDebug==0){
			log.debug(this,"screenImage","EnableDisplayDebug-截图开启失败");
		}
		
		Variant[] var=new Variant[5];
		var[0]=new Variant(xStart);
		var[1]=new Variant(yStart);
		var[2]=new Variant(xEnd);
		var[3]=new Variant(yEnd);
		var[4]=new Variant(fileName);
		int capTurePre=active.invoke("CapturePng",var).getInt();
		var=null;
		
		if(capTurePre==0){
			log.debug(this,"screenImage","截图失败");
		}
		
		active.invoke("EnableDisplayDebug",0);
	} catch (Exception e) {
		log.debug(this,"screenImage","截图异常捕获:"+e.getMessage());
	}
}
 
Example #27
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 查找符合类名或者标题名的顶层可见窗口,如果指定了parentHwnd,则在parentHwnd的第一层子窗口中查找.
 * @param parentHwnd 父窗口句柄,如果为0,则匹配所有顶层窗口
 * @param className 窗口类名,如果为空,则匹配所有. 这里的匹配是模糊匹配.
 * @param title 窗口标题,如果为空,则匹配所有. 这里的匹配是模糊匹配.
 * @return 找到的窗口句柄,0为没有找到
 */
public int findWindow(int parentHwnd,String className,String title){
	Variant[] var=new Variant[3];
	int result=0;
	if(className==null){
		className="";
	}
	if(title==null){
		title="";
	}
	try {
		var[0]=new Variant(parentHwnd);
		var[1]=new Variant(className);
		var[2]=new Variant(title);
		result=this.active.invoke("FindWindowEx",var).getInt();
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this, "findChildWindow", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	return result; 
}
 
Example #28
Source File: Window.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 获取窗口在屏幕上的位置,窗口可被遮挡,不可最小化
 * @param hwnd 目标窗口句柄
 * @return int[] 参数介绍:
 * 			<li>[0]:调用C函数执行情况。 0失败;1成功
 * 			<li>[1]:返回窗口左上角X坐标
 * 			<li>[2]:返回窗口左上角Y坐标
 * 			<li>[3]:返回窗口右下角X坐标
 * 			<li>[4]:返回窗口右下角Y坐标
 */
public int[] getWindowRect(int hwnd){
	int result[]={0,0,0,0,0};
	
	Variant[] var=new Variant[5];
	try{
		var[0]=new Variant(hwnd);
		var[1]=new Variant(0,true);
		var[2]=new Variant(0,true);
		var[3]=new Variant(0,true);
		var[4]=new Variant(0,true);
		result[0]=active.invoke("GetWindowRect",var).getInt();
	}catch (Exception e) {
		e.printStackTrace();
	}finally{
		result[1]=var[1].getInt();
		result[2]=var[2].getInt();
		result[3]=var[3].getInt();
		result[4]=var[4].getInt();
		
		var=null;
	}
	
	return result;
}
 
Example #29
Source File: FindPic.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 查找图片,返回找到的所有图片,限制1500个以内
 * @param xStart 区域的左上X坐标
 * @param yStart 区域的左上Y坐标
 * @param xEnd 区域的右下X坐标
 * @param yEnd 区域的右下Y坐标
 * @param pic 图像集,多个用|分割,24位色bmp格式,且边框为同一种颜色,比如"test.bmp|test2.bmp|test3.bmp"
 * @param deviationColor 颜色偏差,比如"203040" 表示RGB的色偏分别是20 30 40 (这里是16进制表示)
 * @param sim 相似度,取值范围0.1-1.0 , 一般情况下0.9即可<li>越大,查找的越精准,误差越小,速度越快
 * @param order <li>0: 从左到右,从上到下 
 * 				<li>1: 从左到右,从下到上 
 * 				<li>2: 从右到左,从上到下 
 * 				<li>3: 从右到左, 从下到上
 * @return 返回找到的所有图片,格式如:"id,x,y|id,x,y..|id,x,y"
 * 		<br/>比如"0,100,20|2,30,40" 表示找到了两个,第一个,对应的图片是图像序号为0的图片,坐标是(100,20),第二个是序号为2的图片,坐标(30,40)
 * 		<li>出错返回null
 */
public String findPics(int xStart,int yStart,int xEnd,int yEnd,String pic,String deviationColor,double sim,int order){
	String result=null;
	Variant[] var=new Variant[8];
	try {
		var[0]=new Variant(xStart);
		var[1]=new Variant(yStart);
		var[2]=new Variant(xEnd);
		var[3]=new Variant(yEnd);
		var[4]=new Variant(pic);
		var[5]=new Variant(deviationColor);
		var[6]=new Variant(sim);
		var[7]=new Variant(order);
		result=active.invoke("FindPicEx",var).getString();
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this,"findPicExPositions","查找图片异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}

	return result;
}
 
Example #30
Source File: FindPic.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 判断指定的区域,在指定的时间内(秒),图像数据是否一直不变.(卡屏)
 * <li>若是出现变化,会立即中断计时,返回false
 * <li>若未出现变化,则会阻塞 time 的时间
 * @param xStart 区域的左上X坐标
 * @param yStart 区域的左上Y坐标
 * @param xEnd 区域的右下X坐标
 * @param yEnd 区域的右下Y坐标
 * @param time 需要等待的时间,单位是秒
 * @return true:是一直不变
 */
public boolean isDisplayDead(int xStart,int yStart,int xEnd,int yEnd,int time){
	Variant[] var=new Variant[5];
	int result=0;
	try {
		var[0]=new Variant(xStart);
		var[1]=new Variant(yStart);
		var[2]=new Variant(xEnd);
		var[3]=new Variant(yEnd);
		var[4]=new Variant(time);
		result=this.active.invoke("IsDisplayDead",var).getInt();
	} catch (Exception e) {
		e.printStackTrace();
		log.debug(this, "isDisplayDead", "异常捕获:"+e.getMessage());
	}finally{
		var=null;
	}
	
	return result==1; 
}