双击MFC文档时如何获取MFC应用程序文件的路径 [英] How to get path of MFC application file when double click in MFC document

查看:102
本文介绍了双击MFC文档时如何获取MFC应用程序文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好家伙

我有一个MFC应用程序,并且doc是* .cvt

当我双击cvt文件时,GetCurrentDir函数获取cvt的路径文件,而不是应用程序文件的路径

如何获取路径应用程序文件?



Hi guy
I'm have a MFC application, and there doc is *.cvt
When I double click cvt file, GetCurrentDir function is get path of cvt file, not path of application file
How i get path Application file ?

CString utility::GetPathExe()
{
	char cCurrentPath[FILENAME_MAX];
	if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
	{
		return _T("");
	}
	cCurrentPath[sizeof(cCurrentPath)-1] = '\0'; /* not really required */
	CString szResult = _T("");
	szResult = cCurrentPath;
	return szResult;
}

推荐答案

可执行文件的路径和名称存储在传递的第一个命令行参数数组条目中到主要功能。所以你可以复制或存储一个指针。



或者你可以使用 GetModuleFileName() [ ^ ]功能:

The path and name of the executable file are stored in the first command line argument array entry that is passed to the main function. So you may copy that or store a pointer.

Alternatively you can use the GetModuleFileName()[^] function:
// Get path of the executable file of the current process
TCHAR path[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
// Remove the file name
// Set ext[0] to zero to strip also the trailing back slash
LPCTSTR ext = _tcsrchr(path, _T('\\'));
if (ext)
    ext[1] = _T('\0');


这篇关于双击MFC文档时如何获取MFC应用程序文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆