VC++實現spy++獲取視窗控制代碼的功能
阿新 • • 發佈:2019-02-11
在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++那種視窗高亮效果,可以參考下面的函式,這裡就不給出程式碼了
SetForegroungwindow Bringwindowtotop flashwindow switchtothiswindow setwindowpos showwindow 任一個