windows 如何在 C# 中使用 Sendmessage?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4280788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:40:16  来源:igfitidea点击:

How to use Sendmessage in C#?

c#windows

提问by Marcus

I got the hwnd = FindWindow(""); but how to do Sendmessage with mouse clicks with this window ?? Thx.

我得到了 hwnd = FindWindow(""); 但是如何用鼠标点击这个窗口来发送消息??谢谢。

回答by Svisstack

using System.Runtime.InteropServices;
...
[DllImport("user32.dll")]
private static extern IntPtr SendMessage
    (IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

For usage information look at http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspxGeneraly you must only call this function with good arguments, to know what arguments you need you must look at msdn.

有关使用信息,请查看http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx一般而言,您只能使用正确的参数调用此函数,要知道您需要哪些参数,您必须查看在 msdn。

回答by Govert

You want to simulate mouse clicks using SendMessage?

您想使用 SendMessage 模拟鼠标点击吗?

This is a duplicate question to this one: Using SendMessage for Simulating User Mouse Clicks.

这是一个重复的问题:Using SendMessage for Simulating User Mouse Clicks

The answer there recommends that you investigate WIN32 journal hooks, thus sending WH_JOURNALPLAYBACK.

那里的答案建议您调查 WIN32 日志挂钩,从而发送 WH_JOURNALPLAYBACK。

And another duplicate with what is reported to be a working snippet: Clicking mouse by sending messages

另一个重复的报告是一个工作片段:通过发送消息单击鼠标

This discussion on MSDN indicates that it's not so easy using the raw mouse messages: http://social.msdn.microsoft.com/Forums/hu-HU/vbide/thread/5352d3b8-4f9e-4a0a-8575-fdd592ae45f8.

MSDN 上的讨论表明使用原始鼠标消息并不容易:http: //social.msdn.microsoft.com/Forums/hu-HU/vbide/thread/5352d3b8-4f9e-4a0a-8575-fdd592ae45f8