最近在開發基於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測試部要用。我的娘啊。
愁有啥用?哈,新年快樂再說!大家鼠年快樂哦。我是屬老鼠的。本命年,不好過啊。