(转)金山词霸屏幕取词C#应用(XdictGrb.dll)

原帖地址:http://hi.baidu.com/ykhykh/blog/item/8ebecb119214f112b9127ba5.html

屏幕取词窗口在前端显示才能正确屏幕取词哦

窗体总在前端显示

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

2、函数

/// <summary>
                /// 窗体总在前端显示(小荷扬扬原创)
                /// </summary>
                /// <param name="hwnd">窗体的句柄</param>
                /// <param name="hWndInsertAfter">窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面</param>
                /// <param name="x">窗口新的x坐标</param>
                /// <param name="y">窗口的新的y坐标</param>
                /// <param name="cx">窗口的宽度</param>
                /// <param name="cy">窗口的高度</param>
                /// <param name="wFlags"></param>
                /// <returns></returns>
                [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、实现取词代理接口

                /// <summary>
                /// 取词实现的接口(小荷扬扬原创)
                /// </summary>
                /// <param name="WordString"></param>
                /// <param name="lCursorX">x坐标</param>
                /// <param name="lCursorY">y坐标</param>
                /// <param name="SentenceString">语句</param>
                /// <param name="lLoc">鼠标所在语句的位置</param>
                /// <param name="lStart"></param>
                /// <returns></returns>
                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 = "开启屏幕取词";
                    }

}

注意:如您开启了卡巴斯基等杀毒软件和防火墙,您需要将屏幕取词添加到信任区。不然不能启动屏幕取词功能。

屏幕取词概念请参阅转载文章

http://hi.baidu.com/ykhykh/blog/item/5446232d60994636349bf7b1.html

XdictGrb.dll 下载地址

http://download.csdn.net/source/216529(要注册csdn的帐号才能下载的,相信大家都有csdn的帐号吧。没有的话就注册一个吧。o(∩_∩)o...哈哈)

注:未经金山公司批准发布其软件的一部分应该是侵权的。

 

 

另外相关资料:

http://www.cnblogs.com/star65225692/articles/1134818.html

CSDN上也有一贴:
http://topic.csdn.net/u/20070511/17/c01fbd1d-c653-4a32-b733-be171f08afa6.html

 

posted on 2008-10-06 15:29  冷月孤峰  阅读(3956)  评论(3编辑  收藏  举报