学习心得之七(续)--字体启动程序的设计
昨天我们写了大概的字体启动程序的代码,也讲解比较详细,我们来看看运行结果:
我们看到运行出来了,而且每次的颜色都不同,并不是我们运行了两个不同的程序哦!而是字体自己变色的。
接下来我们删除我们运行的结果:
黑色箭头所指的地方就是我们VC运行的对话框,我们删了它:
我们发现竟然还有对话框,这是为什么呢?我们看看VC的资源视图,黑色箭头的是我们自己的工程所给予的对话框,红色的箭头就是我们新建对话框类的所基于的对话框
我们看看昨天的文章《学习心得之七---程序启动画面的设计》,最后的时候,我们在CApp类的InitInstance()函数中,添加了这两句代码:
CRunMode runmode;
runmode.DoModal();
我们看看完整的代码:
BOOL CFormApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CRunMode runmode;
runmode.DoModal();
/**** CFormDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.****/
return FALSE;
// GetClientRect(clientRC);
}
资源视图中有两个对话框,而我们的CApp类中有两个对话框创建函数,因此我们注释掉一个就行了,我们把上述代码中的/****与****/中的代码注释掉,就行了。
最后我们改下字体启动程序的字体大小,原本它是(50,30),我们改为(80,80),看看运行效果:
看!字体竟然没有显示完全?这又是为什么呢?我们知道,我们创建的字体是基于新建类的对话框区域,也就是基于我们上面第二幅图中ID号为IDD_DIALOG1的对话框,于是我们想到,是不是我们新建对话框的大小不够?我们试试改变它的大小:
我们最大限度的增大对话框的大小,我们看看运行结果:
果然!我们运行成功了。