Windows API 和 SendMessage()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3539190/
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:05:11  来源:igfitidea点击:

Windows API and SendMessage()

windowswinapi

提问by Gooose

int x = 5;
int y = 10;

y = y << 16;
int coord = x | y;

NativeMethods.SendMessage(hwnd, WM_LBUTTONDOWN, new IntPtr(0), new IntPtr(coord));
NativeMethods.SendMessage(hwnd, WM_LBUTTONUP, new IntPtr(0), new IntPtr(coord));

Using the above code (ref: MSDN), I'm able to select a row in a datagridview in an external application. I would like to know how I can send a ctrl-a and ctrl-c to the same datagridview.

使用上面的代码(参考:MSDN),我可以在外部应用程序的 datagridview 中选择一行。我想知道如何将 ctrl-a 和 ctrl-c 发送到同一个 datagridview。

Still trying to connect to why the x and y variables are initialized to 5,10, and why y is left shifted by 16 and then | with x.

仍然试图连接到为什么 x 和 y 变量初始化为 5,10,以及为什么 y 左移 16 然后 | 与 x。

回答by Bertrand Marron

What about this:

那这个呢:

SendMessage( hwnd, WM_KEYDOWN, VK_CTRL, 0 );
SendMessage( hwnd, WM_KEYDOWN, 0x43, 0 );
// Ctrl and C keys are both pressed.
SendMessage( hwnd, WM_KEYUP, 0x43, 0 );
SendMessage( hwnd, WM_KEYUP, VK_CTRL, 0 );

0x43being the C key (see http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx)

0x43作为 C 键(参见http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx



Edit:If it doesn't work, try sending WM_COPY, which should be a better idea.

编辑:如果它不起作用,请尝试发送WM_COPY,这应该是一个更好的主意。

SendMessage( hwnd, WM_COPY, 0, 0 );

回答by JustBoo

You might actually need Windows Subclassing. Note this is not C++ Subclassing.

您可能实际上需要Windows Subclassing。请注意,这不是 C++ 子类化。

This technique sends messages from a particular Window Procedure (WndProc) to another WndProc, thus achieving what you seem to want.

这种技术将消息从特定的窗口过程 (WndProc) 发送到另一个 WndProc,从而实现您想要的效果。

Once setup it just works. MSDN is light on this information, thus the link above as a tutorial.

一旦设置它就可以工作。MSDN 对这些信息很清楚,因此上面的链接作为教程。

More info:

更多信息:

Subclassing Controls - MSDN

子类化控件 - MSDN

ActiveX Controls: Subclassing a Windows Control

ActiveX 控件:子类化 Windows 控件

** Subclassing Windows Forms ControlsMay be the most pertinent.

**子类化 Windows 窗体控件可能是最相关的。

回答by JustBoo

Additional Links for "Windows Hooking." It's a technique to hook or trap messages and events in external applications.

“Windows 挂钩”的附加链接。这是一种在外部应用程序中挂钩或捕获消息和事件的技术。

Hooking

挂钩

EasyHook

易钩

MSDN HooksGood overview.

MSDN Hooks很好的概述。

HTH

HTH