Se si chiede gentilmente, WindowFromPoint
ignorerà la finestra (quella attualmente trascinata) e restituirà la finestra successiva. Questo è ciò che fa Internet Explorer quando si trascina una scheda.
per farlo:
- Maniglia
WM_NCHITTEST
nella finestra trascinato
- ritorno
HTTRANSPARENT
durante il trascinamento. Chiama altrimenti la finestra predefinita proc.
WindowFromPoint
will ignoreHTTRANSPARENT
windows, ma solo quelli che appartengono al thread chiamante. Questo non dovrebbe essere un problema per te, perché dovresti chiamare lo WindowFromPoint
dal thread del proprietario della finestra.
- Assicurarsi che non vi siano finestre secondarie nel punto passato a
WindowFromPoint
o gestire WM_NCHITTEST
anche per queste finestre secondarie.
guasti (se è ancora ottenere la finestra da WindowFromPoint
)
- test
GetCurrentThreadID() == GetWindowThreadProcessId(WindowFromPoint(), 0)
per garantire che si sta chiamando dal thread corretto
- In
WM_NCHITTEST
, test che hwnd
parametro è uguale a quello che si ottiene da WindowFromPoint()
Esempio (l'area all'interno rettangolo di restituisce la finestra sottostante da WindowFromPoint
):
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static const RECT s_TransparentRect = {100, 100, 200, 200};
switch (message)
{
case WM_NCCREATE:
SetTimer(hWnd, 1, 100, 0);
break;
case WM_TIMER:
{
POINT cursorPos;
GetCursorPos(&cursorPos);
TCHAR buffer[256];
_snwprintf_s(buffer, _countof(buffer), _TRUNCATE, _T("WindowFromPoint: %08X\n"), (int)WindowFromPoint(cursorPos));
SetWindowText(hWnd, buffer);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
Rectangle(ps.hdc, s_TransparentRect.left, s_TransparentRect.top, s_TransparentRect.right, s_TransparentRect.bottom);
EndPaint(hWnd, &ps);
}
break;
case WM_NCHITTEST:
{
POINT cursorPos;
GetCursorPos(&cursorPos);
MapWindowPoints(HWND_DESKTOP, hWnd, &cursorPos, 1);
if (PtInRect(&s_TransparentRect, cursorPos))
return HTTRANSPARENT;
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Se si effettua l'ipotesi che non nuove finestre verranno creati mentre si sta trascinando, è possibile enumerare le finestre di primo livello Una volta a l'inizio dell'operazione di trascinamento, quindi utilizzare il risultato per verificare ogni mossa del mouse durante il trascinamento. –
È un'ottimizzazione che vale la pena investigare, grazie. –
Potresti riuscire a farla franca usando 'GetNextWindow' e guardando le finestre sopra il tuo obiettivo nell'ordine Z. – theB