Screensaver not configuring properly

This is a discussion on Screensaver not configuring properly within the Windows Programming forums, part of the Platform Specific Boards category; The problem: Whenever I compile and run the screensaver, and open the configure dialog, and try to move the scrollbar, ...

  1. #1
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    Post Screensaver not configuring properly

    The problem: Whenever I compile and run the screensaver, and open the configure dialog, and try to move the scrollbar, the scrollbar does not move. What is wrong??

    I know this is a lot of code, but I think the problem lies in the WM_HSCROLL message or in the ID_OK message.
    Code:
    //main.c
    #define MINVEL  1                 // minimum redraw speed value
    #define MAXVEL  10                // maximum redraw speed value
    #define DEFVEL  5                 // default redraw speed value
    #include <stdio.h>
    #include "resource.h"
    LONG    lSpeed = DEFVEL;          // redraw speed variable
    
    extern HINSTANCE hMainInstance;   // screen saver instance handle
    
    CHAR   szAppName[80];             // .ini section name
    CHAR   szTemp[20];                // temporary array of characters
    CHAR   szRedrawSpeed[ ] = "Redraw Speed";   // .ini speed entry
    CHAR   szIniFile[MAXFILELEN];     // .ini or registry file name
    UINT i=0;
    BOOL WINAPI ScreenSaverConfigureDialog(hDlg, message, wParam, lParam)
    HWND     hDlg;
    UINT     message;
    WPARAM    wParam;
    LPARAM     lParam;
    {
        static HWND hSpeed;   // handle to speed scroll bar
        static HWND hOK;      // handle to OK push button
    
        switch(message)
        {
            case WM_INITDIALOG:
    
                // Retrieve the application name from the .rc file.
                LoadString(hMainInstance, idsAppName, szAppName,
                           80 * sizeof(TCHAR));
    
                // Retrieve the .ini (or registry) file name.
                LoadString(hMainInstance, idsIniFile, szIniFile,
                           MAXFILELEN * sizeof(TCHAR));
    
                // TODO: Add error checking to verify LoadString success
                //       for both calls.
    
                // Retrieve any redraw speed data from the registry.
                lSpeed = GetPrivateProfileInt(szAppName, szRedrawSpeed,
                                              DEFVEL, szIniFile);
    
                // If the initialization file does not contain an entry
                // for this screen saver, use the default value.
                if(lSpeed > MAXVEL || lSpeed < MINVEL)
                    lSpeed = DEFVEL;
    
                // Initialize the redraw speed scroll bar control.
                hSpeed = GetDlgItem(hDlg, ID_SPEED);
                SetScrollRange(hSpeed, SB_CTL, MINVEL, MAXVEL, FALSE);
                SetScrollPos(hSpeed, SB_CTL, lSpeed, TRUE);
    
                // Retrieve a handle to the OK push button control.
                hOK = GetDlgItem(hDlg, ID_OK);
    
                return TRUE;
    
            case WM_HSCROLL:
    
                // Process scroll bar input, adjusting the lSpeed
                // value as appropriate.
                switch (LOWORD(wParam))
                    {
                        case SB_PAGEUP:
                            --lSpeed;
                        break;
    
                        case SB_LINEUP:
                            --lSpeed;
                        break;
    
                        case SB_PAGEDOWN:
                            ++lSpeed;
                        break;
    
                        case SB_LINEDOWN:
                            ++lSpeed;
                        break;
    
                        case SB_THUMBPOSITION:
                            lSpeed = HIWORD(wParam);
                        break;
    
                        case SB_BOTTOM:
                            lSpeed = MINVEL;
                        break;
    
                        case SB_TOP:
                            lSpeed = MAXVEL;
                        break;
    
                        case SB_THUMBTRACK:
                        case SB_ENDSCROLL:
                            return TRUE;
                        break;
                    }
    
                    if ((int) lSpeed <= MINVEL)
                        lSpeed = MINVEL;
                    if ((int) lSpeed >= MAXVEL)
                        lSpeed = MAXVEL;
    
                    SetScrollPos((HWND) lParam, SB_CTL, lSpeed, TRUE);
                break;
    
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case ID_OK:
    
                        // Write the current redraw speed variable to
                        // the .ini file.
                        //hr = StringCchPrintf(szTemp, 20, "%ld", lSpeed);
                        wsprintf(szTemp, "%ld", lSpeed);
                        //if (SUCCEEDED(hr))
                            WritePrivateProfileString(szAppName, szRedrawSpeed,
                                                      szTemp, szIniFile);
    
                    case ID_CANCEL:
                        EndDialog(hDlg, LOWORD(wParam) == ID_OK);
    
                    return TRUE;
                }
        }
        return FALSE;
    }
    
    BOOL WINAPI RegisterDialogClasses(hInst)
    HANDLE  hInst;
    {
        return TRUE;
    }
    
    LONG WINAPI ScreenSaverProc(hwnd, message, wParam, lParam)
    HWND  hwnd;
    UINT  message;
    WPARAM wParam;
    LPARAM  lParam;
    {
        static HDC          hdc;      // device-context handle
        static RECT         rc;       // RECT structure
        static UINT         uTimer;   // timer identifier
    
        switch(message)
        {
            case WM_CREATE:
    
                // Retrieve the application name from the .rc file.
                LoadString(hMainInstance, idsAppName, szAppName, 80 * sizeof(TCHAR));
    
                // Retrieve the .ini (or registry) file name.
                LoadString(hMainInstance, idsIniFile, szIniFile, MAXFILELEN * sizeof(TCHAR));
    
                // TODO: Add error checking to verify LoadString success
                //       for both calls.
    
                // Retrieve any redraw speed data from the registry.
                lSpeed = GetPrivateProfileInt(szAppName, szRedrawSpeed,
                                              DEFVEL, szIniFile);
    
                // Set a timer for the screen saver window using the
                // redraw rate stored in Regedit.ini.
                uTimer = SetTimer(hwnd, 1, lSpeed * 1000, NULL);
                break;
    
            case WM_ERASEBKGND:
    
                // The WM_ERASEBKGND message is issued before the
                // WM_TIMER message, allowing the screen saver to
                // paint the background as appropriate.
    
                hdc = GetDC(hwnd);
                GetClientRect (hwnd, &rc);
                FillRect (hdc, &rc, GetStockObject(BLACK_BRUSH));
                ReleaseDC(hwnd,hdc);
                break;
    
            case WM_TIMER:
    
                // The WM_TIMER message is issued at (lSpeed * 1000)
                // intervals, where lSpeed == .001 seconds. This
                // code repaints the entire desktop with a white,
                // light gray, dark gray, or black brush each
                // time a WM_TIMER message is issued.
    
                hdc = GetDC(hwnd);
                GetClientRect(hwnd, &rc);
                if (i++ <= 4)
                    FillRect(hdc, &rc, GetStockObject(i));
                else
                    (i = 0);
                ReleaseDC(hwnd,hdc);
                break;
    
            case WM_DESTROY:
    
                // When the WM_DESTROY message is issued, the screen saver
                // must destroy any of the timers that were set at WM_CREATE
                // time.
    
                if (uTimer)
                    KillTimer(hwnd, uTimer);
                break;
        }
    
        // DefScreenSaverProc processes any messages ignored by ScreenSaverProc.
        return DefScreenSaverProc(hwnd, message, wParam, lParam);
    }
    Code:
    //resource.h
    #include <windows.h>
    #include <wingdi.h>
    #include <scrnsave.h>
    #ifndef ID_SPEED
    #define ID_SPEED 200453
    #endif
    #ifndef ID_OK
    #define ID_OK IDOK
    #endif
    #ifndef ID_CANCEL
    #define ID_CANCEL IDCANCEL
    #endif
    Code:
    //resource.rc
    #include "resource.h"
    DLG_SCRNSAVECONFIGURE DIALOG 6, 18, 160, 63
    LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
    STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
    CAPTION "Sample Screen-Saver Setup"
    FONT 8, "MS Shell Dlg"
    BEGIN
        GROUPBOX      "Redraw Speed", 101, 0, 6, 98, 40
        SCROLLBAR     ID_SPEED, 5, 31, 89, 10
        LTEXT         "Fast", 103, 6, 21, 20, 8
        LTEXT         "Slow", 104, 75, 21, 20, 8
        PUSHBUTTON    "OK", ID_OK, 117, 10, 40, 14
        PUSHBUTTON    "Cancel", ID_CANCEL, 117, 32, 40, 14
    END
    
    LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
    1                  RT_MANIFEST    "manifest.xml"
    Code:
    //manifest.xml
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
      <dependency>
        <dependentAssembly>
          <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
        </dependentAssembly>
      </dependency>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
          <requestedPrivileges>
            <requestedExecutionLevel
              level="asInvoker"
              uiAccess="false"/>
          </requestedPrivileges>
        </security>
      </trustInfo>
    </assembly>
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Hmmmm... it looks like it should work...

    A couple of things to try...
    1) Put a diagnostic Beep() in the switch so that you know the WM_HSCROLL it's being called correctly.
    2) Test the return value of SetScrollPos() to be sure the function isn't failing.
    3) Use a temporary static or edit control to visually report the value of lSpeed after setting the scroll pos.
    4) Of course running it in debug mode will also be revealing.
    5) You should also add SBS_HORZ style to your scrollbar's resource definitions... (control styles are important to getting correct behavior)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Configuring VS2008 C++ to C
    By Akkernight in forum C Programming
    Replies: 8
    Last Post: 02-28-2009, 04:17 AM
  2. Configuring VPN
    By ssharish2005 in forum Tech Board
    Replies: 5
    Last Post: 12-26-2006, 11:57 PM
  3. configuring Network
    By michas in forum Windows Programming
    Replies: 0
    Last Post: 07-17-2005, 02:53 AM
  4. Configuring SDL with Borland
    By Nakeerb in forum C++ Programming
    Replies: 4
    Last Post: 10-29-2002, 09:04 PM
  5. configuring emacs
    By greenRoom in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2001, 06:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21