次の方法で共有


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"));

必要条件

ヘッダー: afxwin.h

参照

関連項目

CWinApp クラス

階層図