Sign in to follow this  
b1gjo3

member ScreenSaverProc

Recommended Posts

b1gjo3    213
Is it possible to have the ScreenSaverProc as a member function. I have it declared static as I would have a WndProc member function would be, but it seems i need to tell scrnsav.lib where to get the screensaver proc as well as the other 2 important functions. i know with WndProc you have the WNDCLASSEX point to the procedure, is there a way i can point scrnsave.h or scrnsave.lib to the correct functions? here are my errors as im sure you know them
1>ScrnSavw.lib(scrnsave.obj) : error LNK2019: unresolved external symbol _ScreenSaverProcW@16 referenced in function _RealScreenSaverProc@16
1>ScrnSavw.lib(scrnsave.obj) : error LNK2019: unresolved external symbol _ScreenSaverConfigureDialog@16 referenced in function _DoConfigBox@4
1>ScrnSavw.lib(scrnsave.obj) : error LNK2019: unresolved external symbol _RegisterDialogClasses@4 referenced in function _DoConfigBox@4

heres my code
#include <windows.h>
#include <scrnsave.h>
#include <commctrl.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

//for application description, you need to create a string table and put int "IDS_DESCRIPTION=1" then the description
//for application icon, set ID of icon to ID_APP
//for dialog, set its id to "DLG_SCRNSAVECONFIGURE=2003"
#include "resource.h"

// Include these libraries
#pragma comment(lib, "OpenGL32.lib")
#pragma comment(lib, "GLu32.lib")
#pragma comment(lib, "GLaux.lib")

#ifdef UNICODE
#pragma comment(lib, "ScrnSavw.lib")
#else
#pragma comment(lib, "ScrnSave.lib")
#endif

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

#define TIMER 1

class GLScreenSaver
{
public:
	GLScreenSaver() {}
	~GLScreenSaver() {}

	//required screensaver functions
	static LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	static BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
	static BOOL WINAPI RegisterDialogClasses(HANDLE hInst);
private:
	//opengl functions
	static void InitGL(HWND hWnd);
	static void CloseGL(HWND hWnd);

	//window dimensions
	static int windowWidth;
	static int windowHeight;

	//window variables
	static HDC hDC;
	static HGLRC hRC;
};

int GLScreenSaver::windowWidth = 0;
int GLScreenSaver::windowHeight = 0;
HDC GLScreenSaver::hDC = NULL;
HGLRC GLScreenSaver::hRC = NULL;

void GLScreenSaver::InitGL(HWND hWnd)
{
	static PIXELFORMATDESCRIPTOR pfd = 
	{
		sizeof(PIXELFORMATDESCRIPTOR),
		1,                     // nVersion should be set to 1
		PFD_DRAW_TO_WINDOW |   // buffer can draw to window
		PFD_SUPPORT_OPENGL |   // buffer supports OpenGL drawing
		PFD_DOUBLEBUFFER,      // buffer is double buffered
		PFD_TYPE_RGBA,         // rgba pixels
		24,                    // 24-bit color depth
		0, 0, 0, 0, 0, 0,      // look up rest at MSDN, color bits ignored
		0,                     // no alpha buffer
		0,                     // shift bit ignored
		0,                     // no accumulation buffer
		0, 0, 0, 0,            // accumulation bits
		16,                    // 16 bit z buffer
		0,                     // no stencil buffer
		0,                     // no auxiliary buffer
		PFD_MAIN_PLANE,        // main drawing layer
		0,                     // reserved
		0, 0, 0                // layer mask ignored
    };

	GLScreenSaver::hDC = GetDC( hWnd );
      
	int i = ChoosePixelFormat( GLScreenSaver::hDC, &pfd ); 
	SetPixelFormat( GLScreenSaver::hDC, i, &pfd );

	hRC = wglCreateContext( GLScreenSaver::hDC );
	wglMakeCurrent( GLScreenSaver::hDC, GLScreenSaver::hRC );
}

void GLScreenSaver::CloseGL(HWND hWnd)
{
	wglMakeCurrent( NULL, NULL );
	wglDeleteContext( GLScreenSaver::hRC );
	ReleaseDC( hWnd, GLScreenSaver::hDC );
}

// Screensaver procedure...first when window is created: 
// 1) get users window resolution 
// 2) call a function that sets up OpenGL  
// 3) Setup a TIMER that will be used to drive animations

// Screen Saver Procedure
LRESULT WINAPI GLScreenSaver::ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
		case WM_CREATE:
		{
			RECT rect;

			// get window dimensions
			GetClientRect(hWnd, &rect);
			GLScreenSaver::windowWidth = rect.right;		
			GLScreenSaver::windowHeight = rect.bottom;
    
			//get configuration from registry if applicable

			//set up OpenGL
			GLScreenSaver::InitGL(hWnd);

			//INITIALIZE

			//create a timer that ticks every 10 milliseconds
			SetTimer(hWnd, TIMER, 10, NULL); 
			break;
		}
 
		case WM_DESTROY:
		{
			KillTimer(hWnd, TIMER);
		    
			//delete any objects created during animation
			//and close down OpenGL nicely

			GLScreenSaver::CloseGL(hWnd);
			break;
		}

		case WM_TIMER:
		{
			//call some function to advance your animation		
			break;
		}
	}

	//let the screensaver library take care of any
	//other messages

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

//for the dialog when user hits settings
BOOL WINAPI GLScreenSaver::ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      // Dialog message handling
      switch(message)
      {
      case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                  case IDOK:
                        EndDialog(hDlg, LOWORD(wParam) == IDOK);
                        return TRUE;
            }
      }

      return FALSE;
}

// needed for SCRNSAVE.LIB
BOOL WINAPI GLScreenSaver::RegisterDialogClasses(HANDLE hInst)
{
	return TRUE;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this