VC如何得到鼠标焦点所在的控件ID
3个回答
展开全部
楼上的,GetFocus看翻译返回的应该是键盘的焦点吧,具体未测试。
现提供一种方法获取当前鼠标所在位置的控件ID.
如下(Win32):
POINT pt;
GetCursorPos(&pt);
HWND hWnd = WindowFromPoint(pt);
ScreenToClinet(hWnd,&pt);
//得到窗体的控件句柄
HWND hControlWnd = ChildWindowFromPoint(hWnd,pt);
UINT uId=GetDlgCtrlID(hControlWnd);
现提供一种方法获取当前鼠标所在位置的控件ID.
如下(Win32):
POINT pt;
GetCursorPos(&pt);
HWND hWnd = WindowFromPoint(pt);
ScreenToClinet(hWnd,&pt);
//得到窗体的控件句柄
HWND hControlWnd = ChildWindowFromPoint(hWnd,pt);
UINT uId=GetDlgCtrlID(hControlWnd);
展开全部
自己设定一个类内的成员变量usigned int OldID用于记录当前焦点控件的ID,等到下一个控件获得焦点的时候,OldID中的值就是前一个焦点的ID
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
MFC::
CWnd *pWnd = GetFocus();
if(pWnd == NULL)
;//no focus
else
UINT nID = pWnd->GetDlgCtrlID();
SDK:
HWND hWnd = ::GetFocus();
if(hWnd == NULL)
;//no focus
else
UINT nID = ::GetDlgCtrlID(hWnd);
GetFocus: The return value is the handle to the window with the keyboard focus. If the calling thread's message queue does not have an associated window with the keyboard focus, the return value is NULL.
CWnd *pWnd = GetFocus();
if(pWnd == NULL)
;//no focus
else
UINT nID = pWnd->GetDlgCtrlID();
SDK:
HWND hWnd = ::GetFocus();
if(hWnd == NULL)
;//no focus
else
UINT nID = ::GetDlgCtrlID(hWnd);
GetFocus: The return value is the handle to the window with the keyboard focus. If the calling thread's message queue does not have an associated window with the keyboard focus, the return value is NULL.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询