CWinApp::m_pszAppName
更新 : 2007 年 11 月
アプリケーション名を示します。
LPCTSTR m_pszAppName;
解説
アプリケーション名は、CWinApp のコンストラクタから渡されたパラメータか、それが指定されないときは、AFX_IDS_APP_TITLE の ID を持つリソース文字列が使われます。リソースにアプリケーション名が見つからないときは、プログラムの .EXE ファイル名が使われます。
これは、グローバル関数 AfxGetAppName から返されます。m_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"));
必要条件
ヘッダー : afxwin.h