C#此时金山的屏幕取词,编译无错误,但是没有反应!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using XDICTGRB;
namespace ScreenCatchTextProject1
{
public partial class Form1 : Form,IXDictGrabSink
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(
IntPtr hwnd,
int hWndlnsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags);
private void Form1_Load(object sender, EventArgs e)
{
SetWindowPos(this.Handle,
-1,
Screen.PrimaryScreen.Bounds.Width / 2,
Screen.PrimaryScreen.Bounds.Height / 2,
this.Width,
this.Height,
0);
int i;
GrabProxy gp = new GrabProxy();//取词代理对象
gp.GrabInterval = 1;//抓取时间间隔
gp.GrabMode = XDictGrabModeEnum.XDictGrabMouseWithCtrl;//抓取模式
gp.GrabFlag = (XDictGrabFlagEnum.XDictGrabDisableButton
& XDictGrabFlagEnum.XDictGrabDisableCaption
& XDictGrabFlagEnum.XDictGrabDisableMenu);
gp.GrabEnabled = true;//是否取词的属性
i = gp.AdviseGrab(this);//要实现的接口
}
int IXDictGrabSink.QueryWord(string WordString,
int lCursorX,
int lCursorY,
string SentenceString,
ref int lLoc,
ref int lStart)
{
this.textBox4.Text = SentenceString;
this.textBox3.Text = lCursorX.ToString() + " " + lCursorY.ToString();
this.textBox2.Text = SentenceString.Substring(lLoc, 1);
this.textBox1.Text = GetWord(SentenceString, lLoc + 1);
return 1;
}
private string GetWord(string SentenceString, int lLoc)
{
int iR = 0;
int iL = 0;
int ilen = 0;
ilen = SentenceString.Length;
string str = "abcedfghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
for (iL = lLoc; iL > 0; iL--)
{
if (str.IndexOf(SentenceString.Substring(iL, 1)) == -1)
break;
}
for (iR = lLoc; iR < ilen; iR++)
{
if (str.IndexOf(SentenceString.Substring(iR, 1)) == -1)
break;
}
return SentenceString.Substring(iL + 1, iR - iL - 1);
}
}
}
以上是代码,编译无错误,但是运行后,取词无反应。猜测原因:
1、所在系统为WIN10,是不是不能用。
2、考虑的技术没有全面。
希望大牛能帮帮忙,给点意见!