whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

56 Visitors Online


 
...check if a control is partially covered by another window?
Autor: Babak Sateli
Homepage: http://www.cdcenterco.com
[ Print tip ]  

Tip Rating (7):  
     


{

  You would have to iterate over all windows above yours in Z-order and
  check for each window you find if it has the WS_EX_TOPMOST exstyle set
  and is visible.
  If it has, you have to get its window rectangle (GetWindowRect) and test
  if that overlaps your window.

  Example:

}

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;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners