在Visual Studio C#控制对外窗口 [英] Control external window in visual studio c#

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

问题描述

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

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

什么是最好的编程习惯从自己的窗口控制对外窗口?
结果是在 FindWindowEx 最好的做法,或 FindWindow函数更好的为,或者是有一些开发了它的lib?使用任何提示 FindWindowEx 像它应该使用吗?

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?

此外,在许多情况下,标题可能会沿着不同的语言,结果
不同,所以 HWND = FindWindow函数(空,计算器)未必如果标题不是计算器,而是Simulateur工作[法国]或雷希纳[德]。我怎样才能确保它找到的窗口,不管是什么操作系统的语言

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

和另一面的问题 - 是否有可能以一个锚我的应用程序的VLC播放器,在这样的VLC播放器窗口的任何移动也将移动应用程序?我找不到任何合适的函数。

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.

推荐答案

你没有描述你是打算做一个样本,但.NET自动化可以帮助你。请查看这个文章。另外要注意

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


哦,为了获得查找窗口中independed标题值,你应该只使用FindWindEx功能,并依靠外部窗口类名的可能性。类是语言环境无关。在我看来,
UI自动化分为两类:

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:


  • 基于窗口。这种方法假设你是使用FindWindow函数和SendMessage函数外窗的操纵

  • 基于坐标。在这种方法中使用的对外窗口仅控制坐标。所以,你将消息发送到特定坐标顶层窗口。

第二个方法是更容易,但完全地不可靠的。它将会一直工作到目标应用程序的变更控制布局。所以我会建议你使用FindWindowEx和SenMessage无论它可以applyed。

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.

关于与目标应用锚您的应用程序。是的,它有可能,你有两种方法可以做到这一点:结果
第一,简单的方法是将您的应用程序内创建相应的计时器和检查目标应用程序的坐标和移动你的AP窗口,但这样的方法似乎是解决方法。
第二和更复杂的方法是创建挂钩,并在目标进程注入它。您可以设置钩 SetWindowHookEx 功能。还阅读有关C# 鼠标钩子。和一个提示你的情况下,你会写一个钩子,不要在所有进程注入.NET挂钩,这可能会在管理应用过程中的问题,如果他们writen针对不同平台的版本,而你的钩子。

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天全站免登陆