如何判断另一个程序中可编辑的文本框内的文字处于部分或者全部选择的状态。 多谢,但是不明白你的意思,另一个程序上的控件类型是未知的。只要是可以输入文字的控件,都肯那个是我判断的对象。正如前面提到的,其实我就是想判断当前是否处于可以输入文字的状态,如果是的话,就正常输入文字,如果不是处于文字输入状态,则会启动自定义的键盘钩子,响应其他处理。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能够想到这么复杂的逻辑,楼主不容易啊,看样子不是代码的问题啊,既然有的控件上有效,有的控件上无效,那应该是控件的问题,通过消息操作控件是很原始的控件了吧,这问题有点悬 控件都没有问题,因为都是别的程序上的控件,我感现在觉关键就是要想办法取到控件。可惜想不出啊想不出 得到了解决。分享一下方案。文字未被选择的情况下,winform程序和wpf程序都可以用GetGUIThreadInfo的hwndCaret来判断,是否是处于获得插入符的输入状态。在文字有被选择的情况下,对于winform程序依然可以用上述方法判断。对于wpf程序,要用到下面的类来判断。System.Windows.IInputElement inputElement = System.Windows.Input.Keyboard.FocusedElement;之后再将inputElement转换成TextBox和RichTextBox,然后判断他的IsReadOnly和IsEnabled的属性。 if (GetGUIThreadInfo(uiThreadid, ref stLpGui) == true) { if (stLpGui.hwndCaret != IntPtr.Zero) { //返回值 = 输入状态! } else { //返回值 = 非输入状态! System.Windows.IInputElement inputElement = System.Windows.Input.Keyboard.FocusedElement; if (inputElement != null) { if (inputElement is System.Windows.Controls.TextBox) { if (((System.Windows.Controls.TextBox)inputElement).IsReadOnly == false && ((System.Windows.Controls.TextBox)inputElement).IsEnabled == true) { //返回值 = 输入状态! } } else if (inputElement is RichTextBox) { if (((System.Windows.Controls.RichTextBox)inputElement).IsReadOnly == false && ((System.Windows.Controls.RichTextBox)inputElement).IsEnabled == true) { //返回值 = 输入状态! } } } } } c# 如何与考勤机通讯? 程序跟踪 TeeChart如何标记某点的值 关于注册表的读取问题,挺简单的,新手求助 桌面程序运行在不同层次 相对路径VS绝对路径 C#winform把DataGridView中的数据制作成水晶报表,急啊!!! 请问怎样把图片存入数据库 新手上路! 关于DataTime 一个正则表达式的问题,给分100 bs架构中怎么做图?
可惜想不出啊想不出
分享一下方案。文字未被选择的情况下,winform程序和wpf程序都可以用GetGUIThreadInfo的hwndCaret来判断,是否是处于获得插入符的输入状态。
在文字有被选择的情况下,对于winform程序依然可以用上述方法判断。
对于wpf程序,要用到下面的类来判断。
System.Windows.IInputElement inputElement = System.Windows.Input.Keyboard.FocusedElement;
之后再将inputElement转换成TextBox和RichTextBox,然后判断他的IsReadOnly和IsEnabled的属性。
if (GetGUIThreadInfo(uiThreadid, ref stLpGui) == true)
{
if (stLpGui.hwndCaret != IntPtr.Zero)
{
//返回值 = 输入状态!
}
else
{
//返回值 = 非输入状态!
System.Windows.IInputElement inputElement = System.Windows.Input.Keyboard.FocusedElement;
if (inputElement != null)
{
if (inputElement is System.Windows.Controls.TextBox)
{
if (((System.Windows.Controls.TextBox)inputElement).IsReadOnly == false && ((System.Windows.Controls.TextBox)inputElement).IsEnabled == true)
{
//返回值 = 输入状态!
}
}
else if (inputElement is RichTextBox)
{
if (((System.Windows.Controls.RichTextBox)inputElement).IsReadOnly == false && ((System.Windows.Controls.RichTextBox)inputElement).IsEnabled == true)
{
//返回值 = 输入状态!
}
}
}
}
}