Click to open or copy the SAVER project files.
SAVER demonstrates how to write a simple screen saver using the Microsoft Foundation Class Library (MFC). The screen saver draws large characters on the screen, psuedo-morphing the text "MFC" to the text "C++". You can add SAVER to your system as a screen saver. You can also run it and configure its parameters, such as pen width, pen style, and speed of drawing, from the command line.
SAVER demonstrates the following techniques.
To run SAVER from the command line, type SAVER -s
. To configure the screen saver parameters, type SAVER -c
on the command line. The SAVER configuration dialog box is then displayed.
To add the screen saver to your system, you need to copy it to your windows system directory after building it. The details differ slightly, depending on whether you are running Windows® NT or Windows® 95.
Saver does not use the library Scrnsave.lib that is provided by the SDK, as that library does not fit the MFC architecture. Much of what Scrnsave.lib does has to be duplicated in Saver.
Saver's CSaverApp::InitInstance routine looks at the command line. If "-c" is specified, the routine creates a dialog box, calls DoModal( ), and returns FALSE from InitInstance (which causes the application to exit). If the user presses the OK button, the user's settings are stored in the registry.
If "-s" is specified, CSaverApp::InitInstance creates a CSaverWnd object and returns TRUE from InitInstance. CSaverWnd derives from CDrawWnd, which does the basic drawing of the screen saver image and is used by the configuration dialog itself to provide a preview of what the screen saver is going to do. CSaverWnd adds handlers for events such as WM_MOUSEMOVE and WM_LBUTTONDOWN. When these events occur, the screen saver shuts down.
This sample demonstrates the following keywords:
AfxGetApp; AfxGetResourceHandle; AfxRegisterWndClass; BeginPath; CColorDialog::DoModal; CColorDialog::GetColor; CComboBox::GetCurSel; CDC::DrawIcon; CDC::FillRect; CDC::GetSafeHdc; CDialog::DoModal; CDialog::OnInitDialog; CGdiObject::Attach; CGdiObject::DeleteObject; CGdiObject::Detach; CMenu::AppendMenu; CRect::Height; CRect::Width; CRgn::CombineRgn; CRgn::CreateFromPath; CRgn::CreateRectRgn; CScrollBar::GetScrollPos; CScrollBar::SetScrollPos; CString::IsEmpty; CString::LoadString; CWinApp::Enable3dControls; CWinApp::GetProfileInt; CWinApp::InitInstance; CWinApp::SetRegistryKey; CWinApp::WriteProfileInt; CWnd::CenterWindow; CWnd::Create; CWnd::CreateEx; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::GetDlgItemInt; CWnd::GetSafeHwnd; CWnd::Invalidate; CWnd::IsIconic; CWnd::KillTimer; CWnd::OnActivate; CWnd::OnActivateApp; CWnd::OnCreate; CWnd::OnDestroy; CWnd::OnHScroll; CWnd::OnKeyDown; CWnd::OnLButtonDown; CWnd::OnMButtonDown; CWnd::OnMouseMove; CWnd::OnNcActivate; CWnd::OnPaint; CWnd::OnQueryDragIcon; CWnd::OnRButtonDown; CWnd::OnSetCursor; CWnd::OnSize; CWnd::OnSysCommand; CWnd::OnSysKeyDown; CWnd::OnTimer; CWnd::PostMessage; CWnd::PostNcDestroy; CWnd::SendMessage; CWnd::SetTimer; CWnd::UpdateWindow; EndPath; FillRgn; GetBValue; GetDlgItem; GetGValue; GetProfileInt; GetRValue; GetSystemMenu; GetSystemMetrics; GetWindowRect; LineTo; LoadCursor; LoadIcon; MAKEINTRESOURCE; MoveTo; PostQuitMessage; RGB; ScreenToClient; SelectObject; SetCursor; SetPolyFillMode; SetScrollPos; SetScrollRange; WidenPath; atol; lstrcmpi