如何通过句柄读取TLISTBOX(的内容-600分,不够再加 ( 积分: 100 )

  • 主题发起人 主题发起人 蓝叶菱
  • 开始时间 开始时间

蓝叶菱

Unregistered / Unconfirmed
GUEST, unregistred user!
原题:<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3859264<br>以下是该控件我的模拟原代码:<br>放置一个TListBox,TMemo1,设置ListBox1的属性为:lbOwnerDrawFixed,<br>原代码如下:<br>unit&nbsp;uMain;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;StdCtrls,&nbsp;ExtCtrls;<br><br>type<br>&nbsp;&nbsp;TFrmMain&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;ListBox1:&nbsp;TListBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;Memo1:&nbsp;TMemo;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;ListBox1DrawItem(Control:&nbsp;TWinControl;&nbsp;Index:&nbsp;Integer;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rect:&nbsp;TRect;&nbsp;State:&nbsp;TOwnerDrawState);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormCreate(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;PList:TStringList;<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;FrmMain:&nbsp;TFrmMain;<br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;TFrmMain.ListBox1DrawItem(Control:&nbsp;TWinControl;&nbsp;Index:&nbsp;Integer;<br>&nbsp;&nbsp;Rect:&nbsp;TRect;&nbsp;State:&nbsp;TOwnerDrawState);<br>var<br>&nbsp;&nbsp;i:integer;<br>begin<br>&nbsp;&nbsp;if&nbsp;Index&nbsp;div&nbsp;2&nbsp;=0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListBox1.Canvas.Font.Color:=clBlue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListBox1.Canvas.TextOut(Rect.Left,Rect.Top,PList.Strings[Index]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListBox1.Canvas.Font.Color:=clgreen;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListBox1.Canvas.TextOut(Rect.Left,Rect.Top,PList.Strings[Index]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>procedure&nbsp;TFrmMain.FormCreate(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;i:integer;<br>begin<br>&nbsp;&nbsp;PList:=TStringList.Create;<br>&nbsp;&nbsp;for&nbsp;i:=0&nbsp;to&nbsp;20&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;ListBox1.Items.Add('');<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;i&nbsp;mod&nbsp;2=0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PList.Add('时间:'+DateToStr(now)+'&nbsp;有消息和信息传输!')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PList.Add('时间:'+DateToStr(now)+'&nbsp;&nbsp;无消息!');<br>&nbsp;&nbsp;&nbsp;&nbsp;Memo1.Lines.Add(PList.Strings);<br>&nbsp;&nbsp;end;<br>end;<br><br>end.
 
procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;S&nbsp;:&nbsp;Array&nbsp;[0..1023]&nbsp;of&nbsp;char;<br>begin<br>&nbsp;&nbsp;ZeroMemory(@S,SizeOf(S));<br>&nbsp;&nbsp;SendMessage(THandle(StrToInt(Self.Edit1.Text)),LB_GetText,0,Integer(@S[0]));<br>&nbsp;&nbsp;ShowMessage(S);<br>end;<br><br>这个代码可以查到标准的ListBox的内容<br><br>他的实现过程是<br>procedure&nbsp;TCustomListBox.LBGetText(var&nbsp;Message:&nbsp;TMessage);<br>var<br>&nbsp;&nbsp;S:&nbsp;string;<br>begin<br>&nbsp;&nbsp;if&nbsp;Style&nbsp;in&nbsp;[lbVirtual,&nbsp;lbVirtualOwnerDraw]&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;Assigned(FOnData)&nbsp;and&nbsp;(Message.WParam&nbsp;&gt;&nbsp;-1)&nbsp;and&nbsp;(Message.WParam&nbsp;&lt;&nbsp;Count)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S&nbsp;:=&nbsp;'';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OnData(Self,&nbsp;Message.wParam,&nbsp;S);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StrCopy(PChar(Message.lParam),&nbsp;PChar(S));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message.Result&nbsp;:=&nbsp;Length(S);<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message.Result&nbsp;:=&nbsp;LB_ERR;<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;inherited;<br>end;<br><br>因为这个是从ListBox自己存储文本的StringList来读取的<br><br>你上面的代码是在别的地方来存储这些文本,然后在自己画上去的.<br>还有另外已经方法可以实现这个情况.<br>过滤重写LB_GetText的处理过程,过滤掉返回文本的执行过程就可以了.<br><br>从消息这条路上恐怕是难走的通了,不妨从内存读取上找突破点
 
后退
顶部