当前位置:

屏幕取词

窗体总在前端显示

1、命名空间using System.Runtime.InteropServices;

2、函数

///


/// 窗体总在前端显示(小荷扬扬原创)
///


///窗体的句柄
///窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面
///窗口新的x坐标
///窗口的新的y坐标
///窗口的宽度
///窗口的高度
///
///
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(
IntPtr hwnd,
int hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags
);

3.在frm_load中调用函数

private void FrmScreen_Load(object sender, EventArgs e)
{
SetWindowPos(this.Handle, -1, Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2, this.Width, this.Height, 0);

}

屏幕取词

1、using XDICTGRB;

2、 public partial class FrmScreen : Form, IXDictGrabSink(继承接口)

3、取词代理对象

int i;//取词的返回值,用于注册和注销取词
GrabProxy gp = new GrabProxy();//取词代理对象

4、设置取词代理对象

gp.GrabInterval = 1;//指抓取时间间隔
gp.GrabMode = XDictGrabModeEnum.XDictGrabMouse;//设定取词的属性
//Const XDictGrabDisableButton = 4
//不取按钮上的文字
//Const XDictGrabDisableCaption = 8
//不取标题栏的文字
//Const XDictGrabDisableMenu = 2
//不取菜单的文字
//Const XDictGrabOnlyEnglish = 1
//只取英文
gp.GrabFlag = (XDictGrabFlagEnum.XDictGrabDisableButton & XDictGrabFlagEnum.XDictGrabDisableMenu & XDictGrabFlagEnum.XDictGrabDisableCaption);
gp.GrabEnabled = true;//是否取词的属性
i = gp.AdviseGrab(this);//要实现的接口

5、实现取词代理接口

///


/// 取词实现的接口(小荷扬扬原创)
///


///
///x坐标
///y坐标
///语句
///鼠标所在语句的位置
///
///
int IXDictGrabSink.QueryWord(string WordString, int lCursorX, int lCursorY, string SentenceString, ref int lLoc, ref int lStart)
{

//取词后所做的处理

}

开启屏幕取词窗口

if (Button.Caption=="开启屏幕取词")//(小荷扬扬原创)
{
if (screen==null )//如果没有窗体的实例开启屏幕取词
{
screen = new FrmScreen( );
screen.Show();
}
Button.Caption = "关闭屏幕取词";
}
else if(Button.Caption=="关闭屏幕取词")
{
if (screen != null)
{
screen.Close();
screen = null;
}
Button.Caption = "开启屏幕取词";
}

}

 

本文由客户端添加

 

光锥极客  2012-03-25 01:57:28  阅读量:2115