鼠标点击桌面图标获取文件全名

coder_shadow 2017-01-17 06:10:49

SIZE_T len = sizeof(LVITEM);
lvi.cchTextMax = 512;
lvi.iSubItem =0;
lvi.pszText=(LPWSTR)_item ;
lvi.mask = LVIF_IMAGE |LVIF_TEXT |LVIF_STATE |LVIF_PARAM;
if(!WriteProcessMemory(g_hProcess, _lvi, &lvi, sizeof(LVITEM), NULL)){
rs =GetLastError();
}
::SendMessage(g_DLVhwnd, LVM_GETITEMTEXT, (WPARAM)icont, (LPARAM)_lvi);
ReadProcessMemory(g_hProcess, _item, item, 512, NULL);


使用上面代码获取鼠标选中单个桌面文件名,但是在文件扩展名隐藏的时候不能获取到文件扩展名,有没有高手能帮我看看。
多谢多谢!
...全文
1042 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
顾小白xx 2021-02-22
  • 打赏
  • 举报
回复
你把这个文件的隐藏文件扩展名的属性去掉获取然后在给他设置回去不就完了么
murongyuan 2020-12-04
  • 打赏
  • 举报
回复
这个需求解决了吗?我来挖坟了。。。
schlafenhamster 2017-02-02
  • 打赏
  • 举报
回复
试试 GetFileAttributesEx The GetFileAttributesEx function obtains attribute information about a specified file or directory. This function is similar to the GetFileAttributes function. GetFileAttributes returns a set of FAT-style attribute information. GetFileAttributesEx is designed to obtain other sets of file or directory attribute information. Currently, GetFileAttributeEx obtains a set of standard attributes that is a superset of the FAT-style attribute information. BOOL GetFileAttributesEx( LPCTSTR lpFileName, // pointer to string that specifies a // file or directory GET_FILEEX_INFO_LEVELS fInfoLevelId, // value that specifies the type of // attribute information to obtain LPVOID lpFileInformation // pointer to buffer to receive // attribute information );
coder_shadow 2017-01-31
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
也许这个文件本来就没有扩展名。
老哥,详细情况是这样的,我的目的是想用我一开始的代码获取鼠标选中的桌面文件完整文件名。正常情况下我现在已经能获取到了,但是当我在系统的资源管理器中设置‘隐藏文件的扩展名’的时候,桌面上的文件不显示扩展名了,而我之前的程序也不能获取到文件的扩展名了。比如源文件是“testFile.zip”,本来我获取到的是“testFile.zip”,设置隐藏扩展名之后桌面显示的是‘testFile’,我获取到的也是‘testFile’,而我想要获取到的是‘testFile.zip’! 再次感谢老哥
coder_shadow 2017-01-18
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
GetFullPathName The GetFullPathName function retrieves the full path and filename of a specified file. DWORD GetFullPathName( LPCTSTR lpFileName, // pointer to name of file to find path for DWORD nBufferLength, // size, in characters, of path buffer LPTSTR lpBuffer, // pointer to path buffer LPTSTR *lpFilePart // pointer to filename in path ); Parameters lpFileName Pointer to a null-terminated string that specifies a valid filename. This string can use either short (the 8.3 form) or long filenames. nBufferLength Specifies the size, in characters, of the buffer for the drive and path. lpBuffer Pointer to a buffer that contains the null-terminated string for the name of the drive and path. lpFilePart Pointer to a variable that receives the address (in lpBuffer) of the final filename component in the path. Return Values If the GetFullPathName function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the lpBuffer buffer is too small, the return value is the size of the buffer, in characters, required to hold the path. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks The GetFullPathName function merges the name of the current drive and directory with the specified filename to determine the full path and filename of the specified file. It also calculates the address of the filename portion of the full path and filename. This function does not verify that the resulting path and filename are valid or that they refer to an existing file on the associated volume. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also File I/O Overview, File Functions, GetShortPathName, GetTempPath, SearchPath
先谢谢老哥, 不过我今天试了一下,我本就没取到文件的扩展名,然后传给这个函数之后,给我返回的只是加了我程序路径的一个路径,并没有得到我想要的文件全名!老哥还有啥绝招不
赵4老师 2017-01-18
  • 打赏
  • 举报
回复
GetFullPathName The GetFullPathName function retrieves the full path and filename of a specified file. DWORD GetFullPathName( LPCTSTR lpFileName, // pointer to name of file to find path for DWORD nBufferLength, // size, in characters, of path buffer LPTSTR lpBuffer, // pointer to path buffer LPTSTR *lpFilePart // pointer to filename in path ); Parameters lpFileName Pointer to a null-terminated string that specifies a valid filename. This string can use either short (the 8.3 form) or long filenames. nBufferLength Specifies the size, in characters, of the buffer for the drive and path. lpBuffer Pointer to a buffer that contains the null-terminated string for the name of the drive and path. lpFilePart Pointer to a variable that receives the address (in lpBuffer) of the final filename component in the path. Return Values If the GetFullPathName function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the lpBuffer buffer is too small, the return value is the size of the buffer, in characters, required to hold the path. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks The GetFullPathName function merges the name of the current drive and directory with the specified filename to determine the full path and filename of the specified file. It also calculates the address of the filename portion of the full path and filename. This function does not verify that the resulting path and filename are valid or that they refer to an existing file on the associated volume. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also File I/O Overview, File Functions, GetShortPathName, GetTempPath, SearchPath
赵4老师 2017-01-18
  • 打赏
  • 举报
回复
也许这个文件本来就没有扩展名。
赵4老师 2017-01-18
  • 打赏
  • 举报
回复
char fullpathname[1024]="d:\\我的带空格 汉字的目录名\\带空格 汉字的文件名";
char cmdstr[2048];
sprintf(cmdstr,"cmd /c dir /b /s \"%s.*\" >d:\\output.txt",fullpathname);
WinExec(cmdstr,SW_HIDE);
//然后读文件d:\output.txt的内容

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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