I have the following (simplified) procedure to bring a desired window atop all other normal windows:
function focusWindow(): boolean;
var
h: Hwnd;
begin
result := true;
h := findwindow('Notepad', 'Unbenannt - Editor');
if h <> 0 then
BringWindowToTop(h);
end;
I use this in the following example application:
On the top, you can see my example application. There is an explorer window behind and an empty notepad in the background. As seen in the code above, I would like to move the notepad window to the front.
If I call my function from the button event handler
procedure TForm4.btnFocusClick(Sender: TObject);
begin
focusWindow();
end;
everything works as expected. The empty notepad window moves up to the front, behind that is the example application and the explorer is behind the other two windows.
But if I use a vcl ribbon control with an action assigned to a command button, it works only partly.
procedure TForm4.actDemoExecute(Sender: TObject);
begin
focusWindow();
end;
The notepad window moves up leaving the explorer window in the back. But then the procedure stops -- the notepad window keeps hidden behind my own application. What is happening here?