VC中如何获取鼠标点击处控件的ID

 最近在开发基于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测试部要用。我的娘啊。

愁有啥用?哈,新年快乐再说!大家鼠年快乐哦。我是属老鼠的。本命年,不好过啊。

你可能感兴趣的:(VC中如何获取鼠标点击处控件的ID)