title: How can I retrieve the values from window of class "ThunderRT6ListBox" using user32.dll in c#
body: <p>I am trying to retrieve information from extern desktop aplication in Windows.</p>
  
  <p>I know how extract the text from Textboxes (class "Edit") but I don't know how extract the values from controls with class name "ThunderRT6ListBox" and "ThunderRT6ComboBox". How can I do that?</p>
  
  <p>I have this code to extract the text from the textbox:</p>
  
  <pre><code>public static class ModApi
  {
      [DllImport("user32.dll", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
      public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  
      [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
      public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
  
      [DllImport("user32.dll", EntryPoint = "SendMessageTimeout", SetLastError = true, CharSet = CharSet.Auto)]
      public static extern uint SendMessageTimeoutText(IntPtr hWnd, int Msg, int countOfChars, StringBuilder text, uint flags, uint uTImeoutj, uint result);
  
      [DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
      static internal extern bool EnumChildWindows(IntPtr hWndParent, funcCallBackChild funcCallBack, IntPtr lParam);
  
      [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
      static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
      const int LB_GETCOUNT = 0x018B;
      const int LB_GETTEXT = 0x0189;
  
      public static string GetText(IntPtr hwnd)
      {
          var text = new StringBuilder(1024);
          if (SendMessageTimeoutText(hwnd, 0xd, 1024, text, 0x2, 1000, 0) != 0)
          {
              return text.ToString();
          }
  
          return "";
      }        
  }
  
  
  public foo()
  {
       IntPtr value = new IntPtr(0x019C086A); //ID locate using Spy++
       String caption = ModApi.GetText(value);
  }
  </code></pre>
  
  <p>UPDATE 1:</p>
  
  <p>The way to read from ListBox:</p>
  
  <pre><code>    public static List&lt;string&gt; GetListBoxContents(IntPtr listBoxHwnd)
      {
          int cnt = (int)SendMessage(listBoxHwnd, LB_GETCOUNT, IntPtr.Zero, null);
          List&lt;string&gt; listBoxContent = new List&lt;string&gt;();
          for (int i = 0; i &lt; cnt; i++)
          {
              StringBuilder sb = new StringBuilder(256);
              IntPtr getText = SendMessage(listBoxHwnd, LB_GETTEXT, (IntPtr)i, sb);
              listBoxContent.Add(sb.ToString());
          }
          return listBoxContent;
      }
  </code></pre>
  
  <p>UPDATE 2:</p>
  
  <p>The way to read from ComboBox:</p>
  
  <pre><code>    public static List&lt;string&gt; GetComboBoxContents(IntPtr cbBoxHwnd)
      {
          int cnt = (int)SendMessage(cbBoxHwnd, CB_GETCOUNT, IntPtr.Zero, null);
          List&lt;string&gt; listBoxContent = new List&lt;string&gt;();
          for (int i = 0; i &lt; cnt; i++)
          {
              //int txtLength = SendMessage(cbBoxHwnd, CB_GETLBTEXTLEN, i, 0); 
              StringBuilder sb = new StringBuilder(256);
              IntPtr getText = SendMessage(cbBoxHwnd, CB_GETLBTEXT, (IntPtr)i, sb);
              listBoxContent.Add(sb.ToString());
          }
          return listBoxContent;
      }
  </code></pre>