如何获取MFC ActiveX控件本身所在的路径?

bacaihong 2006-02-18 05:26:26
我刚学VC,典型的菜鸟,我现在用MFC ActiveX向导作了一个OCX控件,我想在控件创建时(OnCreate)
时,自动在控件所在路径下生成一个.\Images的子目录。
现有两个小问题:
1)如何获取控件本身(OCX)所在的路径
2)如何创建子目录?
3)如何删除该子目录(.\Images)下的后缀为"*.jpg"的文件?

先多谢各位大哥指点!
...全文
312 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bacaihong 2006-02-19
  • 打赏
  • 举报
回复
多谢,结贴了!
winehero 2006-02-19
  • 打赏
  • 举报
回复
1.
CString GetCurPath()
{
TCHAR exeFullPath[MAX_PATH];
CString strPath;
GetModuleFileName(AfxGetInstanceHandle(),exeFullPath,MAX_PATH);
strPath.Format("%s", exeFullPath);
if(strPath.Right(1)!="\\") strPath += "\\";
return strPath;
}
2.CreateDirectory(全路径字符串, NULL);
3.
short CleanTmpFiles(CString strImagePath)
{
int nFiles=0;
CFileFind finder;
char tempFileFind[200];
sprintf(tempFileFind, "%s\\*.jpg", m_strImagePath);
BOOL IsFinded = (BOOL)finder.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded = (BOOL)finder.FindNextFile();
if(!finder.IsDots())
{
char foundFileName[200];
strcpy(foundFileName, finder.GetFileName().GetBuffer(200));
if(!finder.IsDirectory())
{
char tempFileName[200];
sprintf(tempFileName,"%s%s", strImagePath, foundFileName);
DeleteFile(tempFileName);
nFiles++;
}
}
}
finder.Close();
return nFiles;
}
DentistryDoctor 2006-02-18
  • 打赏
  • 举报
回复
2)
CreateDirectory
3)
枚举*.jpg(CFileFind),DeleteFile
bacaihong 2006-02-18
  • 打赏
  • 举报
回复
DentistryDoctor(MVP-My heart will fly,in the sky.) 大侠,那么后两个问题如何解决,偶
实在是很菜的。。。
DentistryDoctor 2006-02-18
  • 打赏
  • 举报
回复
GetModuleFileName(AfxGetInstanceHandle(),...);
bacaihong 2006-02-18
  • 打赏
  • 举报
回复
我用GetModuleFileName获取的是容器的路径,而不是控件本身的路径,郁闷中,在线急等。。。

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧