VC++实现spy++获取窗口句柄的功能
在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(L0) << std::hex << hTarget->GetSafeHwnd();
OutputDebugString(wss.str().c_str());
OutputDebugString(L" ");
CDialogEx::OnMouseMove(nFlags, point);
}
至于要显示 spy++那种窗口高亮效果,可以参考下面的函数,这里就不给出代码了
SetForegroungwindow Bringwindowtotop flashwindow switchtothiswindow setwindowpos showwindow 任一个
下一篇:
List去除重复数据的五种方式