Lost/got focus on Windows

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Lost/got focus on Windows

Post 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.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post 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">
  <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>
K
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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)...
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
Attachments
test.zgeproj
testing project
(531 Bytes) Downloaded 496 times
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Hi Rado1, I'll fix this in next update!
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

VilleK wrote:Hi Rado1, I'll fix this in next update!
Thanks Ville.
Post Reply