procedure TForm1.Button1Click(Sender: TObject);<br>var<br> Hwnd: THandle;<br> S: string;<br> Count, i: Integer;<br>begin<br> //假设另一个程序的窗口的类名是TForm1,ListBox的类名是TListBox,注意这里要做修改<br> Hwnd := FindWindowEx(FindWindow('TForm1',nil),0,'TListBox',nil);<br> if Hwnd = 0 then ShowMessage('not found!');<br><br> Count := SendMessage(Hwnd, LB_GETCOUNT, 0, 0);<br> for i := 0 to Count - 1 do SendMessage(Hwnd, LB_SETCURSEL, i, 0);<br>end;