使用 C# 将应用程序发送到特定屏幕
如何将不是我的应用程序(例如:任何第 3 方应用程序)的应用程序(例如 WM_ 消息?)发送到多屏幕系统上的不同屏幕?是否有特定的 Windows 消息代码可以发送到窗口或进程句柄来执行此操作?
how could I send an application (think WM_ messages?) which is not my application (think: any 3rd party app) to a different screen on a multiscreen system? Is there a specific windows message code I can send to the window or process handle to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要使用 P/Invoke 和 MoveWindow 函数。
编辑:它可以很好地处理多个屏幕。
MoveWindow
将您的屏幕视为一个大显示器,并相应地接受参数。您可以使用 .Net Screen 类来查找所需屏幕的边界,然后调用MoveWindow
将窗口移至所需位置。另外,如果您没有意识到,您的项目很可能也需要
FindWindowByCaption
函数。You'll want to use P/Invoke and the MoveWindow function.
Edit: It handles multiple screens just fine.
MoveWindow
sees your screens as one big display, and takes arguments accordingly. You can use the .Net Screen class to find the bounds of the screen you want, and then callMoveWindow
to get the window where you want it.Also, in case you weren't aware of it, there's a good chance that your project is probably going to need the
FindWindowByCaption
function as well.我从未尝试过这个,但是如何使用 WM_MOVE< /a>? SendMessage 函数将允许您发送需要的消息。由于您已将问题标记为使用 C#,因此您必须使用 p/invoke 才能使用它。这是一个示例。
至于获取屏幕位置和尺寸,请参阅屏幕< /a> .Net 库中的类。有一个名为 FromHandle(),以及一个名为 AllScreens 返回用户拥有的所有有效屏幕的数组。 FromHandle() 会告诉您应用程序当前占用最多的屏幕(这对于您的情况可能有用,也可能没有用)。这将允许您在将消息发送到第 3 方应用程序之前计算该应用程序的所需位置。
I've never tried this, but how about using WM_MOVE? The SendMessage function will allow you to send the required message. Since you've marked your question as using C#, you'll have to use p/invoke to use it. Here's an example.
As for getting screen locations and sizes, see the Screen class in the .Net library. There's one function called FromHandle(), and a property called AllScreens which returns an array of all the valid screens the user has. FromHandle() will tell you which screen the app is currently occupying the most (this may or may not be useful in your case). This will allow you to compute the desired location of the 3rd party application, before sending the message to that application.