开发者

Windows API and SendMessage()

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.

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.


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 );

0x43 being the C key (see 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.

SendMessage( hwnd, WM_COPY, 0, 0 );


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

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

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

More info:

Subclassing Controls - MSDN

ActiveX Controls: Subclassing a Windows Control

** Subclassing Windows Forms Controls May be the most pertinent.


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

Hooking

EasyHook

MSDN Hooks Good overview.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜