Author: Jonas Bilinkevicius
Is there a way that I can know if there is a 'Stay On Top' form owned by another
application partially covering my control?
Answer:
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:
1
2 procedure TForm1.Button1Click(Sender: TObject);
3
4 function IsTopmost(wnd: HWND): Boolean;
5 begin
6 Result := (GetWindowLong(wnd, GWL_EXSTYLE) and WS_EX_TOPMOST) <> 0;
7 end;
8
9 procedure logWindowInfo(wnd: HWND);
10 const
11 visString: array[Boolean] of string = ('not ', '');
12 var
13 buffer: array[0..256] of Char;
14 r: TRect;
15 begin
16 if wnd = 0 then
17 exit;
18 GetClassname(wnd, buffer, sizeof(buffer));
19 memo1.lines.add(format(' Window of class %s ', [buffer]));
20 Windows.getWindowrect(wnd, r);
21 memo1.lines.add(format(' at (%d,%d):(%d,%d)', [r.left, r.top, r.right,
22 r.bottom]));
23 memo1.lines.add(format(' Window is %svisible',
24 [visString[IsWindowVisible(wnd)]]));
25 memo1.lines.add(format(' Window is %stopmost', [visString[IsTopmost(wnd)]]));
26 end;
27
28 var
29 wnd: HWND;
30 begin
31 memo1.clear;
32 wnd := handle;
33 repeat
34 wnd := GetNextWindow(wnd, GW_HWNDPREV);
35 LogWindowInfo(wnd);
36 until
37 wnd = 0;
38 memo1.lines.add('End log');
39 end;
An easier approach would be to make your own window topmost while it is active.
|