ListView的API(100分)

  • 主题发起人 主题发起人 shabi
  • 开始时间 开始时间
S

shabi

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么有的listView的API管用,有的不管用,是不是我的API参数写法不对,大家帮我看看<br>不管用的:<br>&nbsp; itemNo:= ListView_FindItem(hand,-1,itemInfo);<br>这句话返回的值始终是0,不知道为什么,高手指点.<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,CommCtrl,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TMyShape=(Circle,Heart,screwCurve,normal);<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; cbShape: TComboBox;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>function GetDesktopHand: THandle;<br>var Htemp:THandle;<br>begin<br>&nbsp; Result:=FindWindow('progman',nil);<br>&nbsp; Result:=GetWindow(Result,GW_Child);<br>&nbsp; Result:=GetWindow(Result,GW_Child);<br>end;<br><br>procedure DrawPic(r: integer);<br>var<br>&nbsp; i,j,itemNo, Count, CenterX, CenterY, TempR :integer;<br>&nbsp; Hand: THandle;<br>&nbsp; Radian: double;<br>&nbsp; TempRect: TRect;<br>&nbsp; DesktopHeight,DesktopWidth :integer;<br>&nbsp; X, Y,k : Word;<br>&nbsp; ItemInfo:LV_FINDINFO;<br>&nbsp; mylv:Lv_Item;<br>&nbsp; P:TPoint;<br>begin<br>&nbsp; Hand:=GetDesktopHand;<br>&nbsp; SystemParametersInfo(SPI_GetWorkArea,0,@TempRect,0);<br>&nbsp; DesktopWidth:=TempRect.Right - TempRect.Left;<br>&nbsp; DesktopHeight:= TempRect.Bottom - TempRect.Top;<br>&nbsp; CenterX:=DesktopWidth div 2;<br>&nbsp; CenterY:=DesktopHeight div 2;<br>&nbsp; if CenterX&gt;CenterY then<br>&nbsp; &nbsp; TempR:=CenterY-20<br>&nbsp; else<br>&nbsp; &nbsp; TempR:=CenterX;<br>&nbsp; if r&gt;TempR then r:=TempR;<br>&nbsp; Count:=Listview_GetItemCount(Hand);<br>&nbsp; Radian:=2*3.14159/Count;<br>&nbsp; k:=Trunc(r*0.5);<br>&nbsp; with itemInfo do<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;flags:=LVFI_PARTIAL;<br>&nbsp; &nbsp; &nbsp;psz:=pchar('server');<br>&nbsp; end;<br>&nbsp; itemNo:= ListView_FindItem(hand,-1,itemInfo);<br>&nbsp; SendMessage(Hand,LVM_SetItemPosition,ItemNo,MakeLparam(900, 10));<br>&nbsp; i:=-1;<br>&nbsp; for j:=0 to Count-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; i:=i+1;<br>&nbsp; &nbsp; Case TMyShape(form1.cbShape.ItemIndex) of<br>&nbsp; &nbsp; &nbsp; Circle:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;X:=Integer(CenterX+Trunc(r*Sin(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Y:=Integer(CenterY+Trunc(r*Cos(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; Heart:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;X:=Integer(CenterX+Trunc(r*(1-sin(i*Radian))*Cos(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=100-Integer(Trunc(r*(1-sin(i*Radian))*Sin(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; screwCurve:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x:=Integer(Trunc(r*radian*i-k*sin(i*radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=Integer(Centery+Trunc(r-k*cos(i*radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; NorMal:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x:=(i div 9)*80+20;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=(i mod 9)*80+20;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; SendMessage(Hand,LVM_SetItemPosition,i,MakeLparam(X, y));<br><br>&nbsp; end;<br>&nbsp; &nbsp;// &nbsp;sendMessage(Hand,LVM_ARRANGE,LVA_ALIGNTOP,0);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var r:integer;<br>begin<br>&nbsp; if edit1.text='' then r:=250<br>&nbsp; else r:=strToInt(edit1.text);<br>&nbsp; DrawPic(r);<br>end;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var i:TMyShape;<br>begin<br>&nbsp; &nbsp;cbShape.ItemIndex:=0;<br>end;<br><br>end.<br><br>
 
with itemInfo do<br>&nbsp;begin<br>&nbsp; &nbsp; flags:=LVFI_STRING;<br>&nbsp; &nbsp; psz:='server';<br>&nbsp;end;<br>&nbsp;itemNo:= ListView_FindItem(hand,-1,itemInfo);<br><br>这样试试<br>
 
试过了仁兄,如果一样撒
 
晕,今天试试全乱了,psZ的内容设不设好象没有影响,itemno的值不是0但也不是我要打的,乱了,晕
 
好象 text 不是指的他的名称,text返回的值好象全是空。
 
dfm贴上 我试试去
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,CommCtrl,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TMyShape=(Circle,Heart,screwCurve,normal);<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; cbShape: TComboBox;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>function GetDesktopHand: THandle;<br>begin<br>&nbsp; Result:=FindWindow('progman',nil);<br>&nbsp; Result:=GetWindow(Result,GW_Child);<br>&nbsp; Result:=GetWindow(Result,GW_Child);<br>end;<br><br>procedure DrawPic(r: integer);<br>var<br>&nbsp; i,j,itemNo, Count, CenterX, CenterY, TempR :integer;<br>&nbsp; Hand: THandle;<br>&nbsp; Radian: double;<br>&nbsp; TempRect: TRect;<br>&nbsp; DesktopHeight,DesktopWidth :integer;<br>&nbsp; X, Y,k : Word;<br>&nbsp; ItemInfo:LV_FINDINFO;<br>&nbsp; buffer:array[0..100] of char;<br>&nbsp; mylv:Lv_Item;<br>&nbsp; pitem:^lv_Item;<br>begin<br>&nbsp; Hand:=GetDesktopHand;<br>&nbsp; SystemParametersInfo(SPI_GetWorkArea,0,@TempRect,0);<br>&nbsp; DesktopWidth:=TempRect.Right - TempRect.Left;<br>&nbsp; DesktopHeight:= TempRect.Bottom - TempRect.Top;<br>&nbsp; CenterX:=DesktopWidth div 2;<br>&nbsp; CenterY:=DesktopHeight div 2;<br>&nbsp; if CenterX&gt;CenterY then<br>&nbsp; &nbsp; TempR:=CenterY-20<br>&nbsp; else<br>&nbsp; &nbsp; TempR:=CenterX;<br>&nbsp; if r&gt;TempR then r:=TempR;<br>&nbsp; Count:=Listview_GetItemCount(Hand);<br>&nbsp; Radian:=2*3.14159/(Count-1);<br>&nbsp; k:=Trunc(r*0.5);<br>&nbsp; with itemInfo do<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;flags:=LVFI_partial;<br>&nbsp; &nbsp; &nbsp;psz:=pchar('Inter');<br>&nbsp; end;<br>&nbsp; itemNo:= ListView_FindItem(hand,-1,itemInfo);<br>&nbsp; showmessage(IntTostr(itemNo));<br>&nbsp;// ItemNo:=SendMessage(hand,lvm_findItem,-1,lparam(@itemInfo));<br>&nbsp; SendMessage(Hand,LVM_SetItemPosition,ItemNo,MakeLparam(900, 10));<br>&nbsp;// Showmessage('a');<br>&nbsp; i:=-1;<br>&nbsp; for j:=0 to Count-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if j=itemNo then continue;<br>&nbsp; &nbsp; i:=i+1;<br>&nbsp; &nbsp; Case TMyShape(form1.cbShape.ItemIndex) of<br>&nbsp; &nbsp; &nbsp; Circle:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;X:=Integer(CenterX+Trunc(r*Sin(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Y:=Integer(CenterY+Trunc(r*Cos(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; Heart:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;X:=Integer(CenterX+Trunc(r*(1-sin(i*Radian))*Cos(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=100-Integer(Trunc(r*(1-sin(i*Radian))*Sin(i*Radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; screwCurve:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x:=Integer(Trunc(r*radian*i-k*sin(i*radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=Integer(Centery+Trunc(r-k*cos(i*radian)));<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; NorMal:<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x:=(i div 9)*80+20;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=(i mod 9)*80+20;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; SendMessage(Hand,LVM_SetItemPosition,j,MakeLparam(X, y));<br><br>&nbsp; end;<br>&nbsp;{ with mylv do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;mask:=LVIF_TEXT;<br>&nbsp; &nbsp; &nbsp;iitem:=3;<br>&nbsp; &nbsp; &nbsp;isubitem:=0;<br>&nbsp; &nbsp; &nbsp;fillchar(buffer,sizeof(buffer),$ffff);<br>&nbsp; &nbsp; &nbsp;psztext:=buffer;<br>&nbsp; &nbsp; &nbsp;cchTextMax:=sizeOf(buffer);<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;pitem:=@mylv;<br>&nbsp; &nbsp;ListView_GetItem(hand,mylv); &nbsp; &nbsp;}<br>&nbsp; &nbsp;ListView_SetTextColor(hand,clred);<br>&nbsp; &nbsp;ListView_SetTextBkColor(hand,clLime);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var r:integer;<br>begin<br>&nbsp; if edit1.text='' then r:=250<br>&nbsp; else r:=strToInt(edit1.text);<br>&nbsp; DrawPic(r);<br>end;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;cbShape.ItemIndex:=0;<br>end;<br><br><br>end.
 
object Form1: TForm1<br>&nbsp; Left = 480<br>&nbsp; Top = 328<br>&nbsp; BorderIcons = [biSystemMenu]<br>&nbsp; BorderStyle = bsSingle<br>&nbsp; Caption = '桌面图标排放'<br>&nbsp; ClientHeight = 272<br>&nbsp; ClientWidth = 157<br>&nbsp; Color = clBtnFace<br>&nbsp; Font.Charset = GB2312_CHARSET<br>&nbsp; Font.Color = clWindowText<br>&nbsp; Font.Height = -12<br>&nbsp; Font.Name = '宋体'<br>&nbsp; Font.Style = []<br>&nbsp; OldCreateOrder = False<br>&nbsp; OnCreate = FormCreate<br>&nbsp; PixelsPerInch = 96<br>&nbsp; TextHeight = 12<br>&nbsp; object Label1: TLabel<br>&nbsp; &nbsp; Left = 24<br>&nbsp; &nbsp; Top = 40<br>&nbsp; &nbsp; Width = 24<br>&nbsp; &nbsp; Height = 12<br>&nbsp; &nbsp; Caption = '半径'<br>&nbsp; end<br>&nbsp; object Button1: TButton<br>&nbsp; &nbsp; Left = 40<br>&nbsp; &nbsp; Top = 144<br>&nbsp; &nbsp; Width = 75<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = '确定'<br>&nbsp; &nbsp; TabOrder = 0<br>&nbsp; &nbsp; OnClick = Button1Click<br>&nbsp; end<br>&nbsp; object cbShape: TComboBox<br>&nbsp; &nbsp; Left = 24<br>&nbsp; &nbsp; Top = 8<br>&nbsp; &nbsp; Width = 113<br>&nbsp; &nbsp; Height = 20<br>&nbsp; &nbsp; ItemHeight = 12<br>&nbsp; &nbsp; TabOrder = 1<br>&nbsp; &nbsp; Text = 'cbShape'<br>&nbsp; &nbsp; Items.Strings = (<br>&nbsp; &nbsp; &nbsp; 'Circle'<br>&nbsp; &nbsp; &nbsp; 'heart'<br>&nbsp; &nbsp; &nbsp; 'screwCurve'<br>&nbsp; &nbsp; &nbsp; 'Normal')<br>&nbsp; end<br>&nbsp; object Edit1: TEdit<br>&nbsp; &nbsp; Left = 24<br>&nbsp; &nbsp; Top = 64<br>&nbsp; &nbsp; Width = 113<br>&nbsp; &nbsp; Height = 20<br>&nbsp; &nbsp; TabOrder = 2<br>&nbsp; &nbsp; Text = '250'<br>&nbsp; end<br>end
 
itemNo:= ListView_FindItem(hand,-1,itemInfo);<br>这句话返回的值始终是0,<br>&nbsp;itemNo:= ListView_FindItem(listview1.hand,-1,itemInfo);<br><br>感觉上, 你对ListView的操作的Handle是从这个函数获得的,<br>======================================================<br>function GetDesktopHand: THandle;<br>begin<br>&nbsp; Result:=FindWindow('progman',nil);<br>&nbsp; Result:=GetWindow(Result,GW_Child);<br>&nbsp; Result:=GetWindow(Result,GW_Child);<br>end;<br>=====================================================<br>它是不是一个ListView的Handle ?
 
有的API函数也用这个句柄,要不行都应该不行啊!
 
你的程序在我电脑上运行正常。
 
图标排列正常。
 
在我的电脑上运行也正常呀<br>修改了一下不会闪动的效果:<br>procedure DrawPic(r: integer);<br>var<br>&nbsp; i,j,itemNo, Count, CenterX, CenterY, TempR :integer;<br>&nbsp; Hand: THandle;<br>&nbsp; Radian: double;<br>&nbsp; TempRect: TRect;<br>&nbsp; DesktopHeight,DesktopWidth :integer;<br>&nbsp; X, Y,k : Word;<br>&nbsp; ItemInfo:LV_FINDINFO;<br>&nbsp; buffer:array[0..100] of char;<br>&nbsp; mylv:Lv_Item;<br>&nbsp; pitem:^lv_Item;<br>begin<br>&nbsp; Hand:=GetDesktopHand;<br>&nbsp; SendMessage(Hand, WM_SETREDRAW, 0, 0);<br>&nbsp; try<br>&nbsp; ...<br>&nbsp; finally<br>&nbsp; &nbsp; SendMessage(Hand, WM_SETREDRAW, 1, 0); <br>&nbsp; end;<br>end;
 
正常是正常,不过我想找到其中一个图标的 index ,比如"我的电脑“的, 用finditem 不行啊,再帮我看看
 
ListView的API必须在同一进程。(否则你传过去的指针无效)
 
请楼主看清楚:<br>with itemInfo do<br>&nbsp;begin<br>&nbsp; &nbsp; flags:=LVFI_STRING;<br>&nbsp; &nbsp; psz:='server';<br>&nbsp;end;<br>不同于<br>&nbsp;with itemInfo do<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;flags:=LVFI_PARTIAL;<br>&nbsp; &nbsp; &nbsp;psz:=pchar('server');<br>&nbsp; end;<br><br>
 
另外:<br>请确认是listview的handle。<br>测试此api没问题。
 
后退
顶部