还是不对,应该是这样的:<br><br>procedure TForm1.OpenDialog1FolderChange(Sender: TObject);<br>var<br> Info: TLVFindInfo;<br> hparent,hlist:hwnd;<br> Index: Integer;<br> buf:array[0..256] of char;<br> sFileName:string;<br> item:LV_ITEM;<br>begin<br> hparent:=getparent(OpenDialog1.handle);<br> hlist:=findwindowex(hparent,0,'SHELLDLL_DefView',nil);<br> hlist:=findwindowex(hlist,0,'SysListView32',nil);<br><br> windows.setfocus(hlist); //给他设置焦点<br><br> with Info do<br> begin<br> flags := LVFI_STRING or 0 or LVFI_WRAP;<br> psz := PChar('Project1.exe');<br> end;<br> Index := ListView_FindItem(hlist, -1, Info);<br><br> if index <> -1 then<br> begin<br> ListView_EnsureVisible(Hlist, Index div 5,false); //强制visible<br> ListView_SetItemState(Hlist, Index, LVIS_SELECTED+LVIS_FOCUSED, LVIS_SELECTED+LVIS_FOCUSED);<br> exit;<br> end;<br><br> with Info do<br> begin<br> flags := LVFI_STRING or 0 or LVFI_WRAP;<br> psz := PChar('Project1');<br> end;<br> Index := ListView_FindItem(hlist, -1, Info);<br><br> while index <> -1 do<br> begin<br> item.mask:=LVIF_PARAM ;<br> item.iItem:=index;<br> item.iSubItem:=0;<br> ListView_GetItem(hlist,item);<br> SHGetPathFromIDList(PItemIDList(item.lParam),buf);<br><br> sFileName := ExtractFileName(string(buf));<br> if sFileName = 'Project1.exe' then break;<br><br> sFileName := ChangeFileExt(sFileName,'');<br> if sFilename <> 'Project1' then break;<br><br> index := ListView_GetNextItem(hlist,index,LVNI_ALL);<br> end;<br> ListView_EnsureVisible(Hlist, Index div 5,false); //强制visible<br> ListView_SetItemState(Hlist, Index, LVIS_SELECTED+LVIS_FOCUSED, LVIS_SELECTED+LVIS_FOCUSED);<br>end;<br>