对话框头文件中
HICON m_hIcon;
HCURSOR mCursor; //定义鼠标
RECT rect; //定义鼠标形状
HWND hDest; //获得的目标句柄
BOOL CMy9Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
....
mCursor = LoadCursor(NULL, IDC_SIZEALL); //默认带有箭头
GetDlgItem(IDC_STATIC)->GetWindowRect(&rect);
...
void CMy9Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if (point.x >= rect.left && point.x <= rect.right || point.y >= rect.top && point.y <= rect.bottom) {
SetCapture(); //开始捕获
SetCursor(mCursor); //当范围匹配,就对当前光标进行改变
}
CDialogEx::OnLButtonDown(nFlags, point);
}
void CMy9Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
POINT pt = point;
CString mString;
wchar_t sName[64];
wchar_t sContent[64];
ReleaseCapture();
ClientToScreen(&pt);
hDest = ::WindowFromPoint(pt); //获取指定POINT的窗口的句柄
mString.Format(_T("0x%.8x"), hDest);
SetDlgItemText(IDC_EDIT1, mString);
GetClassName(hDest, sName, MAX_PATH); //获取类名
SetDlgItemText(IDC_EDIT2, sName);
::SendMessage(hDest, WM_GETTEXT, (WPARAM)64, (LPARAM)sContent); //获取标题
SetDlgItemText(IDC_EDIT3, sContent);
CDialogEx::OnLButtonUp(nFlags, point);
}
原文地址:https://www.cnblogs.com/zpchcbd/p/12296624.html
时间: 2024-10-13 19:36:12