VC++实现spy++获取窗口句柄的功能

来源:互联网 发布:html javascript怎么用 编辑:程序博客网 时间:2024/06/05 12:40

在WM_MOUSEMOVE 消息中实现如下代码:

void CInputMethodTestDlg::OnMouseMove(UINT nFlags, CPoint point)

{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (GetCapture() == NULL) {
//一旦窗口捕获了鼠标,所有鼠标输入都针对该窗口
SetCapture();
}
POINT pt;
GetCursorPos(&pt);
CWnd* hTarget = WindowFromPoint(pt);
std::wstringstream wss;
wss << L"坐标:" << pt.x << L"," << pt.y << L" ";
wss << L"句柄:" << std::setw(8) << std::setfill(L'0') << std::hex << hTarget->GetSafeHwnd();
OutputDebugString(wss.str().c_str());
OutputDebugString(L"\n");
CDialogEx::OnMouseMove(nFlags, point);

}

至于要显示 spy++那种窗口高亮效果,可以参考下面的函数,这里就不给出代码了

SetForegroungwindowBringwindowtotopflashwindowswitchtothiswindowsetwindowposshowwindow任一个

原创粉丝点击