虽然是小程序,编辑的源代码也很少,但其中的编程思想却是大型工程项目的配色经典基础。就如万丈高楼的基础中的钢筋般重要。
或许很多程序员一辈子也难接触到大型项目程序...还是那句话,既然缘分来了,不妨共享出来,希望能对有缘人有所帮助。
VS平台做的MFC皮肤颜色集组合的皮肤界面的小项目程序。左点击在4个主颜色色组合套餐切换,右点击在17颜色组合套餐间切换。
MFC_DlgSkinBase.rar解压后有4个文件和1个源代码程序压缩包。
1,color.ini 所有的17个颜色组合套餐的数据。
2,ColorSet.h 配色时需要用到的源代码头文件。
3,ColorSet.cpp 配色时需要用到的源代码实现文件。
4,readme.txt 以上文件的使用方法及简单编程过程。
5,DlgSkinBase.rar 颜色组合套餐的配色程序实例(VS2015)。
程序界面图1.
需要增加的文件:
// file ---------------------------------------------------------------------------------------------------------------
ColorSet.h
ColorSet.cpp
Color.ini
项目配置(1-4):
// file ---------------------------------------------------------------------------------------------------------------
xxx.vcxproj
xxx.vcxproj.filters
1,add new filter BaseModule -> add existing item...ColorSet.h ColorSet.cpp
2,Use Multi-Byte Character Set
3,Use x86, no Use x64
4,copy Color.ini ---> Debug\Color.ini or Release\Color.ini
编辑源代码文件1:
// file ---------------------------------------------------------------------------------------------------------------
xxxDlg.h
#pragma once
#include "ColorSet.h"
class xxxDlg : public CDialog
{...
CColorSet m_ColorSet;
int m_ColorSet_index; //辅助(assist)
CRect rc_client, rc_windows; //辅助(assist)
CStringArray aColorName; //辅助(assist)
...
afx_msg void OnLButtonUp(UINT nFlags, CPoint point); //辅助(assist)
afx_msg void OnRButtonUp(UINT nFlags, CPoint point); //辅助(assist)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
编辑源代码文件2:
// file ---------------------------------------------------------------------------------------------------------------
xxxDlg.cpp
BOOL xxxDlg::OnInitDialog()
{...
m_ColorSet.Init();
m_ColorSet.Load();
m_ColorSet_index = m_ColorSet.m_nCurSel; //辅助(assist)
m_ColorSet.GetAllColorName(aColorName); //辅助(assist)
return TRUE; // return TRUE unless you set the focus to a control
}
程序界面图2,
辅助(assist)编辑其它的源代码文件:
// assist begin // 辅助(assist)开始
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void xxxDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int refer[4] = {11, 15, 17, 10}; // 对应白,黑,蓝,经典。
static int index_refer = 0;
m_ColorSet_index = refer[index_refer];
m_ColorSet.SetCurSel(m_ColorSet_index);
index_refer ++;
if (index_refer >=4 ) index_refer = 0;
InvalidateRect(NULL, false);
CDialog::OnLButtonUp(nFlags, point);
}
void xxxDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ColorSet_index ++;
m_ColorSet.SetCurSel(m_ColorSet_index);
InvalidateRect(NULL, false);
CDialog::OnRButtonUp(nFlags, point);
}
void xxxDlg::OnPaint()
{
#if 0
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
#endif
CPaintDC dc(this); // device context for painting
GetClientRect(&rc_client);
GetWindowRect(&rc_windows);
CRect rc;
GetClientRect(&rc);
// #define CR_BACKGROUND 0 // 背景色
dc.FillSolidRect( rc, m_ColorSet.m_colors[CR_BACKGROUND]);
dc.SetBkColor(m_ColorSet.m_colors[CR_BACKGROUND]);
dc.SetTextColor(m_ColorSet.m_colors[CR_TEXT]);
CString strCaption;
CSize size;
int max_right=0, offcx = 100;
int max_bottom=0, offcy = 20;
size.cx = size.cy = 0;
// Title
if (0 == aColorName.GetSize())
strCaption.Format("颜色组合名称:aColorName.GetSize()=0. m_nCurSel=%d",m_ColorSet.m_nCurSel);
else
strCaption.Format("颜色组合名称:%s. m_nCurSel=%d",aColorName[m_ColorSet.m_nCurSel], m_ColorSet.m_nCurSel);
dc.SetTextColor(m_ColorSet.m_colors[CR_NAMECODE]);
rc.top = rc.top + size.cy;
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
dc.TextOut((rc.Width()-size.cx)/2, rc.top, strCaption );
strCaption.Format("RGB(0X%02X,0X%02X,0X%02X) COLORREF:%ul ",
GetRValue(m_ColorSet.m_colors[CR_BACKGROUND]),
GetGValue(m_ColorSet.m_colors[CR_BACKGROUND]),
GetBValue(m_ColorSet.m_colors[CR_BACKGROUND]),
m_ColorSet.m_colors[CR_BACKGROUND]);
dc.SetTextColor(m_ColorSet.m_colors[CR_NAMECODE]);
rc.top = rc.top + size.cy;
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
dc.TextOut((rc.Width()-size.cx)/2, rc.top, strCaption );
// #define CR_NAMECODE 1 // 名称代号
strCaption.Format("1,名称代号 %s=%ul", "m_ColorSet.m_colors[CR_NAMECODE]",m_ColorSet.m_colors[CR_NAMECODE]);
dc.SetTextColor(m_ColorSet.m_colors[CR_NAMECODE]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
max_right = rc.left + size.cx;
// #define CR_CUSTOM 2 // 自定义
strCaption.Format("2,自定义 %s=%ul", "m_ColorSet.m_colors[CR_CUSTOM]",m_ColorSet.m_colors[CR_CUSTOM]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CUSTOM]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_TITLE 3 // 标题
strCaption.Format("3,标题 %s=%ul", "m_ColorSet.m_colors[CR_TITLE]",m_ColorSet.m_colors[CR_TITLE]);
dc.SetTextColor(m_ColorSet.m_colors[CR_TITLE]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_TITLEBG 4 // 标题背景 //基本和// 背景色 一致.
strCaption.Format("4,(CR_NAMECODE)标题背景 %s=%ul...一致背景色?", "m_ColorSet.m_colors[CR_TITLEBG]",m_ColorSet.m_colors[CR_TITLEBG]);
dc.SetTextColor(m_ColorSet.m_colors[CR_NAMECODE]); // CR_TITLEBG
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
//#define CR_GRID 5 // 表框线
strCaption.Format("5,表框线 %s=%ul", "m_ColorSet.m_colors[CR_GRID]",m_ColorSet.m_colors[CR_GRID]);
dc.SetTextColor(m_ColorSet.m_colors[CR_GRID]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_SEL 6 // 表选中行
strCaption.Format("6,表选中行 %s=%ul", "m_ColorSet.m_colors[CR_SEL]",m_ColorSet.m_colors[CR_SEL]);
dc.SetTextColor(m_ColorSet.m_colors[CR_SEL]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
//#define CR_GRIDTEXT 7 // 表文本
strCaption.Format("7,表文本 %s=%ul", "m_ColorSet.m_colors[CR_GRIDTEXT]",m_ColorSet.m_colors[CR_GRIDTEXT]);
dc.SetTextColor(m_ColorSet.m_colors[CR_GRIDTEXT]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
//#define CR_FLASH 8 // 表闪烁
strCaption.Format("8,表闪烁 %s=%ul", "m_ColorSet.m_colors[CR_FLASH]",m_ColorSet.m_colors[CR_FLASH]);
dc.SetTextColor(m_ColorSet.m_colors[CR_FLASH]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_RISE 9 // 上升
strCaption.Format("9,上升 %s=%ul", "m_ColorSet.m_colors[CR_RISE]",m_ColorSet.m_colors[CR_RISE]);
dc.SetTextColor(m_ColorSet.m_colors[CR_RISE]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_DOWN 10 // 下降
strCaption.Format("10,下降 %s=%ul", "m_ColorSet.m_colors[CR_DOWN]",m_ColorSet.m_colors[CR_DOWN]);
dc.SetTextColor(m_ColorSet.m_colors[CR_DOWN]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_UNCHANGE 11 // 无变化
strCaption.Format("11,无变化 %s=%ul", "m_ColorSet.m_colors[CR_UNCHANGE]",m_ColorSet.m_colors[CR_UNCHANGE]);
dc.SetTextColor(m_ColorSet.m_colors[CR_UNCHANGE]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTDOWN 12 // 图表向下
strCaption.Format("12,图表向下 %s=%ul", "m_ColorSet.m_colors[CR_CHARTDOWN]",m_ColorSet.m_colors[CR_CHARTDOWN]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTDOWN]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTGRID 13 // 图表框线
strCaption.Format("13,图表框线 %s=%ul", "m_ColorSet.m_colors[CR_CHARTGRID]",m_ColorSet.m_colors[CR_CHARTGRID]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTGRID]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTAXISTEXT 14 // 图表坐标文本
strCaption.Format("14,图表坐标文本 %s=%ul", "m_ColorSet.m_colors[CR_CHARTAXISTEXT]",m_ColorSet.m_colors[CR_CHARTAXISTEXT]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTAXISTEXT]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_VOLUME 15 // 数量
strCaption.Format("15,数量 %s=%ul", "m_ColorSet.m_colors[CR_VOLUME]",m_ColorSet.m_colors[CR_VOLUME]);
dc.SetTextColor(m_ColorSet.m_colors[CR_VOLUME]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_TEXT 16 // 普通文本
strCaption.Format("16,普通文本 %s=%ul", "m_ColorSet.m_colors[CR_TEXT]",m_ColorSet.m_colors[CR_TEXT]);
dc.SetTextColor(m_ColorSet.m_colors[CR_TEXT]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTDESCRIP 17 // 描述文字
strCaption.Format("17,描述文字 %s=%ul", "m_ColorSet.m_colors[CR_CHARTDESCRIP]",m_ColorSet.m_colors[CR_CHARTDESCRIP]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTDESCRIP]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_TOOL 18 // 工具
strCaption.Format("18,工具 %s=%ul", "m_ColorSet.m_colors[CR_TOOL]",m_ColorSet.m_colors[CR_TOOL]);
dc.SetTextColor(m_ColorSet.m_colors[CR_TOOL]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTIND1 19 // 图表指标1
strCaption.Format("19,图表指标1 %s=%ul", "m_ColorSet.m_colors[CR_CHARTIND1]",m_ColorSet.m_colors[CR_CHARTIND1]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTIND1]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTIND2 20 // 图表指标2
strCaption.Format("20,图表指标2 %s=%ul", "m_ColorSet.m_colors[CR_CHARTIND2]",m_ColorSet.m_colors[CR_CHARTIND2]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTIND2]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTIND3 21 // 图表指标3
strCaption.Format("21,图表指标3 %s=%ul", "m_ColorSet.m_colors[CR_CHARTIND3]",m_ColorSet.m_colors[CR_CHARTIND3]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTIND3]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTIND4 22 // 图表指标4
strCaption.Format("22,图表指标4 %s=%ul", "m_ColorSet.m_colors[CR_CHARTIND4]",m_ColorSet.m_colors[CR_CHARTIND4]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTIND4]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTIND5 23 // 图表指标5
strCaption.Format("23,图表指标5 %s=%ul", "m_ColorSet.m_colors[CR_CHARTIND5]",m_ColorSet.m_colors[CR_CHARTIND5]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTIND5]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_CHARTIND6 24 // 图表指标6
strCaption.Format("24,图表指标6 %s=%ul", "m_ColorSet.m_colors[CR_CHARTIND6]",m_ColorSet.m_colors[CR_CHARTIND6]);
dc.SetTextColor(m_ColorSet.m_colors[CR_CHARTIND6]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_TabBack 25 // UI
strCaption.Format("25,UI %s=%ul", "m_ColorSet.m_colors[CR_TabBack]",m_ColorSet.m_colors[CR_TabBack]);
dc.SetTextColor(m_ColorSet.m_colors[CR_TabBack]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
// #define CR_FrameText 26 //UI文字
strCaption.Format("26,UI文字 %s=%ul", "m_ColorSet.m_colors[CR_FrameText]",m_ColorSet.m_colors[CR_FrameText]);
dc.SetTextColor(m_ColorSet.m_colors[CR_FrameText]);
rc.top = rc.top + size.cy;
dc.TextOut(rc.left, rc.top, strCaption );
size = dc.GetTextExtent(strCaption);
if (rc.left + size.cx > max_right) max_right = rc.left + size.cx;
offcy = 3 * CR_FrameText; // 5
rc_windows.right = rc_windows.left + max_right + offcx;
rc_windows.bottom = rc_windows.top + rc.top + size.cy + offcy;
MoveWindow(rc_windows);
}
// assist end //辅助(assist) 结束
// file ---------------------------------------------------------------------------------------------------------------
color.ini, ColorSet.h, ColorSet.cpp 3个文件的内容及详细相关源代码如下链接:
https://download.csdn.net/download/hixi2007/87906622