( Index )
Month

Brief Information about the November 2001 CSIG Meeting

FLAG.SCR - A 32 Bit Screen Saver

3rd Tuesday of the month. 7:30PM - C/C++ Group, SPRS

Welcome to the C++ Users Group. This group is a "Special Interest Group" of the ACGNJ devoted to discussing programming languages in general and C, C++, and C++ for Windows programming in particular. Each month a small but hopefully useful program (complete with source code) is presented for discussion.

Sample Output The object of this month's program is to create a 32 bit screen saver which displays a bitmap. Microsoft Vc++ 6.0 has a 32 bit screen saver library which greatly simplifies the programming effort. The MS include file, scrnsave.h, outlines the steps required. This is simpler than the 16 bit screen saver that I presented at the March, 1997 meeting.

Using this information, I have created a screen saver in just 3 pages of C++ code. It displays a picture of the US flag which I took on August 20, 2001 at a Flag Ceremony on the beach at Cape May, NJ.

This program will demonstrate some of the inner workings of a conventional Windows program without the MFC layer. It works under Windows 95, 98, 98se, ME, NT, 2000, and XP.

At the meeting on Tuesday night we will be discussing the utility and the source code.


SAMPLE CODE
===========
LRESULT WINAPI ScreenSaverProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static int t1;
    #define TIMER_EVENT_ID 1

    switch (message)
        {
        case WM_CREATE:
            {
            // Microsoft required code: get szAppName from String Table
            LoadString(hMainInstance, idsAppName, szAppName, 40);
            
            // A halftone palette is required for a 256 color display.
            if (GetDeviceCaps(GetDC(NULL), RASTERCAPS) & RC_PALETTE) PaletteFlag=1;

            // Seed the random number generator
            srand( (unsigned)time( NULL ) );

            // Use timer to trigger events...
            t1 = SetTimer(hWnd,TIMER_EVENT_ID,500,NULL);
            if (!t1) {
                MessageBox(hWnd,"Timer creation error",szAppName,
                MB_ICONEXCLAMATION | MB_OK);
                }

            hBitmap = (HBITMAP) LoadImage(hMainInstance,
                MAKEINTRESOURCE(LARGE_BMP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

            hBitmapPrev = (HBITMAP) LoadImage(hMainInstance, 
                MAKEINTRESOURCE(SMALL_BMP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

            HDC hDC = GetDC(NULL);
            hPalette = CreateHalftonePalette(hDC);
            ReleaseDC(NULL, hDC);
            return 0;
            }

        case WM_SYSCOMMAND :                            // See scrnsave.h
            {
            WPARAM uCmdType = wParam & 0xFFF0; 
            if (uCmdType==SC_SCREENSAVE || uCmdType==SC_CLOSE)
                return FALSE;
            return TRUE;
            }
        case WM_DESTROY :               // Windows has removed window fm scrn
            {
            KillTimer(hWnd,t1);
            DeleteObject(hBitmapPrev);
            DeleteObject(hBitmap);      // very important!
            DeleteObject(hPalette);      // very important!
            PostQuitMessage(0);
            return 0;
            }

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page