1

I have a program that displays information(simple text, but not in a txt box, looks like labels in .NET) but has disabled selection and disabled left and right mouse click.

I want to write another program(lets say in C#, but it can be other language also) that acts as a user and writes down the info displayed by the first program in a txt file.

Is there a way that i can get around disabled selection, left and right mouse click?

deloki
  • 1,729
  • 2
  • 18
  • 26

1 Answers1

2

GetWindowText windows API is your friend:

[DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);

you would have to get the handle of the other program's window then loop on all child windows/controls using EnumChildWindows then get the text calling GetWindowText against all those handles. In some cases you would not get a result as expected I guess or could be that some controls have no handle exposed.

[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);

for details and answers on how to use EnumChildWindows see here:

Why is EnumChildWindows skipping children?

have also a look here for some ideas and examples... Why does GetWindowText hang with a "closed" handle but not with a random one

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147