【MFC系列-第12天】Windows系统对话框
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對象(指針)設置到一個窗口上;
總結
以上是生活随笔為你收集整理的【MFC系列-第12天】Windows系统对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【MFC系列-第11天】CWinApp类
- 下一篇: 角色扮演游戏的种类可以分为几种?