Export (0) Print
Expand All
Expand Minimize
0 out of 3 rated this helpful - Rate this topic

CWinApp::m_pszAppName

Specifies the name of the application.

LPCTSTR m_pszAppName;

The application name can come from the parameter passed to the CWinApp constructor, or, if not specified, to the resource string with the ID of AFX_IDS_APP_TITLE. If the application name is not found in the resource, it comes from the program's .EXE filename.

Returned by the global function AfxGetAppName. m_pszAppName is a public variable of type const char*.

Note Note

If you assign a value to m_pszAppName, it must be dynamically allocated on the heap. The CWinApp destructor calls free( ) with this pointer. You many want to use the _tcsdup( ) run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example:

//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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.