zoukankan      html  css  js  c++  java
  • 021.MFC_字体和颜色对话框

    字体、颜色对话框

    字体对话框 CFontDialog

    颜色对话框 CColorialog

    富文本框 CRichEdit

    一、建立名为FontAndColor的MFC工程,添加menu资源,并添加到对话框。修改id 分别为ID_FONT、ID_COLOR。主窗口添加rich edit 构建,并添加初始化

     二、为menu添加事件处理程序

    void CFontAndColorDlg::OnFont()
    {
    	// TODO: 在此添加命令处理程序代码
    	CHARFORMAT cf={0};
    	cf.cbSize = sizeof(cf);
    	//获取当前文本框文字格式
    	m_editcontent.GetSelectionCharFormat(cf);
    	CFontDialog dlg(cf);
    	if(dlg.DoModal() == IDOK)
    	{
    		dlg.GetCharFormat(cf);
    		m_editcontent.SetSelectionCharFormat(cf);
    	}
    }
    
    
    void CFontAndColorDlg::OnColor()
    {
    	// TODO: 在此添加命令处理程序代码
    	CHARFORMAT cf={0};
    	cf.cbSize = sizeof(cf);
    	//只修改颜色
    	cf.dwMask = CFM_COLOR;
    
    	m_editcontent.GetSelectionCharFormat(cf);
    
    	CColorDialog dlg(cf.crTextColor);
    	if(dlg.DoModal() == IDOK)
    	{
    		//获取选中的颜色
    		cf.crTextColor = dlg.GetColor();
    		cf.dwEffects = 0;
    		//设置字体颜色
    		m_editcontent.SetSelectionCharFormat(cf);
    	}
    }
    

     三、源码下载

    链接:https://pan.baidu.com/s/1eldBgaftRy-qw-rUFLDy6g
    提取码:06bh

  • 相关阅读:
    Centos Another app is currently holding the yum lock
    Centos 重置密码
    Effective c#学习笔记(1)
    浅谈计算机编码
    mongodb java spring data
    VS2013 好用的插件
    xml存储bug
    VS 2008 生成操作中各个选项的差别
    程序权限控制
    给钛度产品的一些建议(Note)
  • 原文地址:https://www.cnblogs.com/Malphite/p/14967359.html
Copyright © 2011-2022 走看看