控制外部窗口在visual studio c# [英] Control external window in visual studio c#

查看:179
本文介绍了控制外部窗口在visual studio c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算在VLC播放器上构建一些外部添加,所以我使用 FindWindow 类型的函数来控制VLC播放器从我的程序。



从您自己的窗口控制外部窗口最好的编程实践是什么?

最佳做法是 FindWindowEx ,或者 FindWindow 更好,或者是有一些开发lib吗?使用 FindWindowEx 的任何提示应该被使用?



[edit]此外,在许多情况下,标题可能会根据不同的语言变化,

so hwnd = FindWindow(null,Calculator)如果标题不是计算器,而是Simulateur [法语]或Rechner[德语]。如何找到窗口,无论操作系统语言是什么?



另一个侧面的问题是有可能将我的应用程序固定在VLC旁边玩家的方式,vlc播放器窗口的任何移动也会移动我的应用程序?我找不到任何适当的功能。

解决方案

你没有描述你打算做的样本,但是.NET自动化可能会帮助您。查看这篇文章。还要注意




好​​了,为了获得找到窗口的可能性,您只能使用FindWindEx函数并依赖于外部窗口的className。 Class是独立于区域设置的。
在我看来,UI自动化分为两类:




  • 基于窗口。这种方法假设您使用FindWindow和SendMessage来处理外部窗口

  • 基于坐标。在这种方法中,您只能使用外部窗口上的控件坐标。所以你要发送消息到具有特定坐标的顶级窗口。



第二种方法更容易,但完全不可靠。它将工作,直到目标应用程序更改控制布局。所以我建议您使用FindWindowEx和SenMessage,无论何处可以应用。



关于使用目标应用程序锚定应用程序。有可能,您有两种方法:

首先,简单的方法是在您的应用程序中创建计时器,并检查目标应用程序的坐标,并相应地移动您的ap窗口,但这种方法似乎是解决方法。
第二个更复杂的方法是创建Hook并将其注入到目标进程中。您可以使用 SetWindowHookEx 设置钩子功能。另请参阅 C#中的鼠标钩子。一个提示给你,以防万一你会写一个钩子,不要在所有进程注入.NET钩子,这可能是管理应用程序中的问题,如果他们为不同的平台版本写作而不是钩子。


[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.

这篇关于控制外部窗口在visual studio c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆