class CFinder { public: static void MouseDown(HWND hWnd) { hStatic = ::GetDlgItem(hWnd,IDC_CAPTURE); hBmpBlank = LoadBitmap (::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BLANK)); hCurCross = LoadCursor (::GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_CROSS0)); POINT point; ::GetCursorPos(&point); RECT rc; ::GetWindowRect(hStatic, &rc); if( ::PtInRect(&rc, point) ) { bCapture = true; ::SetCursor( hCurCross ); hBmpNomal=(HBITMAP)::SendMessage (hStatic,STM_SETIMAGE,IMAGE_BITMAP,(long)hBmpBlank); ::SetCapture( hWnd ); //必须把上次窗口句柄置空 FindWnd=NULL; } } static bool MouseUp() { if( bCapture ) { bCapture = false; ::SetCursor( LoadCursor(NULL,IDC_ARROW) ); ::SendMessage (hStatic,STM_SETIMAGE,IMAGE_BITMAP,(long)hBmpNomal); ::ReleaseCapture(); if( FindWnd ) HeightLightWnd(FindWnd);html ::DeleteObject(hBmpBlank); ::DeleteObject(hCurCross);vim return true; } else return false; } static bool MouseMove() { if (bCapture) { POINT point; ::GetCursorPos(&point); HWND hWnd=SmallestWindowFromPoint(point); // HWND hWnd=::WindowFromPoint(point); //第一次进入窗口 if (FindWnd != hWnd) { HeightLightWnd(FindWnd);//刷新旧窗口 FindWnd=hWnd; //保存wnd HeightLightWnd(hWnd); //高亮度新窗口 } return true; } else return false; }工具 /**************************************************************************** 把窗体的边框画上线条 参数1 hWnd : 指定窗口句柄 ****************************************************************************/ static void HeightLightWnd(HWND hWnd) { RECT DesRect; ::GetWindowRect(hWnd,&DesRect); DesRect.left+=2; DesRect.top+=2; DesRect.right-=2; DesRect.bottom-=2; HDC hdc=::GetDC(NULL); HPEN Pen=::CreatePen(PS_SOLID,4,RGB(0,0,0)); HPEN OldPen=(HPEN)SelectObject(hdc,Pen) ; SelectObject (hdc, GetStockObject (NULL_BRUSH)) ; //设置为空刷 SetROP2 (hdc, R2_NOT) ; //当前绘制的像素值设为屏幕像素值的反,这样能够覆盖掉上次的绘图(自动擦除上次图形) Rectangle (hdc, DesRect.left,DesRect.top,DesRect.right,DesRect.bottom) ; //擦除原来的图形 ::SelectObject (hdc,OldPen) ; ::DeleteObject(Pen); ::ReleaseDC(NULL,hdc); }学习 //----------------------------------------------- // SmallestWindowFromPoint // Notice: from PasswordSpy by Brian Friesen // // Find the smallest window still containing the point // // WindowFromPoint returns the first window in the Z-order -> // if the password control is sorounded by a Group Box or some other control, // WindowFromPoint returns the handle to the sorounding control instead // to the password control. // static HWND SmallestWindowFromPoint( const POINT point ) { RECT rect, rcTemp; HWND hParent, hWnd, hTemp; hWnd = ::WindowFromPoint( point ); if( hWnd != NULL ) { ::GetWindowRect( hWnd, &rect ); hParent = ::GetParent( hWnd ); // Has window a parent? if( hParent != NULL ) { // Search down the Z-Order hTemp = hWnd; do{ hTemp = ::GetWindow( hTemp, GW_HWNDNEXT ); // Search window contains the point, hase the same parent, and is visible? ::GetWindowRect( hTemp, &rcTemp ); if(::PtInRect(&rcTemp, point) && ::GetParent(hTemp) == hParent && ::IsWindowVisible(hTemp)) { // Is it smaller? if(((rcTemp.right - rcTemp.left) * (rcTemp.bottom - rcTemp.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top))) { // Found new smaller window! hWnd = hTemp; ::GetWindowRect(hWnd, &rect); } } }while( hTemp != NULL ); } } return hWnd; }测试 public: static HWND FindWnd; private: static HWND hStatic; static HCURSOR hCurCross; static HBITMAP hBmpNomal; static HBITMAP hBmpBlank; static bool bCapture ; };spa HWND CFinder::hStatic=NULL; HCURSOR CFinder::hCurCross=NULL; HBITMAP CFinder::hBmpNomal=NULL; HBITMAP CFinder::hBmpBlank=NULL; bool CFinder::bCapture=false; HWND CFinder::FindWnd=NULL;3d |