獲取游標位置方法研究
阿新 • • 發佈:2018-12-21
獲取游標位置可以使用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);
}
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);
}