[edit] I intend to build some external add on to VLC player, so for that I'm using the FindWindow
type of functions in order to control the VLC player from my program.
What's the best programming practice to control external window from your own window?
Is the FindWindowEx
the best practice, or FindWindow
better for that, or is there some developed lib for it? Any tips for using FindWindowEx
like it should be used?
[edit] Also, in many cases the titles may vary along different languages,
so hwnd = FindWindow(null, "Calculator")
may not work if the title is not "Calculator" but "Simulateur" [French] or "Rechner" [German]. How can I make sure it finds the window, no matter what is the OS language?
And another side question - is there any possibility to anchor my application next to the VLC player, in way that any movement of the vlc player window will also move my application? I couldn't find any appropriate function for that.
You didnt describe a sample of that you are intended to do, but .NET automation may help you. Check out this article. Also pay attention to this
[EDIT] Well, To obtain possibility of find window to be independed of title value you should use only FindWindEx function and rely to className of external window. Class is locale independent. UI automation in my opinion devided into two classes:
- window based. This approach suppose that you are use FindWindow and SendMessage to manipulation of external windows
- coordinate based. In this approach you use only coordinates of controls on external window. So you are sending messages to top level window with specific coordinates.
Second approach is more easy but completly unreliable. It will work until target application change control layout. So I will suggest you to use FindWindowEx and SenMessage wherever it can be applyed.
About anchoring your application with target app. Yes it possible, and you have two ways to do that:
first and easy way is to create timer inside your app and check coordinates of target app and move your's ap window accordingly, but such approach seems to be workaround. Second and more complex way is to create Hook and inject it in target process. You can set hook with SetWindowHookEx function. Also read about mouse hook in C#. And one tip for you in case you will write a hook, dont inject .NET hook in all processes, this may course problems in managed apps if they writen for different platform versions rather your hook.