How to create a screen saver archive here it is it is called kaliscreen.zip click on filestore link
filestore
 

This is a instruction page in how to create a screen saver and some of the pitfalls or traps to avoid I could not find ONE PAGE on the internet using google with this information 100 percent correct so i shall continue the tradition (here is my version of incorrectness) * NOTE updated this page 30 Jan 2012 hmm some of this stuff is outdated now see my page screensaver2

 

The hardest part is the preview mode that is the mode that is executed in your screen saver when

the switch /p is selected (a switch is a option that is given to your screen saver on the command line) 

this needs to show the demo in a window in the display properties applet on the desktop of your system.

This is a child window in the following hierarchy in windows 2000/XP is as follows.

WIndows Desktop > 

Display properties >

screen saver >

ssDemoParent 

The window ssDemoParent is the small window in the center of the screensaver applet window you can check this with a program like winsight or your favourite window browser program. Here is one I have written called Windows Devining Rod the screen shot shows me editing this page in Mozzie Firefox using Google Webpage Edit tools.


You can burrow down into the layers of windows with this program using the nodes to go down the list of child windows  to make sure you get the correct one.

findwindowex windows API function automatically starts at the windows desktop so you just need 4 commands to get to the one you need. (following is Delphi if you use others you can translate them for your language although API functions are pretty universal in windows so you can translate easilly to C++, Python, .net etc)

 hwndParent := FindWindowEx(0,0,nil,PChar('Display Properties'));

      hwndParent :=  FindWindowEx(hwndParent, 0, '#32770', nil);
      hwndParent := FindWindowEx(hwndparent,0,PChar('Static'),nil);
      hwndParent := FindWindowEx(hwndparent,0,PChar('SSDemoParent'),nil);


Once you have the right window the next step is to resize your programs screen to it

this is a bit tricky as the co-ordinates are a combination of  the Display properties plus the ssDemoParent window

here is the delphi code for form adjustments to get the window to match the correct position and size

first get the screen saver rectangle

GetWindowRect(hwndParent,rctScreen);  

then the smaller window rectangle 

   GetWindowRect(hwndParentNew,rctDemoParent);


      //calculate width and height of parent window
      largeWindowWidth := rctDemoParent.right - rctDemoParent.left;
      LargeWindowHeight:= rctDemoParent.Bottom - rctDemoParent.Top;

      //  calculate width and height of child window so our form can use them
      Smallwindowwidth := rctScreen.Right - rctScreen.Left;
      SmallwindowHeight:= rctScreen.Bottom - rctScreen.Top;


 formsaver.top   := rctScreen.Top;
    formsaver.Left  := rctScreen.Left;
    formsaver.width := smallwindowwidth;
    formsaver.Height := smallwindowheight;

don't forget to change your viewing  port if you are using  GL otehrwise your graphics wont be resized;

glViewport(0 , 0 , formSaver.width ,formSaver.height );
 

and that should fix your code this is all executed in the GLDraw function its probably a waste to

calculate them all the time and should  be just put in some global vars when the program starts

but this is only a small config screen demo so not to worried about waste here. :)

Next you can draw a small button on the Display properties window so the user can exit the demo

we can use the API again  for this with the Rectangle function.

Rectangle(x,y,hwnd)

 



Next i found my screensaver Kali would hang the system when tabs were changed or the close button was clicked  in the Display Properties dialog so i wrote a small routine to disable tab changing while SS is running its called function bool disable TCM (Tab Change Message) to

the window that holds the tab control as it is just a window it is called SysTabControl32 and the window can be disabled with a call to enablewindow = false

  function tFormSaver.fboolDisableTCMWindow(blnEnabled : boolean) : boolean;
      var
       hwndParent2: hwnd;   

  begin 

  hwndParent2:= FindWindowEx(0,0,nil,PChar('Display Properties'));

             hwndParent2 := FindWindowEx(hwndparent2, 0,pchar('SysTabControl32'), nil);
             if blnEnabled = true then
              enablewindow(hwndparent2,false)
              else
              enablewindow(hwndparent2,true);
    end;



 

It just disables tab changing when the saver is in preview mode.

now you can trap all the messages to the window with a mouse Hook dll and you have fixed the

Display properties bug that doesn't  close your wonderful new screensaver !!!!! 

Main