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

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Lost/got focus on Windows

Postby Rado1 » Fri Jul 11, 2014 9:55 pm

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: 1613
Joined: Sat Feb 23, 2008 11:15 pm

Postby Kjell » Fri Jul 11, 2014 10:21 pm

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: 770
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Fri Jul 11, 2014 10:31 pm

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: 770
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sun Aug 24, 2014 5:00 pm

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 79 times

User avatar
VilleK
Site Admin
Posts: 1891
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Postby VilleK » Mon Aug 25, 2014 7:38 am

Hi Rado1, I'll fix this in next update!

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Mon Aug 25, 2014 8:10 am

VilleK wrote:Hi Rado1, I'll fix this in next update!

Thanks Ville.


Return to “Feature requests”

Who is online

Users browsing this forum: No registered users and 1 guest