求教高手二个关于路径名称的问题

No9 2001-10-22 11:15:08
请教高手们:
一.有没有什么API能够得到程序自己的完整路径名称呢?
二.有没有什么API能够得到桌面的完整路径名称呢?
...全文
186 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
No9 2001-10-23
  • 打赏
  • 举报
回复
感谢大家的帮忙!
尤其是非常感谢 Hoarfrost 老兄的回答!
eggplant 和 liqi 回答也解决的另外一个问题!

由于各位的积极参与,本人觉得分数好像有点少!
决定再添一些分!——将这40分全部给予 Hoarfrost 作为酬谢!
hsdly 2001-10-23
  • 打赏
  • 举报
回复
把去掉"Media\\"+"bmp4.bmp"就得到是路径了
hsdly 2001-10-23
  • 打赏
  • 举报
回复
如果你要得到的是你的可执行程序的路径你可以这样试一试:

TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中定义了吧,好象是128
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
bitmapstr=((CString)exeFullPath).Left(((CString)exeFullPath).GetLength()-8);
if(bitmapstr.Find("DEBUG")!=-1)
bitmapstr=bitmapstr.Left(bitmapstr.GetLength()-6);
bitmapstr=bitmapstr+"Media\\"+"bmp4.bmp";
liqi 2001-10-23
  • 打赏
  • 举报
回复
TCHAR exeFullPath[MAX_PATH];
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
试试这个,我用这个好使。
No9 2001-10-23
  • 打赏
  • 举报
回复
上面的老兄们,GetCurrentDirectory()函数我也知道的!
但我的问题是如何得到完整的名称,而GetCurrentDirectory()仅仅是得到了路径而已,程序名称还不知道呢?这么办呀?
eggplant 2001-10-23
  • 打赏
  • 举报
回复
还是GetModuleFileName()保险。
瑶瑶爸爸 2001-10-23
  • 打赏
  • 举报
回复
桌面路径可以从注册表中获得:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Desktop(String)=桌面路径

也可用以下API函数:
WINSHELLAPI HRESULT WINAPI SHGetSpecialFolderLocation(;

HWND hwndOwner,
int nFolder,
LPITEMIDLIST *ppidl
);


Parameters

hwndOwner

Handle of the owner window that the client should specify if it displays a dialog box or message box.

nFolder

Value specifying the folder to retrieve the location of. This parameter can be one of the following values:

CSIDL_BITBUCKET Recycle bin ?file system directory containing file objects in the user's recycle bin. The location of this directory is not in the registry; it is marked with the hidden and system attributes to prevent the user from moving or deleting it.
CSIDL_CONTROLS Control Panel ?virtual folder containing icons for the control panel applications.
CSIDL_DESKTOP Windows desktop ?virtual folder at the root of the name space.
CSIDL_DESKTOPDIRECTORY File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself).
CSIDL_DRIVES My Computer ?virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
CSIDL_FONTS Virtual folder containing fonts.
CSIDL_NETHOOD File system directory containing objects that appear in the network neighborhood.
CSIDL_NETWORK Network Neighborhood ?virtual folder representing the top level of the network hierarchy.
CSIDL_PERSONAL File system directory that serves as a common respository for documents.
CSIDL_PRINTERS Printers folder ?virtual folder containing installed printers.
CSIDL_PROGRAMS File system directory that contains the user's program groups (which are also file system directories).
CSIDL_RECENT File system directory that contains the user's most recently used documents.
CSIDL_SENDTO File system directory that contains Send To menu items.
CSIDL_STARTMENU File system directory containing Start menu items.
CSIDL_STARTUP File system directory that corresponds to the user's Startup program group.
CSIDL_TEMPLATES File system directory that serves as a common repository for document templates.

ppidl
Address that receives a pointer to an item identifier list specifying the folder's location relative to the root of the name space (the desktop).

Return Values
Returns NOERROR if successful or an OLE-defined error result otherwise.
pursuer_zhao 2001-10-23
  • 打赏
  • 举报
回复
GetCurrentDirectory() ----当前程序路径
GetDesktopWindow()-----桌面路径
SHGetSpecialFolderPath()---返回指定文件夹路径
具体用法看MSDN
swordbroken 2001-10-23
  • 打赏
  • 举报
回复
GetCurrentDirectory()可以得到当前运行程序所在的路径

得到桌面路径的函数我不知道
fiolin 2001-10-23
  • 打赏
  • 举报
回复
up
Eason 2001-10-22
  • 打赏
  • 举报
回复
VC下有这样一个__argv[0]
用它可以得到应用程序运行的路径
比如
AfxMessageBox(__argv[0])或是printf("%s\r\n",__argv[0])
都可以得到程序自己的完整路径名称呢

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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