1.問題背景
使用afxmessagebox彈出資訊框,此函數沒有設定标題的參數,預設标題為建立的項目名稱。
注:因使用的環境不允許使用messagebox.so....尋找之路。。。
2.初識 m_pszAppName
MSDN: The application name can come from the parameter passed to the CWinApp constructor, or, if not specified, to the resource string with the ID ofAFX_IDS_APP_TITLE. If the application name is not found in the resource, it comes from the program's .EXE filename.
根據MSDN的描述,我們隻要改掉這個值就可以了,如何修改。
3.實踐操作
我想實作在CDlg_Test.cpp中所有的标題都設為“網絡安全”。
a)構造函數時修改
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)AfxGetApp()->m_pszAppName);
//Change the name of the application file.
//The CWinApp destructor will free the memory.
AfxGetApp()->m_pszAppName = _tcsdup("網絡安全");
ps:此時使用afxmessage(),标題就變為改之後的。
b)重寫DoMessageBox--此種方式筆者沒有親自實驗:)
int CEx0811aApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
{
LPCTSTR pOldAppName = m_pszAppName;
m_pszAppName = "新标題";// 其實afxmessgebox的标題就是這個變量決定的
int iRet = CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
m_pszAppName = pOldAppName ;
return iRet ;
}