1. MFC中使用richedit控件
--在CxxxxAPP::InitInstance()函数中添加AfxInitRichEdit()即可
2. mfc的对话框程序怎么加菜单栏
--在对话框头文件中声明CMenu 变量,例如m_Menu;
--在OnInitDlg()中加入如下语句:
--m_Menu.LoadMenu("此处加入你的菜单id");
--SetMenu(&m_Menu);
3. 给基于对话框的MFC程序添加状态栏并实时显示时间
1.首先在string table 里添加两个字串,ID分别为IDS_INDICATOR_MESSAGE and IDS_INDICATOR_TIME
2.在你的 dlg.h 类里面加个 CStatusBar m_bar;
3.在dlg.cpp 开头加上
static UINT indicators[] =
{
IDS_INDICATOR_MESSAGE,
IDS_INDICATOR_TIME
};
4.OnInitDialog 里面加上
m_bar.Create(this); //We create the status bar
m_bar.SetIndicators(indicators,2); //Set the number of panes
CRect rect;
GetClientRect(&rect);
//Size the two panes
m_bar.SetPaneInfo(0,IDS_INDICATOR_MESSAGE,
SBPS_NORMAL,rect.Width()-100);
m_bar.SetPaneInfo(1,IDS_INDICATOR_TIME,SBPS_STRETCH ,0);
//This is where we actually draw it on the screen
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,
ID_INDICATOR_TIME);
5.时间显示
OnInitDialog 里面加 SetTimer(1,1000,NULL);
为你的dlg类添加WM_TIMER的响应函数,在其中添加代码:
CTime t1;
t1=CTime::GetCurrentTime();
m_bar.SetPaneText(1,t1.Format("%H:%M:%S"));
CDialog::OnTimer(nIDEvent);
这样添加的程序刚开始运行时在时间一栏中显示的是初始设置的字符,为了使程序在刚开始运行时就显示系统时间,可在m_bar.SetPaneInfo(1,IDS_INDICATOR_TIME,SBPS_STRETCH ,0);后添加如下代码:
CTime t1;
t1=CTime::GetCurrentTime();
m_bar.SetPaneText(1,t1.Format("%H:%M:%S"));
这样在程序刚启动时就会显示系统时间,然后实时更新。
4. vs2010 mfc框架字体偏小临时解决办法
首先,这是一个MFC的Bug
http://connect.microsoft.com/VisualStudio/feedback/details/505466/mfc-visual-style-font-size-too-small-to-display-chinese-character-clearly-on-windows-xp
解决时间暂时还不确定,临时的方案如下:
App在InitInstance中加入:
LOGFONT logfont = {0};
:: SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &logfont, 0);
afxGlobalData.SetMenuFont(&logfont,true);
注释:
字体的设置保存在一个全局变量afxGlobalData中,此变量定义AfxGlobals.h中。
AFX_GLOBAL_DATA中有一个SetMenuFont可以设定字体属性,影响Menu、Toolbar、Dock Pane等的caption字体。
但是这个设置对tooltip无影响,临时解决:在上面代码基础上在加入
if(afxGlobalData.fontTooltip.GetSafeHandle() != NULL)
{
::DeleteObject(afxGlobalData.fontTooltip.Detach());
}
afxGlobalData.fontTooltip.CreateFontIndirect(&logfont);
5.VS2010中 VC++目录的设定
VS2010不同于已前版本:选择菜单“工具”->“选项”->“项目和解决方案”->“VC++目录”
新的配置方法:项目->属性->配置属性->"VC++ Directories"
以上方法只针对于某一特定项目,对于所有的项目设置如下:
可以直接修改 <drive>:\Documents and Settings\ <user>\Local Settings\Application Data\Microsoft\MSBuild\v4.0. 目录下的文件。Microsoft.Cpp.Win32.user (32位平台) 或者是Microsoft.Cpp.X64.user(64位平)
比如 原来内容为:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<ReferencePath>$(ReferencePath)</ReferencePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
<SourcePath>$(SourcePath)</SourcePath>
<ExcludePath>$(ExcludePath)</ExcludePath>
</PropertyGroup>
</Project>
我现在需要增加一个目录:
C:\Boost\include\boost-1_43\;到默认头Include 路径,则可以修改文件如下:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>C:\Boost\include\boost-1_43\;$(IncludePath)</IncludePath>
<ReferencePath>$(ReferencePath)</ReferencePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
<SourcePath>$(SourcePath)</SourcePath>
<ExcludePath>$(ExcludePath)</ExcludePath>
</PropertyGroup>
</Project>
6. 如何使得WIN7下用VS2010做出的MFC程序具有XP风格(摆脱传统界面的效果)
1. 将下面这段XML保存到你的工程目录下,文件名为XPStyle.manifest(注意后缀不是xml)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="XP style manifest"
type="Win32"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="Win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
2. 在VC中点添加资源, 将XPStyle.manifest文件作为资源文件加入到你的工程中,
填资源类型号为24或者RT_MANIFEST(这是因为manifest格式文件不是VC的常规资源文件), 自己设定一个资源ID,比如说IDR_XP_STYLE或者1都可以.
(1).如果是dll工程,则在Resource.h中修改:
#define IDR_XP_STYLE 2
并在StdAfx.h中添加
#define ISOLATION_AWARE_ENABLED 1
(2).如果是exe工程,则在Resource.h中修改:(自己没有做这一步,发现并无影响)
#define IDR_XP_STYLE 1
3. 点击全部编译,运行你的程序看看.
(友情提示: 编译出来的程序在非XP系统下没有XP风格界面,将是传统的界面效果)
使用.manifest文件不费任何力气就可以在xp系统里实现xp风格的控件,但是这样做有一点不方便的地方就是manifest必须放到exe所在目录,如下做法可以将manifest文件放到资源文件中,编译后生成.res文件,link后自然就和.exe文件“合”到一起了。