VC中如何擷取滑鼠點擊處控制項的ID

來源:互聯網
上載者:User

 最近在開發基於SDK的DEMO時遇到這樣一個問題:我要在響應滑鼠左鍵點擊事件中擷取到滑鼠點擊點的控制項的ID,然後根據ID的不同處理不通的操作,但是我怎麼也擷取不到控制項的ID。上MSDN查,上BAIDU搜,都沒找到能解決問題的方法。但是我找到了幾個可供參考的函數:

CWnd::GetFocus 

static CWnd* PASCAL GetFocus( );

Return Value

A pointer to the window that has the current focus, or NULL if there is no focus window.

The pointer may be temporary and should not be stored for later use.

CWnd::WindowFromPoint 

static CWnd* PASCAL WindowFromPoint( POINT point );

Return Value

A pointer to the window object in which the point lies. It is NULL if no window exists at the given point. The returned pointer may be temporary and should not be stored for later use.

CWnd::ChildWindowFromPoint 

CWnd* ChildWindowFromPoint( POINT point ) const;

CWnd* ChildWindowFromPoint( POINT point, UINT nFlags ) const;

Return Value

Identifies the child window that contains the point. It is NULL if the given point lies outside of the client area. If the point is within the client area but is not contained within any child window, CWnd is returned.

This member function will return a hidden or disabled child window that contains the specified point.

More than one window may contain the given point. However, this function returns only the CWnd* of the first window encountered that contains the point.

CWindow::ChildWindowFromPointEx

HWND ChildWindowFromPoint( POINT point, UINT uFlags ) const;

RealChildWindowFromPoint

The RealChildWindowFromPoint function retrieves a handle to the child window at the specified point. The search is restricted to immediate child windows; grandchildren and deeper descendant windows are not searched.

HWND RealChildWindowFromPoint(  HWND hwndParent,            // handle to window  POINT ptParentClientCoords  // client coordinates);
Parameters
hwndParent
[in] Handle to the window whose child is to be retrieved.
ptParentClientCoords
[in] Specifies a POINT structure that defines the client coordinates of the point to be checked.
Return Values

The return value is a handle to the child window that contains the specified point.

 

可以通過上面的幾個函數可以得到當前點擊點的控制代碼指標CWnd*,然後調用ClientToScreen,再調用GetDlgCtrlID即可。

這是理想狀態,但是我嘗試了所有方法,都沒能實現。很是鬱悶。哪位高手能解決這個問題??急啊,DEMO測試部要用。我的娘啊。

愁有啥用?哈,新年快樂再說!大家鼠年快樂哦。我是屬老鼠的。本命年,不好過啊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.