1
Answer

How do I identify windows with same class in spy++

Stanko Klipic

Stanko Klipic

7y
342
1
 I have WM_SETTEXT and when i try to identify Edit window i have to many parent windows with the same class for example i determine FindWindow and getting some value and after same but on third window value is 0
 
this is my code
 
 
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;   namespace WindowsFormsApplication1 {     public partial class Form1 : Form     {         private const int WM_SETTEXT = 0x000C;         [DllImport("user32.dll")]         private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);           [DllImport("User32.dll")]         private static extern IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,string lpszClass,string lpszWindows);         [DllImport("User32.dll")]         private static extern Int32 SendMessage(IntPtr edithWnd, int Msg, IntPtr wParam, StringBuilder lParam);           public Form1()         {             InitializeComponent();         }           private void Form1_Load(object sender, EventArgs e)         {             IntPtr hWnd = FindWindow("WindowsForms10.Window.8.app.0.23f19a8_r14_ad1", "some software");              if (!hWnd.Equals(IntPtr.Zero)) ;              IntPtr edit = FindWindowEx(hWnd, IntPtr.Zero, "WindowsForms10.SysTabControl32.app.0.23f19a8_r14_ad1", null);             IntPtr pod = FindWindowEx(edit, IntPtr.Zero, null, "Stores");            IntPtr H1 = FindWindowEx(pod, IntPtr.Zero, "WindowsForms10.Window.8.app.0.23f19a8_r14_ad1", null);          IntPtr H2 = FindWindowEx(H1, IntPtr.Zero, "WindowsForms10.Window.8.app.0.23f19a8_r14_ad1", null);          IntPtr H3 = FindWindowEx(H2, IntPtr.Zero, "WindowsForms10.Window.8.app.0.23f19a8_r14_ad1", null);           IntPtr H4 = FindWindowEx(H3, IntPtr.Zero, "WindowsForms10.Window.8.app.0.23f19a8_r14_ad1", null);         IntPtr H5 = FindWindowEx(H4, IntPtr.Zero, "WindowsForms10.Window.8.app.0.23f19a8_r14_ad1", null);        IntPtr H6 = FindWindowEx(H5, IntPtr.Zero, "WindowsForms10.COMBOBOX.app.0.23f19a8_r14_ad1", null);       IntPtr edithWnd = FindWindowEx(H6, IntPtr.Zero, "Edit", null);          if (!edithWnd.Equals(IntPtr.Zero))         SendMessage(edithWnd, WM_SETTEXT, IntPtr.Zero, new StringBuilder("hey"));           }                              }              }     
 i am getting some value from FindWindow and 3 line of FindWindowEx after that it is 0
and when I call
Marshal.GetLastWin32Error();
I am getting error 6 what is
ERROR_INVALID_HANDLE
6 (0x6)
The handle is invalid.
and when i set  
Marshal.GetLastWin32Error();
code was 1400
any suggestions?
 
 
Answers (1)