共用方式為


CWinApp::m_pszAppName

指定應用程式的名稱。

LPCTSTR m_pszAppName;

備註

應用程式名稱可能來自參數傳遞至 CWinApp 建構函式,或者,如果不指定,會以 AFX_IDS_APP_TITLEID 的資源字串。 如果應用程式名稱不在資源中找到,其在程式的 .EXE 檔名。

傳回由全域函式 AfxGetAppNamem_pszAppName 是型別 **const char***的公用變數。

注意事項注意事項

如果您將值指派給 m_pszAppName,在堆積上必須動態配置它。CWinApp 解構函式呼叫 free() 與這個指標。您想要使用許多 _tcsdup() 執行階段程式庫函式會配置。此外,請釋放記憶體與目前指標在指派新值以前。例如:

//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszAppName);
//Change the name of the application file.
//The CWinApp destructor will free the memory.
m_pszAppName = _tcsdup(_T("c:\\somedir\\myapp.exe"));

範例

CWnd* pWnd = AfxGetMainWnd();
// Set pWnd to some CWnd object whose window has already
// been created.

// The following call to CWnd::MessageBox uses the application
// title as the message box caption.
pWnd->MessageBox(_T("Some message"), AfxGetApp()->m_pszAppName);

// A more direct way to get the application title is to 
// call AfxGetAppName:
pWnd->MessageBox(_T("Some message"), AfxGetAppName());

// An easier way to display a message box using the application
// title as the message box caption is to call AfxMessageBox:
AfxMessageBox(_T("Some message"));

需求

Header: afxwin.h

請參閱

參考

CWinApp 類別

階層架構圖