[Lazarus] How to bring application to from (top)

Sven Barth pascaldragon at googlemail.com
Fri Jul 8 17:19:18 CEST 2011


Am 08.07.2011 15:18, schrieb Tommi Prami:
>
>> Could possibly do it using a dbus (or whatever) message. But the rule
>> still is that that sort of thing is considered rude.
>>
> Let me explain here a bit...
>
> It is mainly an WinCE app that is more than less Full screen. If the
> user goes on purpose or accidently to the system side... Then it might
> be that he/she does not know how to bring the already running
> application to the screen.
>
> But, what they surely know or are at least told how to do is to start
> the app. And now my app check that it is already running, informs the
> running one that wake up, and kills it self (to put nicely).
>
> Now it works perfectly only I can't get unfocused App to come to the
> Screen to the top most app. ..
>
> If there is some force way to do it. Any will do, would be good...

In our Windows Mobile application we are using this way from within the 
newly started application. It searches for the form window (this is 
important; focusing the invisible application window does not work, so 
you need to give the form a different title than the application) and 
puts it into the foreground.

=== source begin ===

   // h is a THandle
   h := FindWindow('Window', PWideChar(wTitle));
   if h <> 0 then
     SetForegroundWindow(h);

=== source end ===

A maybe better solution (I need to test this...) is to somehow send the 
old application a message and then that application could do the 
following when receiving that message:

=== source begin ===

SetForegroundWindow(Screen.ActiveForm.Handle);

=== source end ===

As said, I have not tested it yet, but if it works it would be a 
better/nicer solution than the (working) solution above.

Regards,
Sven




More information about the Lazarus mailing list