12.1 INI配置文件
UINT GetProfileInt( LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault );
从应用程序的配置文件(.INI)的一个配置项中获取一个整数
CString GetProfileString(LPCTSTR szSection, LPCTSTR szEntry, LPCTSTR szDefault = NULL );
从应用程序的配置文件(.INI)的一个配置项中获取一个字符串
BOOL WriteProfileInt(LPCTSTR szSection, LPCTSTR szEntry, int nValue );
将一个整数写到应用程序的配置文件(.INI)文件的配置项中
BOOL WriteProfileString(LPCTSTR szSect, LPCTSTR szEntry, LPCTSTR lpszValue );
将一个字符串写到应用程序的配置文件(.INI)文件的配置项中
void SetRegistryKey( LPCTSTR lpszRegistryKey );
使应用程序的配置保存在注册表中,而不保存于(.INI)文件中
WriteProfileBinary
:把二进制数据写入配置文件或注册表(例如:结构体对象的存取)
GetProfileBinary
:从配置文件或注册表提取二进制数据(例如:结构体对象的存取)
DoWaitCursor
:在一个函数执行时间很长时使用;
CWaitCursor a;
//构造时忙,析构时恢复;
BOOL CNotepadApp::InitInstance()
{SetRegistryKey(_T("NotePad"));free((LPTSTR)m_pszProfileName);m_pszProfileName =(LPCTSTR) malloc(256);_tcscpy_s((LPTSTR)m_pszProfileName,128, _T("./notepad.ini"));CNotepadDlg dlg;m_pMainWnd = &dlg;INT_PTR nResponse = dlg.DoModal();return FALSE;
}
void CNotepadDlg::OnDestroy()
{CDialogEx::OnDestroy();CRect rect;//RECT* GetWindowRect(rect);theApp.WriteProfileInt(_T("RECT"), _T("LEFT"), rect.left);theApp.WriteProfileInt(_T("RECT"), _T("RIGHT"), rect.right);theApp.WriteProfileInt(_T("RECT"), _T("TOP"), rect.top);theApp.WriteProfileInt(_T("RECT"), _T("BOTTOM"), rect.bottom);
// theApp.WriteProfileString(_T("SETTING"), _T("CAPTION"), _T("我的记事本"));
}
12.2 INI配置文件的特点
a)方便保存和加载,比CFile使用方便多了;
b)方便运营人员在程序外配置数据,配置好的数据参与程序启动后的运行;
c)方便数据管理,比如数据可以保存在注册表中;
12.3 CDialog类常用成员函数:
a)DoModal:创建模式对话框
b)Create:创建非模式对话框
c)NextDlgCtrl:
d)PrevDlgCtrl:
e)GotoDlgCtrl:
f)GetDefID SetDefID:
12.4 CDialog的派生类,CDialogEx:里面新增了背景颜色设置和背景图片(居上下左右或平铺)
CCommandDialog派生了以下这些类。
a)CColorDialog: Lets user select colors.
b)CFileDialog: Lets user select a filename to open or to save.
c)CFindReplaceDialog: Lets user initiate a find or replace operation in a text file.
d)CFontDialog: Lets user specify a font.
e)CPrintDialog: Lets user specify information for a print job.
f)CPrintDialogEx Windows 2000 print property sheet.
12.5 COLORREF类型
四个字节变量类型(DWORD),最低位是红,然后是绿和蓝代表RGB颜色。
GetRValue
:拆分其中最低字节的红(分量数值)。
GetGValue
:拆分其中第二个字节的(绿分量数值)。
GetBValue
:拆分其中第三个字节的(蓝分量数值)。
红 RGB(255,0,0)
反色 青 RGB(0,255,255)
绿 RGB(0,255,0)
发色 紫 RGB(255,0,255)
蓝 RGB(0,0,255)
反色 黄 RGB(255,255,0)
粉红色:RGB(255,128,128)
粉紫色:RGB(255,128,255)
深绿色:RGB(0,128,0)
12.6 CColorDialog:颜色对话框
a)构造函数:CColorDialog dlg(0,0,GetDesktopWindow());让对话框成为独立窗口(不附着于主窗口)
b)CColorDialog dlg(RGB(255,128,128));让对话框弹出时选中一个指定的颜色
12.7 CFontDialog:字体对话框
a)CFontDialog
构造函数:根据指定LOGFONT
结构体,对话框启动时将按照带入的信息初始化;
b)GetCurrentFont(LPLOGFONT plf)
:把选中的字体信息输出到指针指向的LOGFONT结构体内;
c)CFont::CreateFontIndirect(const LPLOGFONT plf)
:把指定的字体信息(名称大小粗体等)生成Font句柄;
d)CFont::GetLogFont(LPLOGFONT plf)
:从CFont类对象内的句柄解析出字体信息((名称大小斜体等));
e)CWnd::GetFont
:获取一个窗口已经设置好的CFont对象(指针);
f)CWnd::SetFont
:将含有句柄的CFont对象(指针)设置到一个窗口上;