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);
使用上面代碼獲取滑鼠選中單個桌面檔案名,但是在檔案擴展名隱藏的時候不能獲取到檔案擴展名,有沒有高手能幫我看看。
多謝多謝!
uj5u.com熱心網友回復:
GetFullPathNameThe 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
uj5u.com熱心網友回復:
先謝謝老哥,
不過我今天試了一下,我本就沒取到檔案的擴展名,然后傳給這個函式之后,給我回傳的只是加了我程式路徑的一個路徑,并沒有得到我想要的檔案全名!老哥還有啥絕招不
uj5u.com熱心網友回復:
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的內容
uj5u.com熱心網友回復:
也許這個檔案本來就沒有擴展名。uj5u.com熱心網友回復:
老哥,詳細情況是這樣的,我的目的是想用我一開始的代碼獲取滑鼠選中的桌面檔案的完整檔案名。正常情況下我現在已經能獲取到了,但是當我在系統的資源管理器中設定‘隱藏檔案的擴展名’的時候,桌面上的檔案不顯示擴展名了,而我之前的程式也不能獲取到檔案的擴展名了。比如源檔案是“testFile.zip”,本來我獲取到的是“testFile.zip”,設定隱藏擴展名之后桌面顯示的是‘testFile’,我獲取到的也是‘testFile’,而我想要獲取到的是‘testFile.zip’!
再次感謝老哥
uj5u.com熱心網友回復:
試試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
);
uj5u.com熱心網友回復:
http://blog.csdn.net/tpnndhqc/article/details/41402297轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/111007.html
標籤:進程/線程/DLL
