Jump to content
  • Advertisement
Sign in to follow this  
DMengelt

screensaver settings dialog not working correctly

This topic is 4561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This problem is annoying... i have very simple screensaver code im trying to get to work. The screensaver works fine. I'm trying to get a settings dialog to work correctly and am having problems. When you click the settings button that calls the dialog, everything on the dialog shows up and works (buttons etc.) except the dialog box itself. The dialog box doesn't show up. The buttons on the dialog do show up. wtf is that? seriously... anywho... help would be appreciated main.cpp:

#pragma comment(lib, "ScrnSave.lib")
#pragma comment(lib, "comctl32.lib")

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

#define szAppName  "Screensaver Test"
#define szAuthor   "Author"
#define szPreview  "Preview"

BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message) 
    {

        // add code here
		case WM_INITDIALOG:

		    // get registry data

            return TRUE;

       case WM_COMMAND:

            switch(LOWORD(wParam)) 
            { 
                // add cases for controls checked / unchecked etc

                // write to registry on ok

                case IDOK:
			
                //write configuration

			EndDialog( hDlg, LOWORD( wParam ) == IDOK ); 
			return TRUE; 

		case IDCANCEL: 
			EndDialog( hDlg, LOWORD( wParam ) == IDOK ); 
			return TRUE;   
		}

    }
    return TRUE;
}

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

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

    static int delay = 6500;

    switch(message)
    {
        case WM_CREATE:

            xpos = GetSystemMetrics(SM_CXSCREEN);
            ypos = GetSystemMetrics(SM_CYSCREEN);

            xpos/=2;
            ypos/=2;

            hBrush = CreateSolidBrush(RGB(0, 0, 0));
            uTimer = static_cast<UINT>(SetTimer(hWnd, 1, delay, NULL));

            PostMessage(hWnd,WM_TIMER,0,0);

            break;

        case WM_DESTROY:

            if(uTimer)
                KillTimer(hWnd, uTimer);

            if(hBrush)
                DeleteObject(hBrush);

            PostQuitMessage(0);
            break;

        case WM_TIMER:

            // load resources

            GetWindowRect(hWnd,&wrec);
            InvalidateRect(hWnd, &wrec, TRUE);
            break;

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

            if(fChildPreview)
            {
                SetBkColor(hDC, RGB(0, 0, 0));
                SetTextColor(hDC, RGB(255, 255, 0));
                TextOut(hDC, 2, 45, szPreview, static_cast<int>(strlen(szPreview)));
            }
            else
            {
                SetBkColor(hDC, RGB(0, 0, 0));
                SetTextColor(hDC, RGB(120, 120, 120));
                TextOut(hDC, 0, ypos * 2 - 42, szAppName, static_cast<int>(strlen(szAppName)));
                TextOut(hDC, 0, ypos * 2 - 25, szAuthor, static_cast<int>(strlen(szAuthor)));

                // add display code
            }

            EndPaint(hWnd, &ps);
            break;

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

    return 0;
}


resource.h:

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by screensaver.rc
//
#define IDD_DIALOG1                     101
#define DLG_SCRNSAVECONFIGURE           2003

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif


resource.rc:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

DLG_SCRNSAVECONFIGURE DIALOGEX 0, 0, 186, 95
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | 
    WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,129,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,129,24,50,14
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO 
BEGIN
    DLG_SCRNSAVECONFIGURE, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 179
        TOPMARGIN, 7
        BOTTOMMARGIN, 88
    END
END
#endif    // APSTUDIO_INVOKED

#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


thanks!

Share this post


Link to post
Share on other sites
Advertisement
ScreenSaverConfigureDialog is a "normal" dialog proc. Do not return TRUE at the end, but FALSE to indicate that you did not process the message.

With returning TRUE you're telling Windows that you already processed all messages and a lot of default event handling will not happen.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!