⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propskin.cpp

📁 WinCE下绝好的工具条软件
💻 CPP
字号:
// PropSkin.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "PropSkin.h"
#include "strdefs.h"
#include "SetupDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPropSkin property page

IMPLEMENT_DYNCREATE(CPropSkin, CPropertyPage)

CPropSkin::CPropSkin() : CPropertyPage(CPropSkin::IDD)
{
	//{{AFX_DATA_INIT(CPropSkin)
	//}}AFX_DATA_INIT
}

CPropSkin::~CPropSkin()
{
}

void CPropSkin::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropSkin)
	DDX_Control(pDX, IDC_BTN_SAVESKIN, m_btnSave);
	DDX_Control(pDX, IDC_SKIN_FILE, m_edtSkin);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropSkin, CPropertyPage)
	//{{AFX_MSG_MAP(CPropSkin)
	ON_BN_CLICKED(IDC_BROWSE_SKIN, OnBrowseSkin)
	ON_BN_CLICKED(IDC_BTN_APPLY_SKIN, OnBtnApplySkin)
	ON_BN_CLICKED(IDC_BTN_SAVESKIN, OnBtnSaveskin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropSkin message handlers

void CPropSkin::OnBrowseSkin() 
{
	OPENFILENAME of;
	TCHAR szFile[MAX_PATH];
	TCHAR szExtName[8] = { _T("*.ini") };
	TCHAR szFileType[] = STR_BROWSE_SKN;

	ZeroMemory(&of, sizeof(OPENFILENAME));
	of.hwndOwner = m_hWnd;
	of.lpstrFile = szFile;
	of.lStructSize = sizeof(OPENFILENAME);
	of.lpstrInitialDir = NULL;
	of.nMaxFile = MAX_PATH;

	of.lpstrDefExt = szExtName;
	of.Flags = OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_FILEMUSTEXIST;

	of.lpfnHook = NULL;
	of.lpstrTitle = STR_BROWSE_SKIN;
	of.lpstrFilter = szFileType;

	if( GetOpenFileName(&of) ) {
		m_edtSkin.SetWindowText(szFile);
	}
}

void CPropSkin::OnBtnApplySkin() 
{
	TCHAR szSkinFile[MAX_PATH];

	m_edtSkin.GetWindowText(szSkinFile, MAX_PATH);

	// Load the skin file
	if( szSkinFile[0] != '\0' ) 
		loadSkinFile(szSkinFile);
}

bool CPropSkin::loadSkinFile(LPCTSTR sFile)
{
	CStdioFile *cFile = new CStdioFile();

	// Open the file
	if( cFile->Open(sFile, CFile::modeRead) ) {

		// Find the end of file 
		cFile->SeekToEnd();
		unsigned int file_end = cFile->GetPosition();
		cFile->SeekToBegin();
		
		// Read the file
		while( cFile->GetPosition() < file_end ) {
			CString line;
			char ch = 0x0;

			// Read the line
			while( (ch != 0x0a) && (cFile->GetPosition() < file_end) ) {
				cFile->Read(&ch, sizeof(char));
				if( ch != 0x0a )
					line = line + ch;
			}

			// Now, figure out what was just read
			int index = line.Find('=');
			CString item = line.Left(index);
			CString value = line.Right(line.GetLength() - (index + 1));
			setConfigValue(item, value);
		}

		// Save the configuration and update the dialogs
		CSetupDlg* pParent = (CSetupDlg*)GetParent();
		pParent->SaveSettings();
		pParent->m_items.resetItems();
		if( pParent->m_icons.initialized )
			pParent->m_icons.resetItems();
		if( pParent->m_imgs.initialized )
			pParent->m_imgs.resetItems();
		if( pParent->m_options.initialized )
			pParent->m_options.resetItems();
		if( pParent->m_order.initialized )
			pParent->m_order.resetItems();
		pParent->ApplyNow();
	}

	cFile->Close();
	delete cFile;
	return true;
}

void CPropSkin::setConfigValue(CString item, CString value)
{
	// Remove trailing and leading spaces
	item.TrimLeft();
	item.TrimRight();
	value.TrimLeft();
	value.TrimRight();

	// Window Title
	if( item.CompareNoCase(SKIN_WINDOWTITLE) == 0 )
		m_pOpt->bTitle = strToBool(value);
	else if( item.CompareNoCase(SKIN_WINDOWFONTNAME) == 0 )
		lstrcpy(m_pOpt->szTitleFont, value);
	else if( item.CompareNoCase(SKIN_WINDOWFONTSIZE) == 0 )
		m_pOpt->iTitleSize = strToInt(value);
	else if( item.CompareNoCase(SKIN_WINDOWFONTCOLOR) == 0 )
		m_pOpt->crTitle = strToInt(value);
	else if( item.CompareNoCase(SKIN_WINDOWFONTBOLD) == 0 )
		m_pOpt->dwTitleStyle = (strToBool(value) ? 1 : 0);
	else if( item.CompareNoCase(SKIN_WINDOWFONTITALIC) == 0 )
		m_pOpt->dwTitleStyle += (strToBool(value) ? 2 : 0);
	else if( item.CompareNoCase(SKIN_WINDOWTITLESTART) == 0 )
		m_pOpt->bAlways = strToBool(value);

	// Time
	else if( item.CompareNoCase(SKIN_TIME) == 0 )
		m_pOpt->bClock = strToBool(value);
	else if( item.CompareNoCase(SKIN_TIMEFONTNAME) == 0 )
		lstrcpy(m_pOpt->szClockFont, value);
	else if( item.CompareNoCase(SKIN_TIMEFONTSIZE) == 0 )
		m_pOpt->iClockSize = strToInt(value);
	else if( item.CompareNoCase(SKIN_TIMEFONTCOLOR) == 0 )
		m_pOpt->crClock = strToInt(value);
	else if( item.CompareNoCase(SKIN_TIMEFONTBOLD) == 0 )
		m_pOpt->dwClockStyle = (strToBool(value) ? 1 : 0);
	else if( item.CompareNoCase(SKIN_TIMEFONTITALIC) == 0 )
		m_pOpt->dwClockStyle += (strToBool(value) ? 2 : 0);

	// Date
	else if( item.CompareNoCase(SKIN_DATE) == 0 )
		m_pOpt->bDate = strToBool(value);
	else if( item.CompareNoCase(SKIN_DATEFONTNAME) == 0 )
		lstrcpy(m_pOpt->szDateFont, value);
	else if( item.CompareNoCase(SKIN_DATEFONTSIZE) == 0 )
		m_pOpt->iDateSize = strToInt(value);
	else if( item.CompareNoCase(SKIN_DATEFONTCOLOR) == 0 )
		m_pOpt->crDate = strToInt(value);
	else if( item.CompareNoCase(SKIN_DATEFONTBOLD) == 0 )
		m_pOpt->dwDateStyle = (strToBool(value) ? 1 : 0);
	else if( item.CompareNoCase(SKIN_DATEFONTITALIC) == 0 )
		m_pOpt->dwDateStyle += (strToBool(value) ? 2 : 0);

	// Small Date
	else if( item.CompareNoCase(SKIN_SMALLDATE) == 0 )
		m_pOpt->bSmallDate = strToBool(value);
	else if( item.CompareNoCase(SKIN_SMALLDATECOLOR) == 0 )
		m_pOpt->crSmall = strToInt(value);

	// Compact Date/Time
	else if( item.CompareNoCase(SKIN_COMPACTDATE) == 0 )
		m_pOpt->bAMPM = strToBool(value);

	// Task Icons
	else if( item.CompareNoCase(SKIN_TASKICONS) == 0 )
		m_pOpt->bTaskIcon = strToBool(value);
	else if( item.CompareNoCase(SKIN_NO3DTASK) == 0 )
		m_pOpt->bNo3D = strToBool(value);

	// Battery and Memory
	else if( item.CompareNoCase(SKIN_SYSTEM) == 0 )
		m_pOpt->bSystem = strToBool(value);
	else if( item.CompareNoCase(SKIN_SYSTEMCOLOR) == 0 )
		m_pOpt->crBatt = strToInt(value);

	// Today Icon
	else if( item.CompareNoCase(SKIN_SHOWTODAY) == 0 )
		m_pOpt->ico[WIS_ICO_TODAY].bDsp = strToBool(value);

	// Tap & Close
	else if( item.CompareNoCase(SKIN_SHOWTHCLOSE) == 0 )
		m_pOpt->ico[WIS_ICO_CLOSE2].bDsp = strToBool(value);

	// Volume Icon
	else if( item.CompareNoCase(SKIN_SHOWVOLUME) == 0 )
		m_pOpt->ico[WIS_ICO_LIST].bDsp = strToBool(value);

	// Smart Minimize
	else if( item.CompareNoCase(SKIN_SMARTMINIMIZE) == 0 )
		m_pOpt->bSmartMinimize = strToBool(value);
	
	// Hide Activesync
	else if( item.CompareNoCase(SKIN_HIDEACTIVE) == 0 )
		m_pOpt->bHidea = strToBool(value);

	// Go to Today
	else if( item.CompareNoCase(SKIN_GOTOTODAY) == 0 )
		m_pOpt->bToday = strToBool(value);

	// Reverse Volume
	else if( item.CompareNoCase(SKIN_REVVOLUME) == 0 )
		m_pOpt->bTHMUTE = strToBool(value);

	// Match Font Colors
	else if( item.CompareNoCase(SKIN_2002FONTS) == 0 )
		m_pOpt->use2002FontColors = strToBool(value);

	// Enable 3D Buttons
	else if( item.CompareNoCase(SKIN_ENABLE3D) == 0 )
		m_pOpt->b3dbutton = strToBool(value);

	// Dither Gradient
	else if( item.CompareNoCase(SKIN_DITHGRAD) == 0 )
		m_pOpt->bDithered = strToBool(value);

	// Start Menu
	else if( item.CompareNoCase(SKIN_SHOWLOGO) == 0 )
		m_pOpt->bLogo = strToBool(value);
	else if( item.CompareNoCase(SKIN_SHIFTLOGO) == 0 )
		m_pOpt->bShifted = strToBool(value);
	else if( item.CompareNoCase(SKIN_ENABLESTANDARD) == 0 )
		m_pOpt->szLogo[0] = NULL;
	else if( item.CompareNoCase(SKIN_LOGO) == 0 )
		lstrcpy(m_pOpt->szLogo, value);

	// Background
	else if( item.CompareNoCase(SKIN_BACKGROUND) == 0 )
		lstrcpy(m_pOpt->szBG, value);
	else if( item.CompareNoCase(SKIN_SHOWGRAD) == 0 )
		m_pOpt->bGradient = strToBool(value);
	else if( item.CompareNoCase(SKIN_2002COLORS) == 0 )
		m_pOpt->b2002Theme = strToBool(value);
	else if( item.CompareNoCase(SKIN_STARTCOLOR) == 0 )
		m_pOpt->cStartCr = strToInt(value);
	else if( item.CompareNoCase(SKIN_ENDCOLOR) == 0 )
		m_pOpt->cEndCr = strToInt(value);

	// Icons
	else if( item.CompareNoCase(SKIN_TODAYICON) == 0 )
		lstrcpy(m_pOpt->ico[WIS_ICO_TODAY].szIcon, value);
	else if( item.CompareNoCase(SKIN_VOLUMEICON) == 0 )
		lstrcpy(m_pOpt->ico[WIS_ICO_LIST].szIcon, value);
	else if( item.CompareNoCase(SKIN_OKICON) == 0 )
		lstrcpy(m_pOpt->ico[WIS_ICO_OK].szIcon, value);
	else if( item.CompareNoCase(SKIN_CLOSEICON) == 0 )
		lstrcpy(m_pOpt->ico[WIS_ICO_CLOSE].szIcon, value);
	else if( item.CompareNoCase(SKIN_THCLOSEICON) == 0 )
		lstrcpy(m_pOpt->ico[WIS_ICO_CLOSE2].szIcon, value);
	else if( item.CompareNoCase(SKIN_MUTEICON) == 0 )
		lstrcpy(m_pOpt->ico[WIS_ICO_MUTE].szIcon, value);
}

int CPropSkin::strToInt(LPCTSTR str)
{
	int result = 0;
	bool neg = false;
	for(unsigned int i = 0; i < lstrlen(str); i += sizeof(TCHAR)) {
		if( (str[i] < 48) || (str[i] > 57) && (str[i] != (TCHAR)'-') )
			break;
		if( str[i] == (TCHAR)'-' ) {
			neg = true;
		} else {
			result *= 10;
			result += str[i] - 48;
		}
	}

	if( neg )
		return -result;
	else
		return result;
}

BOOL CPropSkin::strToBool(CString b)
{
	return (b.CompareNoCase(_T("yes")) == 0);
}

CString CPropSkin::boolToStr(BOOL b)
{
	return (b ? "yes" : "no");
}

CString CPropSkin::intToStr(int i)
{
	char *str = new char[20];
	_itoa(i, str, 10);
	return str;
}

void CPropSkin::saveSkin(CString fname)
{
	CStdioFile *file = new CStdioFile();

	if( file->Open(fname, CFile::modeCreate | CFile::modeWrite) ) {
		// Window Title
		writeString(file, SKIN_WINDOWTITLE, boolToStr(m_pOpt->bTitle));
		writeString(file, SKIN_WINDOWFONTNAME, m_pOpt->szTitleFont);
		writeString(file, SKIN_WINDOWFONTSIZE, intToStr(m_pOpt->iTitleSize));
		writeString(file, SKIN_WINDOWFONTCOLOR, intToStr(m_pOpt->crTitle));
		writeString(file, SKIN_WINDOWFONTBOLD, boolToStr(m_pOpt->dwTitleStyle & 0x01 != 0));
		writeString(file, SKIN_WINDOWFONTITALIC, boolToStr(m_pOpt->dwTitleStyle & 0x02 != 0));
		writeString(file, SKIN_WINDOWTITLESTART, boolToStr(m_pOpt->bAlways));

		// Time
		writeString(file, SKIN_TIME, boolToStr(m_pOpt->bClock));
		writeString(file, SKIN_TIMEFONTNAME, m_pOpt->szClockFont);
		writeString(file, SKIN_TIMEFONTSIZE, intToStr(m_pOpt->iClockSize));
		writeString(file, SKIN_TIMEFONTCOLOR, intToStr(m_pOpt->crClock));
		writeString(file, SKIN_TIMEFONTBOLD, boolToStr(m_pOpt->dwClockStyle & 0x01 != 0));
		writeString(file, SKIN_TIMEFONTITALIC, boolToStr(m_pOpt->dwClockStyle & 0x02 != 0));

		// Date
		writeString(file, SKIN_DATE, boolToStr(m_pOpt->bDate));
		writeString(file, SKIN_DATEFONTNAME, m_pOpt->szDateFont);
		writeString(file, SKIN_DATEFONTSIZE, intToStr(m_pOpt->iDateSize));
		writeString(file, SKIN_DATEFONTCOLOR, intToStr(m_pOpt->crDate));
		writeString(file, SKIN_DATEFONTBOLD, boolToStr(m_pOpt->dwDateStyle & 0x01 != 0));
		writeString(file, SKIN_DATEFONTITALIC, boolToStr(m_pOpt->dwDateStyle & 0x02 != 0));

		// Small Date
		writeString(file, SKIN_SMALLDATE, boolToStr(m_pOpt->bSmallDate));
		writeString(file, SKIN_SMALLDATECOLOR, intToStr(m_pOpt->crSmall));

		// Compact Date/Time
		writeString(file, SKIN_COMPACTDATE, boolToStr(m_pOpt->bAMPM));

		// Task Icons
		writeString(file, SKIN_TASKICONS, boolToStr(m_pOpt->bTaskIcon));
		writeString(file, SKIN_NO3DTASK, boolToStr(m_pOpt->bNo3D));

		// Battery and Memory
		writeString(file, SKIN_SYSTEM, boolToStr(m_pOpt->bSystem));
		writeString(file, SKIN_SYSTEMCOLOR, intToStr(m_pOpt->crBatt));

		// Today Icon
		writeString(file, SKIN_SHOWTODAY, boolToStr(m_pOpt->ico[WIS_ICO_TODAY].bDsp));

		// Tap & Close
		writeString(file, SKIN_SHOWTHCLOSE, boolToStr(m_pOpt->ico[WIS_ICO_CLOSE2].bDsp));

		// Volume Icon
		writeString(file, SKIN_SHOWVOLUME, boolToStr(m_pOpt->ico[WIS_ICO_LIST].bDsp));

		// Smart Minimize
		writeString(file, SKIN_SMARTMINIMIZE, boolToStr(m_pOpt->bSmartMinimize));
		
		// Hide Activesync
		writeString(file, SKIN_HIDEACTIVE, boolToStr(m_pOpt->bHidea));
		
		// Go to Today
		writeString(file, SKIN_GOTOTODAY, boolToStr(m_pOpt->bToday));
		
		// Reverse Volume
		writeString(file, SKIN_REVVOLUME, boolToStr(m_pOpt->bTHMUTE));

		// Match Font Colors
		writeString(file, SKIN_2002FONTS, boolToStr(m_pOpt->use2002FontColors));

		// Enable 3D Buttons
		writeString(file, SKIN_ENABLE3D, boolToStr(m_pOpt->b3dbutton));

		// Dither Gradient
		writeString(file, SKIN_DITHGRAD, boolToStr(m_pOpt->bDithered));

		// Start Menu
		writeString(file, SKIN_SHOWLOGO, boolToStr(m_pOpt->bLogo));
		writeString(file, SKIN_SHIFTLOGO, boolToStr(m_pOpt->bShifted));
		writeString(file, SKIN_ENABLESTANDARD, boolToStr(m_pOpt->szLogo[0] == NULL));
		writeString(file, SKIN_LOGO, m_pOpt->szLogo);

		// Background
		writeString(file, SKIN_BACKGROUND, m_pOpt->szBG);
		writeString(file, SKIN_SHOWGRAD, boolToStr(m_pOpt->bGradient));
		writeString(file, SKIN_2002COLORS, boolToStr(m_pOpt->b2002Theme));
		writeString(file, SKIN_STARTCOLOR, intToStr(m_pOpt->cStartCr));
		writeString(file, SKIN_ENDCOLOR, intToStr(m_pOpt->cEndCr));

		// Icons
		writeString(file, SKIN_TODAYICON, m_pOpt->ico[WIS_ICO_TODAY].szIcon);
		writeString(file, SKIN_VOLUMEICON, m_pOpt->ico[WIS_ICO_LIST].szIcon);
		writeString(file, SKIN_OKICON, m_pOpt->ico[WIS_ICO_OK].szIcon);
		writeString(file, SKIN_CLOSEICON, m_pOpt->ico[WIS_ICO_CLOSE].szIcon);
		writeString(file, SKIN_THCLOSEICON, m_pOpt->ico[WIS_ICO_CLOSE2].szIcon);
		writeString(file, SKIN_MUTEICON, m_pOpt->ico[WIS_ICO_MUTE].szIcon);

		file->Close();
		delete file;
	}
}

void CPropSkin::writeString(CFile *file, LPCTSTR key, LPCTSTR value)
{
	CString c = CString(key) + " = " + CString(value);
	
	for(int i = 0; i < c.GetLength(); i ++) {
		char ch = (char)c.GetAt(i);
		((CStdioFile*)file)->Write(&ch, sizeof(char));
	}
	char ch = 0x0a;
	((CStdioFile*)file)->Write(&ch, sizeof(char));
}

void CPropSkin::OnBtnSaveskin() 
{
	OPENFILENAME of;
	TCHAR szFile[MAX_PATH];
	TCHAR szExtName[8] = { _T("*.ini") };
	TCHAR szFileType[] = STR_BROWSE_SKN;

	ZeroMemory(&of, sizeof(OPENFILENAME));
	of.hwndOwner = m_hWnd;
	of.lpstrFile = szFile;
	of.lStructSize = sizeof(OPENFILENAME);
	of.lpstrInitialDir = NULL;
	of.nMaxFile = MAX_PATH;

	of.lpstrDefExt = szExtName;
	of.Flags = OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_OVERWRITEPROMPT|OFN_SHAREAWARE;

	of.lpfnHook = NULL;
	of.lpstrTitle = STR_BROWSE_SKIN;
	of.lpstrFilter = szFileType;

	if( GetSaveFileName(&of) ) {
		saveSkin(szFile);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -