0

I'm developing a piece of software to inset some text in a rich edit of another program the code goes like this:

atlfe = FindWindowEx(wtlsplitterwindow, 0, "atl:0087d7a8" , null);

This is only one line: this works fine, problem is with every release of the program number atl:0087d7a8 changes so i have to use spy++ to get the new one and change it in the code.

The question is, is there is any way I can get that number from code?

By the way I'm using C#, VS2010.

Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126
Stacker
  • 8,157
  • 18
  • 73
  • 135
  • 1
    @Ondrej Slinták i wonder how it was helpful to delete the "thanks" at the end of the my question lol – Stacker Mar 21 '11 at 16:05

4 Answers4

1

I suggest you use UI Automation instead of raw Windows API. You should start with the UI Spy tool to determine the UI hierarchy of your app, it will be more resilient to change.

See some articles on this subject on SO:

Retrieve current URL from C# windows forms application

How to get the word under the cursor in Windows?

Community
  • 1
  • 1
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • but that means any one who wants to use the software has to have the windows sdk installed right ? – Stacker Mar 20 '11 at 09:35
  • @Stacker - no. UI automation runtime is installed on Windows Vista and 7. Only XP/2003 clients requires a redist setup (http://support.microsoft.com/kb/971513/en-us) – Simon Mourier Mar 20 '11 at 17:25
0

Been a while since I messed with some of these windows API's. I think this may be of value though.

http://msdn.microsoft.com/en-us/magazine/cc163617.aspx

user623879
  • 4,066
  • 9
  • 38
  • 53
0

If the Title is always the same, use it instead of class name

atlfe = FindWindowEx(wtlsplitterwindow, 0, null, "Title");

More info on MSDN.

kyrylomyr
  • 12,192
  • 8
  • 52
  • 79
0

Clearly if the sub-window has not title and its classname is different every time you have but one method remaining.

You are first going to have to find the top level window of this app using either EnumWindows or FindWindowEx, the latter if you can identify it by class name and/or window title.

Once you have the top level window you can walk through the children to locate the sub-window that you are looking for. Presumably you already know the relationships between the top level window and the sub-window you are targetting. In any case Spy++ can tell you this.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • i guess that what i did , i used a software to generate code to traverse through the windows but in a certain level it still use a non static numbr to get to the window i need , i was waiting for someone to come up with a better solution , i dont mind having a curser which i can drag and drop on the window i need once if that is what it takes – Stacker Mar 20 '11 at 15:05
  • It's trivial to do what you need with EnumWindows and then EnumChildWindows to find the particular child window. If you don't know the title and the classname varies then you have no other option. – David Heffernan Mar 20 '11 at 15:06