文件對話框,打開文件的對話框:
void CTest38Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFileDialog* file;
file = new CFileDialog(true,"bak");
file->DoModal();
delete file;
}
改變編輯的字體。其中m_font是自己設置的一個CFont類型的成員,用于保留和設置字體。
具體的來說就是創建一個對于的fontdialog,然后就是獲得字體,設置字體。。
void CTest39Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFont * tempfont = m_edit.GetFont(); //獲得編輯字體的信息
LOGFONT logfont;
tempfont->GetLogFont(&logfont); //初始化字體信息,初始化的值放在logfont
CFontDialog fontdlg(&logfont); //創建模態對話框
if(fontdlg.DoModal() == IDOK){
m_font.Detach();
LOGFONT temp;
fontdlg.GetCurrentFont(&temp); //獲得當前字體信息
m_font.CreateFontIndirect(&temp); //創建字體
m_edit.SetFont(&m_font); //設定字體
}
}
顏色對話框的實現,如何設置顏色:
初始化代碼:
m_text.SetWindowText("Hello,world");
m_textcolor = RGB(0,0,255);
其中m_textcolor是自定義的一個COLORREF類型的顏色,用來保存和設置的。。。
自己需要編寫的函數:
HBRUSH CTest40Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pDC->SetTextColor(m_textcolor);
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CTest40Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CColorDialog ColorDlg(m_textcolor);
if(ColorDlg.DoModal() == IDOK){
m_textcolor = ColorDlg.GetColor();
Invalidate(); //重繪窗口。
}
}
一個就是顏色的消息,另外一個就是具體的點擊設置之后的打開顏色對話框的消息。
其中,選擇顏色并重繪窗口是針對所以的,想想可以有好的辦法沒有。
該程序會設置所有的文本為選擇的顏色。
針對于單個文本框,可以添加m_text.Invalidate(),不過,由于是設置所以的畫筆顏色,于是,在其他文本框被激活的時候,也會造成相同的顏色。
posted on 2010-02-08 21:35
deercoder 閱讀(652)
評論(0) 編輯 收藏 引用