日历

2008 7.27 Sun
  12345
6789101112
13141516171819
20212223242526
2728293031  
«» 2008 - 7 «»

文章搜索

日志文章

2008年03月09日 20:43:59

VC目录获取方法

  今天做个东西的时候,突然需要这个东西,上网一查,有人就说用下面的方法,但是不是想要的结果

Copy code

#include < windows.h >
#include < string.h >

HINSTANCE hInst;
char szBuf[256];
char *p;
GetModuleFileName(hInst,szBuf,sizeof(szBuf));
p = szBuf;
while(strchr(p,'\\')) {
p = strchr(p,'\\');
p++;
}
*p = '\0';


上面的这个是获取当前选择的目录路径的,比如说常用的文件选择对话框选择路径的获取.下面的方法才是想要的.程序中我是想要获取安装在我程序的子目录下的winrar.exe的路径,就这样写,
Copy code

CString get_direct()
{
char temp [256];
  char drive[256];
  char dir[256];
  CString str1, str2;
  GetModuleFileName(NULL, temp, 256);
  _splitpath(temp, drive, dir, NULL, NULL );
  str1 = drive;
  str2 = str1+dir;
str2.Replace("[url=file://\\]\\","\\\\"); //此处由于我要在命令行中使用,所以要把\这个转义符搞掉
str2=str2+"Cunzip\\WinRAR.exe";
return str2;
}


呵呵,问题虽小,但没用过就是不晓得哈. ) :

Tags: VC目录获取  

类别: C++编程 |  评论(0) |  浏览(861) |  收藏
发表评论