www.pudn.com > scrnsaverTY23.zip > SaverConfigDialog.cpp


// SaverConfigDialog.cpp: implementation of the CSaverConfigDialog class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "SaverConfigDialog.h" 
#include "resource.h" 
#include "constants.h" 
#include "memory.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
CEdit * CSaverConfigDialog::m_pEdit = NULL; 
CSliderCtrl * CSaverConfigDialog::m_pSlider = NULL; 
CSpinButtonCtrl * CSaverConfigDialog::m_pSpin = NULL; 
 
CSaverConfigDialog::CSaverConfigDialog() 
{ 
 
} 
 
CSaverConfigDialog::~CSaverConfigDialog() 
{ 
 
} 
 
void CSaverConfigDialog::GetSetting(HWND hWnd) 
{ 
	InitControls(hWnd); 
	int cols, speed; 
	cols = GetPrivateProfileInt("Matrix", "Columns", (MIN_COLS + MAX_COLS) / 2, \ 
		"Control.ini"); 
	if (cols > MAX_COLS) cols = MAX_COLS; 
	if (cols < MIN_COLS) cols = MIN_COLS; 
	speed = GetPrivateProfileInt("Matrix", "Speed", (MIN_SPEED + MAX_SPEED) / 2, \ 
		"Control.ini"); 
	if (speed < MIN_SPEED) speed = MIN_SPEED; 
	if (speed > MAX_SPEED) speed = MAX_SPEED; 
	m_pSpin->SetPos(cols); 
	m_pSlider->SetPos(speed); 
} 
 
void CSaverConfigDialog::SetSettings(HWND hWnd) 
{ 
	int cols, speed; 
	cols = m_pSpin->GetPos(); 
	speed = m_pSlider->GetPos(); 
	CString strCols, strSpeed; 
	strCols.Format("%d", cols); 
	strSpeed.Format("%d", speed); 
	WritePrivateProfileString("Matrix", "Columns", strCols, "Control.ini"); 
	WritePrivateProfileString("Matrix", "Speed", strSpeed, "Control.ini"); 
} 
 
void CSaverConfigDialog::InitControls(HWND hWnd) 
{ 
	CDialog *pDlg = (CDialog*)CWnd::FromHandle(hWnd); 
	m_pEdit = (CEdit*)pDlg->GetDlgItem(IDC_EDIT_COLS); 
	m_pSpin = (CSpinButtonCtrl*)pDlg->GetDlgItem(IDC_SPIN); 
	m_pSlider = (CSliderCtrl*)pDlg->GetDlgItem(IDC_SLIDER); 
 
	m_pSpin->SetBuddy(m_pEdit); 
	m_pSpin->SetRange(MIN_COLS, MAX_COLS); 
	m_pSlider->SetRange(MIN_SPEED, MAX_SPEED); 
	 
} 
 
int CSaverConfigDialog::GetCols() 
{ 
	int cols; 
	cols = GetPrivateProfileInt("Matrix", "Columns", (MIN_COLS + MAX_COLS) / 2, \ 
		"Control.ini"); 
	if (cols > MAX_COLS) cols = MAX_COLS; 
	if (cols < MIN_COLS) cols = MIN_COLS; 
	 
	return cols; 
} 
 
 
int CSaverConfigDialog::GetSpeed() 
{ 
	int speed; 
	speed = GetPrivateProfileInt("Matrix", "Speed", (MIN_SPEED + MAX_SPEED) / 2, \ 
		"Control.ini"); 
	if (speed < MIN_SPEED) speed = MIN_SPEED; 
	if (speed > MAX_SPEED) speed = MAX_SPEED; 
 
	return speed; 
} 
 
COLORREF CSaverConfigDialog::GetColor() 
{ 
	COLORREF clrDefault = RGB(0, 255, 0); 
	int defualtColor = (int)clrDefault; 
	int color; 
	color = GetPrivateProfileInt("Matrix", "Color", defualtColor, \ 
		"Control.ini"); 
	return color; 
} 
 
void CSaverConfigDialog::SetColor(HWND hWnd) 
{ 
	COLORREF clrSet; 
	COLORREF clrCurrent = CSaverConfigDialog::GetColor(); 
	 
 
	CColorDialog clrDlg(clrCurrent, CC_FULLOPEN, \ 
		(CWnd*)CWnd::FromHandle(hWnd)); 
 
	if (clrDlg.DoModal() == IDOK) { 
		clrSet = clrDlg.GetColor(); 
		CString strColor; 
		strColor.Format("%d", (int)clrSet); 
		WritePrivateProfileString("Matrix", "Color", strColor, "Control.ini"); 
	} 
}