Delphi: How to get the window below the foreground one?

Hello everybody,

I'm having trouble trying to detect wether Windows Explorer is or not the window below My App. When I Call GetForegroundWindow, it returns my application handle. PLus GetNextWindow(form1.handle,GW_HWNDPREV); does not seem to return the right value.

Any ideas?

#358545

If you need to get the desktop window, call GetDesktopWindow().

If you are hunting for an explorer folder view, keep the following in mind:

Delphi apps have a hidden app window that is completely separate from the active TForm.handle, maybe you have to get TForm.handle's parent and then look for the next window...

It's a good idea to verify your findings with Spy++ or WinSpy...

#358620

What do you mean below? Next in Z-Order? GetNextWindow() or so...

#358648

That's what I did, Rimmer. But seems that It does not get the right window. Didn't try what herd said thought.

What I want is to get the window under my app, cause GetForegroundWindow will return only my form's handle.

#358717

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;

var Handled: Boolean);

var buffer:PAnsiChar;

bufSize:integer;

begin



if LOWORD(msg.wParam) = WA_ACTIVE then

begin

GetMem(buffer, 256);

GetClassName(HWND(msg.lParam), buffer, 256);

if string(buffer) = 'CabinetWClass' then

ShowMessage(string(buffer));

form1.Caption:=string(buffer);

FreeMem(buffer);

end;

end;

After some hours with Ave, that's what we got. But seems that GetClassName(HWND(msg.lParam), buffer, 256); does not work. Any idea?

#358951

try use

buffer: array[0..255] of char;

instead of PansiChar. this helps sometimes for string-answering api calls. When passing this as parameter, use @buffer construction.

#358958

[Pascal Error] test.pas(45): E2008 Incompatible types

On lines :

GetMem(buffer, 256);

and

FreeMem(buffer);

Then I tryed to remove them. It got compiled. But the problem is the same :(

#358962