Page 1 of 1

How do I know, if a screensaver is running?

Posted: Sun Jun 29, 2003 2:52 pm
by high key
I have to know, if a screensaver or a DirectX-game in Fullscreenmode is running. to prevent my program from making screenoutputs. How do I do this?

Re: How do I know, if a screensaver is running?

Posted: Sun Jun 29, 2003 3:07 pm
by tinman
high key wrote:I have to know, if a screensaver or a DirectX-game in Fullscreenmode is running. to prevent my program from making screenoutputs. How do I do this?
If you have your own fullscreen game then you should use IsScreenActive() to know if your own screen is the active one.

My program isn't fullscreen

Posted: Sun Jun 29, 2003 3:36 pm
by high key
It's a little window with the actual date and time in it. I want, that this window changes its position, if the screenresolution is changed. That works fine most time. But when starting a DirectX-game, there are sometimes fatal faults (which do not occur, if my date&time program isn't running)

Posted: Sun Jun 29, 2003 4:00 pm
by tinman
This code seems to work, although I only tested it by changing my desktop resolution and running the directX test programs. I did not have any errors, so there is no code there to test whether the screen is active or not. What kind of games and screen output are you doing in your own code?

Code: Select all

Procedure.l cb(window.l, Message.l, wParam.l, lParam.l)
    If Message = #WM_DISPLAYCHANGE
        lp.l = lParam
        dep.l = wParam
        hres.l = lp & 65535
        vres.l = (lp / 65536) & 65535
        SetGadgetText(1, "Display changed to "+Str(hres)+" x "+Str(vres)+" x "+Str(dep))
    EndIf
    
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 200, 200, 400, 300, 0, "Checker")
    If CreateGadgetList(WindowID())
        StringGadget(1, 10, 10, 380, 30, "")
    EndIf
    
    SetWindowCallback(@cb())
    
    While quit=0
        ev.l = WindowEvent()
        While ev
            Select ev
                Case #WM_DISPLAYCHANGE
                
                Case #PB_Event_CloseWindow
                    quit = 1
            EndSelect
            
            ev = WindowEvent()
        Wend
        Delay(100)
    Wend
    
    SetWindowCallback(0)
    
    CloseWindow(0)
EndIf
End
(PS, creating strings in the callback is probably a bad thing to do, but this is just an example :)

The Res-change is not the problem :-)

Posted: Sun Jun 29, 2003 4:24 pm
by high key
Thanks for your detailed code! But my problem is not the detection of the Res-change. The problem is, that in that moment, when I move my little window to a new position with movewindow(x,y) , the DirectX-application crashes sometimes. I think, this is because movewindow brings my own program in the foreground again. If I knew, whether there is another program running in fullscreenmode, I could suppress the movewindow-action until we are in normal mode again.

Re: The Res-change is not the problem :-)

Posted: Sun Jun 29, 2003 4:34 pm
by tinman
high key wrote:Thanks for your detailed code! But my problem is not the detection of the Res-change. The problem is, that in that moment, when I move my little window to a new position with movewindow(x,y) , the DirectX-application crashes sometimes. I think, this is because movewindow brings my own program in the foreground again. If I knew, whether there is another program running in fullscreenmode, I could suppress the movewindow-action until we are in normal mode again.
OK. I couldn't find any way to detect what was fullscreen, so I avoided it and posted that code ;)

If you think it is related to MoveWindow you could try using the SetWindowPos_() command from the Win32 API. You will get more control over the way the window is moved. Something like this will move only the X and Y position but not anything else:

Code: Select all

SetWindowPos_(WindowID(), 0, x, y, 0, 0, #SWP_NOACTIVATE|#SWP_NOSIZE|#SWP_NOZORDER)

Sounds good :-)

Posted: Sun Jun 29, 2003 5:55 pm
by high key

Code: Select all

 SetWindowPos_(WindowID(), 0, x, y, 0, 0, #SWP_NOACTIVATE|#SWP_NOSIZE|#SWP_NOZORDER)


That sounds really good, especially the SWP_NOACTIVATE !!! :D


I will try this!

Perfect :-))

Posted: Sun Jun 29, 2003 7:01 pm
by high key
Supiiiiiiieee, it worx!!! No more crashes!!! Merci beaucoup :D

Grrrr, it crashed again

Posted: Mon Jun 30, 2003 11:15 am
by high key
Last night, it seemed, the problem was found and solved, but today - same error as before 8O

I'm now quite sure, that is was not the movewindow(x,y)-command, which makes problems.

Code: Select all

x=10
y=10

Fensterid=OpenWindow(1,x,y,200,200,#PB_Window_SystemMenu,"movetest")

abstand=10

For i=1 To 1000

  Delay(1000)
  
  
  x+abstand
  y+abstand
  MoveWindow(x,y)
  If x>300 Or x<10
    abstand=-abstand
  EndIf
 
Next i
  
This shows, that the movewindow-command doesn't activate the moved window or brings it in front. Hence this command should not make any problems or errrors.

Perhaps the problem is in the crashing game itself (bestfriends from retro64.com) or in my graphics card / drivers? Fortunately the game crashes only once a day, when started again it runs without problems.