[Implemented] IsWindowActive()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

[Implemented] IsWindowActive()

Post by nco2k »

IsScreenActive() is a very nice and usefull command, so there should be a IsWindowActive() command aswell.

c ya,
nco2k
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

I think the point of the IsScreenActive command is so that people can pause their games if the user alt-tabs out of their program. However I think to do the same thing with a window you could just do something like this:

Code: Select all

If GetForegroundWindow_()=WindowID()
  Debug "Is active"
Else
  Debug "Isn't active"
EndIf
(only for windows though)
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

sure, but its stil winapi... i am getting tired of always using it, for almost every single thing. :cry:

c ya,
nco2k
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

sure, but its stil winapi... i am getting tired of always using it, for almost every single thing
My guess would be that the IsScreenActive() command probably uses the api, just under the hood. And I think any introduced IsWindowActive() command would probably just be wrapping similar api code to that which I posted. I don't see the problem with just using the api code.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> its stil winapi... i am getting tired of always using it

Why? If your app isn't cross-platform, then what's the problem? It's not like
you need to declare them first (like Visual Basic) -- they're as simple and easy
to use as any other Basic command.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@GreenGiant
of course... many commands use the api under the hood, but a purebasic command does the dirty work for you and you dont need to worry about cross-platform compatibility.

@PB
yep its because of the cross-platform compatibility.

c ya,
nco2k
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> yep its because of the cross-platform compatibility.

Fair enough then! ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

I'm pretty sure that in Windows there's a WindowEvent() event that signifies that your window has lost focus (only a number, not a defined constant as far as I know). If that exists in the linux version too then that would probably be a better way to do it. I think that would fit in better to the event-driven loop most apps use.
With a screen you are generally running through your loop 60 times or so a second, so if you check for the screen being active each loop you can respond pretty much instant instantly when it's deactivated. But in an event-driven loop, you'd only find out it had lost focus when a window event occured, and I doubt you get many when your window isn't active. Probably the only one you'd get would be one that signalled your window gaining/losing focus :) . So I think a defined #PB_LostFocus and a #PB_GainedFocus constant for use with WaitWindowEvent would be more useful.
Post Reply