[Implemented] #PB_Event_UnactivateWindow

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] #PB_Event_UnactivateWindow

Post by nco2k »

now where we (finally) have a #PB_Event_ActivateWindow, there should be something like #PB_Event_UnactivateWindow aswell. :wink:

c ya,
nco2k
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

see wm_activate

LOWORD(wParam) = activation flag (active/deactivated)
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

1.) callbacks always(?) proceed after a windowevent loop
2.) cross platform compatibility
3.) i could write my apps completely in winapi, but why have i bought pure basic then, when the basics are missing?? :roll:

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

True that, for now you can check the #PB_Event_WindowActivate and consider than if a window gets activated, all other in your program are unactivated (as only one can be activated at one instant).
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@Fred
thanks for your reply.

the problem is WindowEvent(), i would like to do something like this for example, without the need for a callback.

Code: Select all

Repeat
  WinEvent.l = WindowEvent()
  Select WinEvent
    Case 0
      Delay(1)
    Case #PB_Event_ActivateWindow
      SetPriorityClass_(GetCurrentProcess_(), #HIGH_PRIORITY_CLASS)
    ;Case #PB_Event_InactivateWindow
      ;SetPriorityClass_(GetCurrentProcess_(), #NORMAL_PRIORITY_CLASS)
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver : End
dont get me wrong, i have no problems using a callback, but sometimes its just better to check window events directly in the main loop. :wink:

i know you have at the moment more important things to do, but it would be cool to have this one, in the next version.

so keep up the good work and dont forget to eat, drink, sleep etc. :D

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> #PB_Event_ActivateWindow

This only checks if your APP'S WINDOWS are activated -- it won't check if
another window from another app is activated. So, what you need to do is
check (in your main loop) if GetForegroundWindow_() is or isn't the same
as WindowID() -- if it is, up the process priority; if not, make it normal. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

nico: you're right, in this case we can't check it by comparing the other windows.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@PB
This only checks if your APP'S WINDOWS are activated
well thats all i need. :wink:
So, what you need to do is
check (in your main loop) if GetForegroundWindow_() is or isn't the same
as WindowID()
call me economical or greedy, but i am trying to avoid (or at least reduce) using commands, which repeat themselves the whole time in a loop. :)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

Fred wrote:nico: you're right, in this case we can't check it by comparing the other windows.
marks this day in my calendar. :lol:
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

doesnt using #wm_activate in the normal windowevent() loop?
when im working with custom window messages, the work in a waitwindowevent()/windowevent() loop
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@lexvictory
nothing happens here, if you mean that:

Code: Select all

If OpenWindow(0, 0, 0, 480, 320, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "")
  
  Repeat
    WinEvent.l = WindowEvent()
    Select WinEvent
      Case 0
        Delay(1)
      Case #WM_ACTIVATE
        Debug "Window has become Active or Inactive"
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
  
EndIf

End
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

so u r right, that is a little wierd, cos most of the other window messages will appear in a normal loop....
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I have a little windows game called Transpetris that shows a little fireworks display when it is paused or idle. I didn't want the fireworks, which use up about 50% of the cpu, to be on if another window grabbed the focus. So I went looking for a window event such as wm_lostfocus, wm_minimized, that sort of thing. I found a few that looked promising but none that worked. So I had a minor brainwave. I debugged the window events, ran the program and selected another window on the desktop. The event that fired when focus was lost was 49355. So I called it #MAESTRO_LOSTFOCUS and tested for it. I figured that solved it so I patted myself on the back and went on to other challenges. But then in later testing I noticed it wouldn't always stop when I expected it to. So I repeated the event-debugging trick and found that anything between 49355 and 49359 could be firing. OKAY, FINE! Now I'm checking for the lostfocus event thus:

Code: Select all

;{ WaitWindow Loop
Repeat 
  ev=WaitWindowEvent()
  If ev >=49355 And ev <=49359
    EndTimer(2)
    EndTimer(3)
    EndTimer(1)
    playing=#False
    If GetActiveWindow_() = WindowID(0)
      StartTimer(2,1000,@StartDemo())
    EndIf
  EndIf
  If ev=#PB_Event_ActivateWindow
    EndTimer(2)
    EndTimer(3)
    EndTimer(1)
    Delay(50) ; Give the thread time to complete before attempting draw
    StartDrawing(WindowOutput())
      DrawImage(UseImage(#window),0,0)
      DrawImage(UseImage(#playarea),67,77)
      If soundson = #False
        DrawImage(UseImage(#buttonsoundoff),462,471)
      EndIf
    StopDrawing()
    If CountList(PieceGroup())
      showpiece(1)
    EndIf
    UpdateScore()
    ShowPreview()
    StartTimer(2,1000,@startdemo())
  EndIf
And so far, many testruns in, it seems to be working. For now you could possibly do something similar.
BERESHEIT
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

i know u sed u didnt want to use a callback.... but u could make it so that all it does is forward the message to the normal windowevent loop like:

Code: Select all

mymsg = registerwindowmessage_("wm_activatething")

procedure windowproc(hwnd, message, wparam,lparam)
if message = #wm_activate
postmessage_(#hwnd_broadcast, mymsg, wparam, lparam)
endif
endprocedure
i know thats not complete but it shows wat u could do
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply