Menu

Screensaver

2002-06-11
2012-09-26
  • Igor Clukas

    Igor Clukas - 2002-06-11

    I'm looking for a screensaver code template/example for Dev-C++. All I have found was examples either needing scrnsave.lib or MSVC++.

    No "Why would you want to write a screensaver anyway" replies, please!

     
    • Nobody/Anonymous

      You have two options:

      1- http://winprog.org/faq/#3.7.

      2- The Allegro library has an example of writing screensavers for the Windows version.

       
    • Nobody/Anonymous

      Note that the winprog faq only has up to #3.2.7 and doesn't appear to mention screensavers anymore. There is some stuff about screensavers on that site, but none of it appears to be really useful.

      Also, DevCpp has the screensaver libs. If anyone is still interested I can post a basic screensaver example.

      blackadder

       
    • Nobody/Anonymous

       
    • Nobody/Anonymous

      I believe that article is based around a screen saver program the guy sells, looks pretty complicated. A basic screensaver skeleton in devcpp is pretty simple, I'll post one when I get to my other computer where my code is later.

      blackadder

       
    • Nobody/Anonymous

      To Bl'adder: I couldn't see any 'for sale' signs anywhere in that article. Still, if i'm wrong then I guess i'll have to cut down the second tallest tree in the forest with a herring...or is it another shrubbery? ;)

      Anyway, the article itself is very thorough and detailed, if a little old, but there's a link to updated code here:

      http://www.codeproject.com/cpp/holsavers.asp

      Both the original article and updated code use win32api so it should be possible to adapt to MinGW use.

      Maybe someone could write a dev-cpp template/package based on it...?

      which brings us--->

      To Kip: Please provide a link to the screensaver thread relevant to this discussion rather than to the forum's main page as I can't be bothered trawling for it. :)

      Lurker 4567-b

       
    • Jim W.

      Jim W. - 2004-01-06

      Got well over 6000 hits with a Google search on:

      screensaver "screen saver" c c++ example

      Adding the term GCC (whether or not it'd matter) cut it to 1640 hits.

      For what it might be worth, and, at minimum, just for perspective....

      -- Jim.

       
    • Nobody/Anonymous

      I too have been looking for a basic screensaver template to learn from.

      I have adapted the following code from a screensaver by Mehdi Mousavi called Ball Fusion (which I think was on Codeforge, but not sure)

      it is very basic.  The screen blanks, a message is displayed, and that is it, but it seems to demonstrate how things should be done.

      #include "windows.h"
      #include "scrnsave.h"
      #include "resource.h"

      #define szAppName    "Test Saver"
      #define szAuthor    "Adapted by xxxxxxxx"
      #define szPreview    "Test Saver"

      LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
      {
          static int i = 0;
          static PAINTSTRUCT ps = {NULL};
          static HDC hDC;
          static HBRUSH hBrush = NULL;
          static UINT uTimer = 0;
          static int ypos;
          static RECT rc;

          switch(message)
          {
          case WM_CREATE:
              ypos = GetSystemMetrics(SM_CYSCREEN);
              hBrush = CreateSolidBrush(RGB(0, 0, 0));
              uTimer = SetTimer(hWnd, 1, 1, NULL);
              break;

          case WM_DESTROY:
              if(uTimer)
                  KillTimer(hWnd, uTimer);

              if(hBrush)
                  DeleteObject(hBrush);
              break;

          case WM_TIMER:

              InvalidateRect(hWnd, NULL, FALSE);
              break;

          case WM_PAINT:
              hDC = BeginPaint(hWnd, &ps);

              if(fChildPreview)
              {
                  SetBkColor(hDC, RGB(0, 0, 0));
                  SetTextColor(hDC, RGB(255, 255, 0));
                  TextOut(hDC, 25, 45, szPreview, strlen(szPreview));
              }
              else
              {
                  SetBkColor(hDC, RGB(0, 0, 0));
                  SetTextColor(hDC, RGB(120, 120, 120));

                  TextOut(hDC, 0, ypos-40, szAppName, strlen(szAppName));
                  TextOut(hDC, 0, ypos-25, szAuthor, strlen(szAuthor));

              }
             
              EndPaint(hWnd, &ps);
              break;

          default:
              return DefScreenSaverProc(hWnd, message, wParam, lParam);
          }
         
          return 0;
      }

      BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
      {
          return FALSE;
      }

      BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
      {
          return TRUE;
      }

      you will need to include the libscrnsave.a file in the project options, and it would help if you changed the outut filename to an scr extension.

      Now, can anybody tell me how to copy the contents of the screen into the saver?

       
    • Nobody/Anonymous

      "you will need to include the libscrnsave.a file"

      I think the original poster wanted to avoid that. ;)

      "can anybody tell me how to copy the contents of the screen into the saver?"

      Check the code by 'Bodach' in this link:

      http://invisionfree.com/forums/CPPlearningcommunity/index.php?showtopic=1224

      Lurker 4567-b

       
    • Nobody/Anonymous

      I not sure the original poster wanted to avoid using libscrnsave.a, I believe he saw examples needing scrnsave.lib, and either didn't know that he would just need to use the .a file instead, or possibly the screensaver files weren't included with the earlier versions of Devcpp (the original post was made in 2002)
      You *can* do a screensaver without using the lib, I've even done them in RapidQ Basic just by making an .exe and renaming it .scr. But doing it that way is more work, using the lib you only need 3 functions, 2 of which can be empty placeholders.
      The example someone gave above is a pretty good start, one thing to add, the resource file:

      ID_APP ICON SCRICON.ICO

      STRINGTABLE
      {
        IDS_DESCRIPTION "My Screen Saver"
      }

      you should use an icon named SCRICON.ICO and the stringtable is supposed to give the string that should be shown in the list of screensavers when you look in display properties.

      blackadder

       
    • Kip

      Kip - 2004-01-11

      You don't need any special libraires or headers.

      It is just a renamed exe with no special entry points or anything like that. Function is dictated by the parameters passed on the command line by the shell. I suggest you watch the arguments windows passes to learn how it works.

      We are building a screensaver template for dev. More information here:

      http://thevertigo.com/phpBB2/viewtopic.php?t=12

      We should finish it soon.

      Kip

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.