Mega Code Archive

 
Categories / Delphi / Forms
 

How to check if a control is partially covered by another window

Title: How to check if a control is partially covered by another window procedure TForm1.Button1Click(Sender: TObject); var wnd: HWND; function IsTopMost(wnd: HWND): Boolean; begin Result := (GetWindowLong(wnd, GWL_EXSTYLE) and WS_EX_TOPMOST) 0; end; procedure logWindowInfo(wnd: HWND); const visString: array[Boolean] of string = ('not ', ''); var buffer: array[0..256] of Char; r: TRect; begin if wnd = 0 then Exit; GetClassName(wnd, buffer, SizeOf(buffer)); with Memo1.Lines do begin Add(Format(' Window of class %s ', [buffer])); GetWindowRect(wnd, r); Add(Format(' at (%d,%d):(%d,%d)', [r.Left, r.Top, r.Right, r.Bottom])); Add(Format(' Window is %svisible', [visString[IsWindowVisible(wnd)]])); Add(Format(' Window is %stopmost', [visString[IsTopmost(wnd)]])); end; end; begin Memo1.Clear; wnd := Handle; repeat wnd := GetNextWindow(wnd, GW_HWNDPREV); LogWindowInfo(wnd); until wnd = 0; Memo1.Lines.Add('End log.'); end;