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

📄 ppccolorconfigdlg.cpp

📁 在evc上开发的例子程序
💻 CPP
字号:

#include "stdafx.h"
#include "PPCColorConfig.h"
#include "PPCColorConfigDlg.h"

CString g_vtrShowStrings[OPTION_VECTOR_SIZE][2] =
{
	{	CString("Scrollbar"),			CString("Color of the gray area of a scroll bar")					},
	{	CString("Background"),			CString("Background color of the desktop window")					},
	{	CString("Active Caption"),		CString("Color of the title bar of an active window")				},
	{	CString("Inactive Caption"),	CString("Color of the title bar of an inactive window")				},
	{	CString("Menu"),				CString("Background color of a menu")								},
	{	CString("Window"),				CString("Background color of a window")								},
	{	CString("Window Frame"),		CString("Color of a window frame")									},
	{	CString("Menu Text"),			CString("Color of the text in a menu")								},
	{	CString("Window Text"),			CString("Color of the text in a window")							},
	{	CString("Caption Text"),		CString("Color of the text in a title bar")							},
	{	CString("Active Border"),		CString("Color of the border of an active window")					},
	{	CString("Inactive Border"),		CString("Color of the border of an inactive window")				},
	{	CString("App. Workspace"),		CString("Background color of a MDI application")					},
	{	CString("Highlight"),			CString("Color of an item selected in a control")					},
	{	CString("Highlight Text"),		CString("Color of the text of selected in a control")				},
	{	CString("Button Face"),			CString("Color of the face of a button")							},
	{	CString("Button Shadow"),		CString("Shadow color of buttons for edges that doesn't face light")},
	{	CString("Gray Text"),			CString("Color of a shaded text")									},
	{	CString("Button Text"),			CString("Color of the text for push buttons")						},
	{	CString("Inactive Caption Txt"),CString("Color of the text in the title bar of an inactive window")	},
	{	CString("Button Highlight"),	CString("Highlight color of buttons for edges that face light src")	},
	{	CString("3D Dark Shadow"),		CString("Color of the dark shadow for 3D display elements")			},
	{	CString("3D Light"),			CString("Highlight color of 3D display elements for edges")			},
	{	CString("Info Text"),			CString("Color of the text for a ToolTip control")					},
	{	CString("Info Background"),		CString("Color of the backgound for a ToolTip control")				},
	{	CString("Static"),				CString("Background color for static controls and dialog boxes.")	},
	{	CString("Static Text"),			CString("Color of the text for static controls")					},
	{	CString("Grad. Active Caption"),CString("Color of the title bar of an active window, gradient")		},
	{	CString("Grad. Inact. Caption"),CString("Color of the title bar of an inactive window, gradient")	}
};

CPPCColorConfigDlg::CPPCColorConfigDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPPCColorConfigDlg::IDD, pParent)
{
	m_iSelected = 0;
	m_iRed = 0;
	m_iGreen = 0;
	m_iBlue = 0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	InitVectors();
}

void CPPCColorConfigDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CPPCColorConfigDlg, CDialog)
	ON_WM_PAINT()
	ON_CBN_SELCHANGE(IDC_CMB_COMPONENTS, OnSelectOption)
	ON_EN_CHANGE(IDC_TXT_RED, OnColorChange)
	ON_EN_CHANGE(IDC_TXT_GREEN, OnColorChange)
	ON_EN_CHANGE(IDC_TXT_BLUE, OnColorChange)
	ON_BN_CLICKED(IDC_CMD_UPDATE, OnUpdateSettings)
END_MESSAGE_MAP()

BOOL CPPCColorConfigDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			
	SetIcon(m_hIcon, FALSE);		
	
	CenterWindow(GetDesktopWindow());

	FillColorOptions();

	SetDlgItemText(IDC_TXT_OTHER, _T("0"));
	SetDlgItemText(IDC_TXT_RED, _T("0"));
	SetDlgItemText(IDC_TXT_GREEN, _T("0"));
	SetDlgItemText(IDC_TXT_BLUE, _T("0"));
	OnColorChange();

	CComboBox* pColorOptions;
	pColorOptions = reinterpret_cast<CComboBox*>(GetDlgItem(IDC_CMB_COMPONENTS));
	pColorOptions->SetCurSel(0);

	return TRUE;  
}

void CPPCColorConfigDlg::FillColorOptions()
{
	CComboBox* pColorOptions;

	pColorOptions = reinterpret_cast<CComboBox*>(GetDlgItem(IDC_CMB_COMPONENTS));
	pColorOptions->Clear();

	for (int i = 0; i < OPTION_VECTOR_SIZE; i++)
	{
		pColorOptions->AddString(g_vtrShowStrings[i][0]);
	}
}

void CPPCColorConfigDlg::OnSelectOption()
{
	CComboBox* pColorOptions;
	int iRed, iGreen, iBlue;
	
	pColorOptions = reinterpret_cast<CComboBox*>(GetDlgItem(IDC_CMB_COMPONENTS));
	m_iSelected = pColorOptions->GetCurSel();

	// fill the current text boxes with the current color
	iRed = iGreen = iBlue = 0;

	ParseItemColors(&iRed, &iGreen, &iBlue);
	SetColorsInBoxes(iRed, iGreen, iBlue);

	DisplayDescription();	
}

void CPPCColorConfigDlg::InitVectors()
{
	HKEY hKey;
	DWORD dwType;
	DWORD dwSize;	

	dwType = 0;
	dwSize = BUFFER_SIZE;
	memset(m_pNewBuffer, 0, BUFFER_SIZE);
	memset(m_pOldBuffer, 0, BUFFER_SIZE);

	::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\GWE"), NULL, NULL, &hKey);
	::RegQueryValueEx(hKey, _T("SysColor"), NULL, &dwType, m_pOldBuffer, &dwSize);
	::RegQueryValueEx(hKey, _T("SysColor"), NULL, &dwType, m_pNewBuffer, &dwSize);
	::RegCloseKey(hKey);

	ASSERT(!memcmp(m_pOldBuffer, m_pNewBuffer, BUFFER_SIZE));
}

void CPPCColorConfigDlg::DisplayDescription()
{
	CStatic* pDescription;

	pDescription = reinterpret_cast<CStatic*>(GetDlgItem(IDC_LBL_DESCRPT));
	pDescription->SetWindowText(g_vtrShowStrings[m_iSelected][1]);
}

void CPPCColorConfigDlg::OnColorChange()
{
	CEdit* pRed, * pGreen, * pBlue;
	int iRed, iGreen, iBlue;
	CString strRed, strGreen, strBlue;

	pRed = reinterpret_cast<CEdit*>(GetDlgItem(IDC_TXT_RED));
	pGreen = reinterpret_cast<CEdit*>(GetDlgItem(IDC_TXT_GREEN));
	pBlue = reinterpret_cast<CEdit*>(GetDlgItem(IDC_TXT_BLUE));

	pRed->GetWindowText(strRed);
	pGreen->GetWindowText(strGreen);
	pBlue->GetWindowText(strBlue);

	iRed = _ttoi(strRed.GetBuffer(0));
	iGreen = _ttoi(strGreen.GetBuffer(0));
	iBlue = _ttoi(strBlue.GetBuffer(0));

	if (iRed < 0 || iRed > 255) 
	{
		MessageBox(_T("Red tone must be between 0 and 255"), NULL, MB_ICONEXCLAMATION);
		pRed->SetWindowText(_T("0"));
	}
	else if (iGreen < 0 || iGreen > 255) 
	{
		MessageBox(_T("Green tone must be between 0 and 255"), NULL, MB_ICONEXCLAMATION);
		pGreen->SetWindowText(_T("0"));
	}
	else if (iBlue < 0 || iBlue > 255) 
	{
		MessageBox(_T("Blue tone must be between 0 and 255"), NULL, MB_ICONEXCLAMATION);
		pBlue->SetWindowText(_T("0"));
	}
	else 
	{
		m_iRed = iRed;
		m_iGreen = iGreen;
		m_iBlue = iBlue;
		InvalidateRect(NULL);
	}
}

void CPPCColorConfigDlg::OnPaint()
{
	CDialog::OnPaint();

	CClientDC dc(this);
	CBrush brush;

	brush.CreateSolidBrush(RGB(m_iRed, m_iGreen, m_iBlue));
	dc.SelectObject(&brush);
		
	dc.Rectangle(12, 90, 215, 150);
}

void CPPCColorConfigDlg::OnUpdateSettings()
{
	int iPosition;

	iPosition = m_iSelected * 4;
	memcpy(m_pNewBuffer + iPosition++, &m_iRed, 1);
	memcpy(m_pNewBuffer + iPosition++, &m_iGreen, 1);
	memcpy(m_pNewBuffer + iPosition++, &m_iBlue, 1);
	UpdateRegistry();

	SetDlgItemText(IDC_LBL_DESCRPT, _T("A soft reset must be made before changes take effect."));
}

void CPPCColorConfigDlg::UpdateRegistry()
{
	HKEY hKey;
	DWORD dwType;
	DWORD dwSize;

	dwType = 0;
	dwSize = BUFFER_SIZE;

	::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\GWE"), NULL, NULL, &hKey);
	::RegQueryValueEx(hKey, _T("SysColor"), NULL, &dwType, m_pOldBuffer, &dwSize);
	::RegSetValueEx(hKey, _T("SysColor"), NULL, dwType, m_pNewBuffer, BUFFER_SIZE);
	::RegCloseKey(hKey);
}

void CPPCColorConfigDlg::ResetRegistry()
{
	memcpy(m_pNewBuffer, m_pOldBuffer, BUFFER_SIZE);
	UpdateRegistry();
}

void CPPCColorConfigDlg::ParseItemColors(int* pRed, int* pGreen, int* pBlue)
{
	int iPosition;
	
	iPosition = m_iSelected * 4;

	memcpy(pRed, m_pNewBuffer + iPosition++, 1);
	memcpy(pGreen, m_pNewBuffer + iPosition++, 1);
	memcpy(pBlue, m_pNewBuffer + iPosition++, 1);
}

void CPPCColorConfigDlg::SetColorsInBoxes(int iRed, int iGreen, int iBlue)
{
	CString strRed, strGreen, strBlue;

	strRed.Format(_T("%d"), iRed);
	strGreen.Format(_T("%d"), iGreen);
	strBlue.Format(_T("%d"), iBlue);

	SetDlgItemText(IDC_TXT_RED, strRed);
	SetDlgItemText(IDC_TXT_GREEN, strGreen);
	SetDlgItemText(IDC_TXT_BLUE, strBlue);
}

⌨️ 快捷键说明

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