随笔-145  评论-173  文章-70  trackbacks-0

文件对话框,打开文件的对话框:

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 阅读(633) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理