I'm trying to draw a rectangle, like in Spy++
Code:
case WM_MOUSEMOVE:
{
if (bSearching) {
POINT pMouse = {0};
HWND hwnd;
char szMouse[64];
GetCursorPos(&pMouse);
hwnd = WindowFromPoint(pMouse);
wsprintf(szMouse, "Cursor: %i x %i", pMouse.x, pMouse.y);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)szMouse);
if (IsWindow(hwnd)) {
RECT rc;
HDC hdc;
HGDIOBJ hPrevPen;
HGDIOBJ hPrevBrush;
HPEN hPen;
hdc = GetWindowDC(hwnd);
GetWindowRect(hwnd, &rc);
hPen = CreatePen(PS_SOLID, 2, RGB(0,0,0));
hPrevPen = SelectObject(hdc, hPen);
hPrevBrush = SelectObject (hdc, GetStockObject(HOLLOW_BRUSH));
Rectangle(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top);
SelectObject(hdc, hPrevBrush);
SelectObject(hdc, hPrevPen);
DeleteObject(hPen);
ReleaseDC(hwnd, hdc);
}
}
return 0;
}
Ok, when I point to a control, the rectangle is corretly draw...but when I left that control, the rectangle stays.... How to erase that rectangle?