C#此时金山的屏幕取词,编译无错误,但是没有反应!!

limiaoyi536 2016-03-19 08:14:52
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、考虑的技术没有全面。
希望大牛能帮帮忙,给点意见!
...全文
210 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ustcer_iim 2016-08-01
  • 打赏
  • 举报
回复
你好,我现在还在做屏幕取词这块,本人至今也没有什么思路,能共享下你的代码吗?谢谢
Justin-Liu 2016-08-01
  • 打赏
  • 举报
回复
用管理员权限运行试试
我不懂电脑 2016-07-31
  • 打赏
  • 举报
回复
c#做屏幕取词还是算了吧,这类软件同事用c#做的和我用c做的,性能不可相提并论。
ustcer_iim 2016-07-30
  • 打赏
  • 举报
回复
你现在知道结果了吗?我的在win7下运行也没有反应,能共享一下解决方案吗

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧