获取光标位置方法研究
2014-09-28 00:45
344 查看
获取光标位置方法研究
johnchen
获取光标位置可以使用GetCaretPos函数获取位置,也可以通过GetGUIThreadInfo函数获取位置。
1、GetCaretPos函数获取光标位置,实现代码:
CPoint point;
CRect rect;
GetWindowRect(&rect);
HWND hwnd=::GetFocus();
HWND pHwnd=::GetForegroundWindow();
AttachThreadInput(GetCurrentThreadId(),::GetWindowThreadProcessId(pHwnd,NULL),TRUE);
::GetCaretPos(&point);
::ClientToScreen(hwnd,&point);
AttachThreadInput(GetCurrentThreadId(),::GetWindowThreadProcessId(pHwnd,NULL),FALSE);
2、GetGUIThreadInfo函数获取光标位置,实现代码:
#include <winable.h>
HWND hwnd;
GUITHREADINFO pg;
POINT point;//光标位置
pg.cbSize=48;
::GetGUIThreadInfo(NULL,&pg);
hwnd=pg.hwndCaret;
if (pg.hwndCaret)
{
point.x=pg.rcCaret.right;
point.y=pg.rcCaret.bottom;
::ClientToScreen(pg.hwndCaret,&point);
}
//CString str;
//str.Format("x=%d,y=%d",point.x,point.y);
//AfxMessageBox(str);
总结:GetCaretPos函数能获取WIN32一些程序窗口中光标位置,但是在IE7和WORD里GetCaretPos是不能获取光标位置的。而GetGUIThreadInfo函数获取窗口坐标位置是没有限制,不过在VCL、GTK、SWT界面框架的窗口具体能不能得到位置没有试过。
johnchen
获取光标位置可以使用GetCaretPos函数获取位置,也可以通过GetGUIThreadInfo函数获取位置。
1、GetCaretPos函数获取光标位置,实现代码:
CPoint point;
CRect rect;
GetWindowRect(&rect);
HWND hwnd=::GetFocus();
HWND pHwnd=::GetForegroundWindow();
AttachThreadInput(GetCurrentThreadId(),::GetWindowThreadProcessId(pHwnd,NULL),TRUE);
::GetCaretPos(&point);
::ClientToScreen(hwnd,&point);
AttachThreadInput(GetCurrentThreadId(),::GetWindowThreadProcessId(pHwnd,NULL),FALSE);
2、GetGUIThreadInfo函数获取光标位置,实现代码:
#include <winable.h>
HWND hwnd;
GUITHREADINFO pg;
POINT point;//光标位置
pg.cbSize=48;
::GetGUIThreadInfo(NULL,&pg);
hwnd=pg.hwndCaret;
if (pg.hwndCaret)
{
point.x=pg.rcCaret.right;
point.y=pg.rcCaret.bottom;
::ClientToScreen(pg.hwndCaret,&point);
}
//CString str;
//str.Format("x=%d,y=%d",point.x,point.y);
//AfxMessageBox(str);
总结:GetCaretPos函数能获取WIN32一些程序窗口中光标位置,但是在IE7和WORD里GetCaretPos是不能获取光标位置的。而GetGUIThreadInfo函数获取窗口坐标位置是没有限制,不过在VCL、GTK、SWT界面框架的窗口具体能不能得到位置没有试过。
相关文章推荐
- 获取光标位置方法研究
- 获取光标位置方法研究
- javascript获取textarea光标选择位置和内容方法(IE, Firefox)
- js 获取/设置文本输入域内光标的位置的方法
- javascript获取textarea光标选择位置和内容方法(IE, Firefox)
- javascript获取textarea光标位置,内容方法(IE, Firefox)
- Javascript设置和获取Textarea的光标位置的方法(亲测有用),可定位光标到某个位置
- 用 javascript 获取当页面上鼠标(光标)位置 和 触发事件的对象 的方法
- js获取textarea光标位置方法(兼容ie,ff)
- Javascript实现获取及设置光标位置的方法
- javascript获取textarea光标选择位置和内容方法(IE, Firefox)
- 获取div编辑框,textarea,input text的光标位置 兼容IE,FF和Chrome的方法介绍
- JS获取textArea中光标位置的方法
- 获取div编辑框,textarea,input text的光标位置 兼容IE,FF和Chrome的方法介绍
- javascript获取textarea光标选择位置和内容方法(IE, Firefox)
- [图解]在输入框和文本框中获取和设置光标位置,以及选中文本和获取选中文本值的方法 --- 详解,兼容所有浏览器。
- javascript获取textarea光标选择位置和内容方法(IE, Firefox)
- 用 javascript 获取当页面上鼠标(光标)位置 和 触发事件的对象 的方法
- Javascript设置和获取Textarea的光标位置的方法