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.
Lost/got focus on Windows
Moderator: Moderators
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 ..
K
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

Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" MouseVisible="255" NoSound="1">
<OnLoaded>
<ZExternalLibrary ModuleName="User32" Source="int GetFocus(){}"/>
</OnLoaded>
<OnRender>
<Condition Expression="return GetFocus() == App.WindowHandle;">
<OnTrue>
<RenderSetColor Color="0 1 0 1"/>
</OnTrue>
<OnFalse>
<RenderSetColor Color="1 0 0 1"/>
</OnFalse>
</Condition>
<RenderSprite/>
</OnRender>
</ZApplication>
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.
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.
- Attachments
-
- test.zgeproj
- testing project
- (531 Bytes) Downloaded 679 times