Page 1 of 1

Lost/got focus on Windows

Posted: Fri Jul 11, 2014 9:55 pm
by Rado1
Similarly to Android support for losing and getting application focus, cannot the same behavior be supported also on Windows? I mean KeyPress with CharCode 255 or 254 respectively working also on Windows.

This would allow to stop music when the ZGE app window is not active (e.g. switched to another application) and play it again when got focus.

Posted: Fri Jul 11, 2014 10:21 pm
by Kjell
Hi Rado1,

Not sure if you're requesting this because you want it build-in or whether you're not aware you can already do this using User32.dll ;) In any case, a simple example ..

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" MouseVisible="255" NoSound="1">
    <ZExternalLibrary ModuleName="User32" Source="int GetFocus(){}"/>
    <Condition Expression="return GetFocus() == App.WindowHandle;">
        <RenderSetColor Color="0 1 0 1"/>
        <RenderSetColor Color="1 0 0 1"/>

Posted: Fri Jul 11, 2014 10:31 pm
by Rado1
Hi Kjell,

actually, I was not aware of such a simple usage of User32.dll. Anyway, I would be glad to have a unified built-in mechanism which allows users to write the same code for all supported OSs as much as possible; without code such as if(ANDROID)...

Posted: Sun Aug 24, 2014 5:00 pm
by Rado1
I'm returning back to this topic because I need to handle getting/losing application focus on Windows in one of my projects. I use the technique suggested by Kjell (GetFocus function from user32 external library) but unfortunately it cannot be tested in the Preview panel of ZGE.

Ville, would it be possible to set the ZApplication.WindowHandle property to handle of the "ZGameEditor application" TGLPanel when the application is previewed in ZGE? This is the value returned by GetFocus() when the Preview panel is focused.

Having this, the application debugging would be much easier. Thanks.

Attached you can find my testing project; the background color is blue when got the focus, black if lost.

Posted: Mon Aug 25, 2014 7:38 am
by VilleK
Hi Rado1, I'll fix this in next update!

Posted: Mon Aug 25, 2014 8:10 am
by Rado1
VilleK wrote:Hi Rado1, I'll fix this in next update!
Thanks Ville.