Click here to Skip to main content
15,896,500 members
Articles / Programming Languages / C++

A Windows screensaver and boot manager

Rate me:
Please Sign up or sign in to vote.
2.83/5 (5 votes)
21 May 20025 min read 87.6K   1.2K   24  
This program Enables / disables / activates the current active screen saver and provides the means to logoff Windows and/or reboot the machine.
// ConfigDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WinMgr.h"
#include "ConfigDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConfigDlg dialog


CConfigDlg::CConfigDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CConfigDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConfigDlg)
	m_iSSValue = -5;
	//}}AFX_DATA_INIT
}


void CConfigDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConfigDlg)
	DDX_Radio(pDX, IDC_RADIOEXITSS, m_iSSValue);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigDlg, CDialog)
	//{{AFX_MSG_MAP(CConfigDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigDlg message handlers

BOOL CConfigDlg::OnInitDialog()
{
	UpdateConfigDlgRadios();
	
	// CG: The following block was added by the ToolTips component.
	{
		// Create the ToolTip control.
		m_tooltip.Create(this);
		m_tooltip.Activate(TRUE);

		// TODO: Use one of the following forms to add controls:
		m_tooltip.AddTool(GetDlgItem(IDC_RADIOEXITSS), IDS_CONFIGRADEXIT);
		m_tooltip.AddTool(GetDlgItem(IDC_RADIOMINSS), IDS_CONFIGRADMIN);
		m_tooltip.AddTool(GetDlgItem(IDOK), IDS_CONFIGOKBUTTON);
		m_tooltip.AddTool(GetDlgItem(IDCANCEL), IDS_CONFIGCANCELBUTTON);
		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), <string-table-id>);
		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
} //End OnInitDialog()

void CConfigDlg::UpdateConfigDlgRadios()
{	
	CString strSection       = "SSConfig";
	CString strIntItem       = "SSValue";   
	
	CWinApp* pApp = AfxGetApp();

	//Get value written in file, if exist...if not exist, value is -1
	int nRadioVal = pApp->GetProfileInt(strSection, strIntItem, -1);
	
	//If no value exists, write default value of 1 & check minimize radio button
	if(nRadioVal == -1){
		pApp->WriteProfileInt(strSection, strIntItem, 1);
		CheckRadioButton(IDC_RADIOEXITSS, IDC_RADIOMINSS, IDC_RADIOMINSS);
		//UpdateData(TRUE);
	} //end if
	//If exist, is value 0 (exit)
	else if(nRadioVal == 0){
		CheckRadioButton(IDC_RADIOEXITSS, IDC_RADIOMINSS, IDC_RADIOEXITSS);
		//UpdateData(TRUE);
	} //end if
	//If exist, is value 1 (min)
	else if(nRadioVal == 1){
		CheckRadioButton(IDC_RADIOEXITSS, IDC_RADIOMINSS, IDC_RADIOMINSS);
		//UpdateData(TRUE);
	} //end if
	//No button selected?
	else if(GetCheckedRadioButton(IDC_RADIOEXITSS, IDC_RADIOMINSS) == 0){
		CheckRadioButton(IDC_RADIOEXITSS, IDC_RADIOMINSS, IDC_RADIOMINSS);
		//UpdateData(TRUE);
	} //end if
UpdateData(TRUE);

} //End UpdateConfigDlgRadios()

void CConfigDlg::OnCancel() 
{
	// TODO: Add extra cleanup here

	CDialog::OnCancel();
} // End OnCancel

void CConfigDlg::OnOK()
{
	// TODO: Add extra validation here
	
	UpdateData(TRUE); //Update the data before writing to file

	//Does not check file for same values, just writes current option values to the file
	CString strSection       = "SSConfig";
	CString strIntItem       = "SSValue";   
	
	CWinApp* pApp = AfxGetApp();

	int WriteVal = m_iSSValue;

	pApp->WriteProfileInt(strSection, strIntItem, WriteVal);
	
	CDialog::OnOK(); //Exit dialog
} //End OnOK()

BOOL CConfigDlg::PreTranslateMessage(MSG* pMsg)
{
	// CG: The following block was added by the ToolTips component.
	{
		// Let the ToolTip process this message.
		m_tooltip.RelayEvent(pMsg);
	}
	return CDialog::PreTranslateMessage(pMsg);	// CG: This was added by the ToolTips component.
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions