How do I know, if a screensaver is running?

Just starting out? Need help? Post your questions and find answers here.
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

How do I know, if a screensaver is running?

Post 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?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

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

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

My program isn't fullscreen

Post 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)
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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 :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

The Res-change is not the problem :-)

Post 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.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

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

Post 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)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

Sounds good :-)

Post 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!
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

Perfect :-))

Post by high key »

Supiiiiiiieee, it worx!!! No more crashes!!! Merci beaucoup :D
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

Grrrr, it crashed again

Post 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.
Post Reply