CWinApp::m_pszAppName
ResSpecifies the name of the application. 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 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(“d:\\somedir\\myapp.exe”));ExampleCWnd* pWnd;
// 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("Some message", AfxGetApp()->m_pszAppName); // A more direct way to get the application title is to
// call AfxGetAppName:
pWnd->MessageBox("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("Some message");
ResSpecifies the name of the application. 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 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(“d:\\somedir\\myapp.exe”));ExampleCWnd* pWnd;
// 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("Some message", AfxGetApp()->m_pszAppName); // A more direct way to get the application title is to
// call AfxGetAppName:
pWnd->MessageBox("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("Some message");
解决方案 »
- DELETEFILE求助
- VC++ TCP/IP通信的问题?
- ADO连接ACCESS换个操作系统运行报错问题
- 一个问题急待解决,如何简便的判断一个进程是否结束?
- com本质论中关于动态复合tearoff的疑问
- 字符数组拷贝到CString类问题
- 郁闷了,在vs2005下,怎么没有FMC ISAPI扩展的向导了
- 用BcgControlBar pro 7.1时,CBCGPOutlookBar类用静态连接时出错,我该怎么办。
- 可以定义一个CView窗口中的CDC吗?
- activex BSTR出口
- SetTimer(1,300,NULL)引起的问题 我查了MSDN应该有四个参数,函数重载后
- 大家谁用过16进制编辑器,比如Hex Workshop 。请大家评比一下那个最好用!
代码:
char szCurrDir[256];
GetCurrentDirectory(256,szCurrDir);
当前应用程序路径即赋给字符串数组szCurrDir.
DWORD GetModuleFileName(
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer to receive module path
DWORD nSize // size of buffer, in characters
);第一个参数用NULL即可,可以得到路径和文件问,只需去掉文件名即可了
::GetCurrentDirectory(50,butter);
AfxMessageBox(butter);
char szCurrDir[256];
GetCurrentDirectory(256,szCurrDir);
当前应用程序路径即赋给字符串数组szCurrDir.