主要用到的函数: BOOL WritePrivateProfileString()
DWORD GetPrivateProfileString()
一. 设置编辑框的背景以及字体的STYLE以及COLOR
HBRUSH CConfig_OperateDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if ( nCtlColor==CTLCOLOR_EDIT)
{
COLORREF clr;
clr=RGB(120,120,250);
pDC->SetBkColor(clr);
CRect rect;
CBrush brush;
pWnd->GetClientRect(rect);
brush.CreateSolidBrush(clr);
pDC->FillRect(rect,&brush);
pDC->SetTextColor(RGB(255,255,255));//设置字体的颜色
pDC->SetTextCharacterExtra(2);//设置字体之间的间距.
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
二. 设置对话框的背景颜色
BOOL CConfig_OperateDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(rect);
CBrush brush;
brush.CreateSolidBrush(RGB(200,200,100));
pDC->FillRect(rect,&brush);
return true;
//return CDialog::OnEraseBkgnd(pDC);
}
三. 设置字体:
AfxGetMainWnd()->SetWindowText(_T("配置文件设定器"));//设置标题
CFont ft;
ft.CreateFont(20,20,3,0,FW_THIN,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,"幼圆");
GetDlgItem(IDC_EDIT_FORM )->SetFont(&ft);GetDlgItem(IDC_EDIT_VERSION)->SetFont(&ft);GetDlgItem(IDC_EDIT_MODAL)->SetFont(&ft);GetDlgItem(IDC_BUTTON_UPDATE)->SetFont(&ft);
void CMyButton::PreSubclassWindow()
{
CButton::PreSubclassWindow();
ModifyStyle(0,BS_OWNERDRAW);
}
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH;
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
CClientDC dc(this);
CPen pen;
pen.CreatePen(PS_SOLID,2,RGB(127,127,127));
dc.SelectObject(pen);
CRect rect;
GetClientRect(&rect);
CPoint point;
point.x=10;
point.y=10;
dc.RoundRect(rect,point);
CRgn rgn;
rgn.CreateRoundRectRgn(rect.left,rect.top,rect.right,rect.bottom,10,10);
CBrush brush;
if (lpDrawItemStruct->itemState & ODS_SELECTED)
{
brush.CreateSolidBrush(RGB(0,255,255));
}else
{
brush.CreateSolidBrush(RGB(255,255,255));
}
dc.FillRgn(&rgn,&brush);
}
按钮的绘制、、
CMyEdit::CMyEdit()
{
m_ctrlBk=RGB(0,225,0);
m_ctrlText=RGB(127,127,127);
m_brBk.CreateSolidBrush(m_ctrlBk);
}
CMyEdit::~CMyEdit()
{
}
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
//{{AFX_MSG_MAP(CMyEdit)
ON_WM_CTLCOLOR_REFLECT()
ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CMyEdit message handlers
HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetBkColor(m_ctrlBk);
pDC->SetTextColor(m_ctrlText);
// TODO: Return a non-NULL brush if the parent's handler should not be called
return m_brBk;
}
Edit控件的颜色控制。
窗口移动
CMyDialog dialog;
dialog.Create(IDD_DIALOG_TOOL);
::MoveWindow(dialog.m_hWnd,0,0,500,500,FALSE);
dialog.ShowWindow(SW_SHOW);
CBrush brush;
brush.CreateSolidBrush(RGB(0,255,0));
CRect rect;
GetClientRect(&rect);
pDC->FillRect(&rect,&brush);
//return CDialog::OnEraseBkgnd(pDC);
return true;
//增加两个接口函数觉得是否使用速度曲面/
[USER_OPERN_SPEED]
UseState=0
Min_Speed=200
void CDNCConfigure::GetOpern_SpeedUseState(bool& bEnableSet)
{
if ('/0' == m_szFnConfig[0])
{
return;
}
char szState[256]={'/0'};
DWORD dWord;
dWord=GetPrivateProfileString(UseOpern_Speed,UseOpern_Speed_State,"",szState,256,m_szFnConfig);
if(dWord==0)
{
return;
}
bEnableSet=(atoi(szState)==1)?true:false;
}
//Desc:to get the minSpeed in Use opern_speed
//Para:MinSpeed
DWORD CDNCConfigure::GetOpern_SpeedMinSpeed(double& minSpeed)
{
if('/0'==m_szFnConfig[0])
{
return -1;
}
char szMinSpeed[256]={'/0'};
DWORD dWord;
dWord=GetPrivateProfileString(UseOpern_Speed,UseOpern_Speed_MinSpeed,"",szMinSpeed,256,m_szFnConfig);
if(dWord==0)
{
return -1;
}
minSpeed=atof(szMinSpeed);
return 1;
}