Loading ...
Sorry, an error occurred while loading the content.

Finding controls on a form - easily.

Expand Messages
  • Alex Morozov
    Hi all. Just want to share my experience in finding controls on forms. Usually it`s a boring task, especially when controls has no titles. You have to
    Message 1 of 1 , Feb 1, 2006
    • 0 Attachment
      Hi all.

      Just want to share my "experience" in finding controls on forms. Usually
      it`s a boring task, especially when controls has no titles. You have to
      inspect a form, get control`s class ID (TComboBox, f.e.), call
      FindWindowLike and guess control`s index in array, returned by that
      function. Grrr. Before sticking with GuiTest, I`ve used AutoIt, which
      have excellent (IMHO) thing: every control on a form has not only class
      ID, but class ID + control`s index on a form (which stays constant
      between program restarts). So, using AU3Info.exe from AutoIt and simple
      function like that below, you can easily find controls within your
      script. Just look up ClassnameNN, using AU3Info, and then call
      FindWindowNN ($parent, undef, 'TComboBox1');. Voila.

      However, there will be problems if class has digits in it`s name. Though
      I haven`t faced such classes.

      Here`s the sub. It returns control HWND.

      sub FindWindowNN {
      my ($parent, $title, $class) = @_;
      $class =~ /([a-zA-Z]+)(\d+)/;
      my @win = FindWindowLike ($parent, $title, $1);
      $win[$2-1]||undef;
      }

      PS: Please, correct me, if there is more easy way to do the job.
      PPS: Sorry for my English. Hope you`ll understand my post ).
    Your message has been successfully submitted and would be delivered to recipients shortly.