MFC--CColorDialog的使用
MFC--CColorDialog的使用??
2012-05-07 11:05:32|??分類: 學習mfc/c++ |??標簽: |字號大中小?訂閱
要在類中定義一個存儲顏色的變量COLORREF m_color;
創(chuàng)建一個按鈕,用來調用CColorDialog,用以改變靜態(tài)文本的顏色,(靜態(tài)文本需改變ID才可以對靜態(tài)文本進行文本的編輯) 想要得到的文本文字的顏色,需要在oninitDialog函數(shù)中進行初始化m_myStaticEdit="hellonihao";//
m_color=RGB(255,0,0);初始化顏色變量
GetDlgItem(IDC_MY_STATIC)->InvalidateRect(NULL);創(chuàng)新刷一遍窗口
UpdateData(FALSE);
void CMyDlg::OnButton1() { // TODO: Add your control notification handler code here CColorDialog colorDia; if (colorDia.DoModal()==IDOK) { m_color=colorDia.GetColor(); GetDlgItem(IDC_MY_STATIC)->InvalidateRect(NULL); }}
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
UpdateData(TRUE); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//
if (pWnd->GetDlgCtrlID()==IDC_MY_STATIC) //判斷是靜態(tài)文本
{
pDC->SetTextColor(m_color);
}
UpdateData(FALSE);
// TODO: Return a different brush if the default is not desired
return hbr;
}
總結
以上是生活随笔為你收集整理的MFC--CColorDialog的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MFC下列表控件的使用
- 下一篇: MFC中打开文件对话框:CFileDlg