Clicking another application's button

- Enumwindows - handle
of a listbox/combobox

unit Ustart;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Image1: TImage;
    procedure Timer1Timer(Sender: TObject);
  private
    {Private declarations }
  public
    {Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function ClickerLeBouton(Element: HWND; Param: LPARAM): Bool; stdcall;
var
 Texte: PChar;
begin
 GetMem(Texte, Succ(GetWindowTextLength(Element)));
  GetWindowText(Element, Texte, Succ(GetWindowTextLength(Element)));
 if Texte='OK' then
  begin
  PostMessage(Element, BM_CLICK, 0, 0);
    Result:=False;
  end
  else
   Result:=True;
  FreeMem(Texte);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
 Programme: HWND;
begin
 Programme:=FindWindow(nil, 'WNetGetUser returned');
  if Programme>0 then
  begin
   EnumChildWindows(Programme, @ClickerLeBouton, 0);
    Close;
  end;
end;

end.

    Based on that experience, I thought I could help with finding the
handle
of list\combo boxes but, as I found out while struggling with my problem,
some Windows functions have strange return values.
    Listboxes and comboboxes are predefined Windows classes and have their
own messages and functions. You'd think that a LB_GETCOUNT or a CB_GETTEXT
would return LB_ERR or CB_ERR if applied to the wrong class but it's not
the
case (thank you, Microsoft).
    However, here's a far less than perfect suggestion: GetWindowClass can
be of some help if applied within an EnumChildProc. As I've tested it, most
commercial applications use the predefined controls (even Netscape). The
only exceptions I've found so far are applications made in Delphi and my
Ulead MediaStudio (and, frankly, I cant understand why). However, even
Ulead
names them "UL_ListBox" and "UL_ComboBox", so searching the substrings
would
work. One other appreciable matter is that, if I understood the help files
correctly, class names are not case sensitive.
    If you do find a more reliable method, please share it with us.