N
netwinds
Unregistered / Unconfirmed
GUEST, unregistred user!
function str_GetFileList(lngWnd : Hwnd):String;<br>var<br> intNewWnd : Hwnd;<br> g_wnd : Hwnd;<br> intP : Integer;<br> intIndex : Integer;<br> objItem : LV_ITEM;<br> strBuf : Array[0..255] of Char;<br> strFileName : String;<br> intHwnd : Hwnd;<br>begin<br> g_wnd := lngWnd;<br> intNewWnd := 0;<br> strFileName := '';<br> while g_wnd <> 0 do begin<br> intNewWnd := g_wnd;<br> g_wnd := GetParent(g_wnd);<br> end;<br> g_wnd := FindWindowEx(intNewWnd, 0, 'SHELLDLL_DefView', nil);<br> if g_wnd = 0 then begin<br> Result := '';<br> exit;<br> end;<br> intHwnd := g_wnd;<br> g_wnd := FindWindowEx(g_wnd, 0, 'Internet Explorer_Server', nil);<br> if g_wnd = 0 then begin<br> g_wnd := FindWindowEx(intHwnd, 0, 'DUIViewWndClassName', nil);<br> g_wnd := FindWindowEx(g_wnd, 0, 'DirectUIHWND', nil);<br> g_wnd := FindWindowEx(g_wnd, 0, 'CtrlNotifySink', nil);<br> g_wnd := FindWindowEx(g_wnd, 0, 'SysListView32', nil);<br> end<br> else begin<br> g_wnd := FindWindowEx(g_wnd, 0, 'ATL Shell Embedding', nil);<br> g_wnd := FindWindowEx(g_wnd, 0, 'SysListView32', nil);<br> end;<br> if g_wnd = 0 then begin<br> Result := '';<br> exit;<br> end;<br><br> intP := -1;<br> for intIndex := 0 to ListView_GetSelectedCount(g_wnd) do begin<br> intP := ListView_GetNextItem(g_wnd,intP,LVNI_SELECTED);<br> if intP <> -1 then begin<br> objItem.mask := LVIF_PARAM;<br> objItem.iItem := intP;<br> objItem.iSubItem := 0;<br> ListView_GetItem(g_wnd,objItem);<br> SHGetPathFromIDList(PItemIDList(objItem.lParam),strBuf);<br> //多个文件之间用 | 隔开,每个文件用双外号引起来是为了避免 Program Files 之类中间有空格的情况<br> strFileName := strFileName + '"' + StrPas(strBuf) + '"|';<br> end;<br> end;<br> Result := strFileName;<br>end;<br><br>如何取得当前选中的文件的路径,上面的方法取得的无论在什么目录下,都是 C:/Documents and Settings/..../桌面/文件名 <br><br>比如我当前的窗体是在 E:/Other 下,然后选择一个 a.txt ,但这边显示出来的则是 C:/Documents and Settings/Administrator/桌面/a.txt <br><br>请教高手!!!!!!!!!!