擷取游標位置方法研究

來源:互聯網
上載者:User

 擷取游標位置方法研究

                                       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介面架構的視窗具體能不能得到位置沒有試過。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.