( Index )
Month

Brief Information about the Oct/Nov '02 CSIG Meetings

SLIDESAV - A Slide Show Screen Saver

Setup Dialog

The subject to this month is a continuation of the screensaver project that displays JPEG photos. Here's the situation: over the years I've accumulated hundreds of family photos using my digital camera. I've also accumulated dozens of screensavers, however it's easy to get tired of any particular screensaver. The best way to personalize a screensaver as well as the computer itself is to display your own pictures. And, since most pictures are in JPEG format, the goal of this utility is to use the JPG format.

The program consists of a number of major parts. The basic program is a Windows 32-bit GUI program, however it has only half of the complexity of a normal Win32 program because it uses the Microsoft screensaver library. When the program starts it looks at a particular directory and makes a list of all files in that directory. It next randomizes the list. Then every minute or so it displays a picture on the screen. Most of the hard work of decoding the JPEG compressed format is accomplished using the Intel JPEG library. The various settings of the program such as the time between updates are saved in the registry.

So here are the topics for the meeting: 32 bit windows programming; using the Intel JPEG a library; registry functions that I've wrapped in a C++ class; other utility C++ classes.

Note: there have been several small changes from the October meeting so be sure to download the latest version.

Sample Code

LRESULT WINAPI ScreenSaverProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static int t1;              static char title[_MAX_PATH];
    #define TIMER_EVENT_ID 1

    switch (message)
        {
        case WM_CREATE:
            {
			...
            t1 = SetTimer(hWnd,TIMER_EVENT_ID,500,NULL);
            GetRegistryInformation();       // Debug -- MessageBeep(MB_ICONASTERISK);
            HDC hDC = GetDC(NULL);
            hPalette = CreateHalftonePalette(hDC);
            ReleaseDC(NULL, hDC);
            fileCount = GetFileList(path, pArray);
            pShuffle = new CShuffle(fileCount, !randomFlag);
            return 0;
            }
        case WM_DESTROY :               // Windows has removed window fm scrn
            {
            KillTimer(hWnd,t1);
            DeleteObject(hPalette);      // very important!
            PostQuitMessage(0);
            if (pDib) delete [] pDib;
			...
            return 0;
            }
        case WM_TIMER:
            {
            if (fileCount)
                {
                if (pDib) delete [] pDib;
                result = DecodeJPGFileToDIB(fullname, &pDib);  // Get BITMAPINFOHEADER*
                InvalidateRect(hWnd,NULL,FALSE);
                UpdateWindow(hWnd);
                }
            return 0;
            }
        case WM_PAINT :
            {
            HDC PaintDC;    HPALETTE oldpal;
            PAINTSTRUCT ps;
            PaintDC = BeginPaint(hWnd, &ps);
			...
            if (pDib)
                {
                int milliSecs = 1000*screenDelay;  if (milliSecs==0) milliSecs=200;
                KillTimer(hWnd,t1);
                PaintIt(hWnd, PaintDC, pDib);
				...
                }
            if (PaletteFlag) SelectPalette(PaintDC, oldpal, FALSE);
            EndPaint(hWnd, &ps);
            return 0;
            }
        }
    return DefScreenSaverProc(hWnd, message, wParam, lParam);
    }


"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