Reputation: 31
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.
Upvotes: 2
Views: 13027
Reputation: 1741
Additional Links for "Windows Hooking." It's a technique to hook or trap messages and events in external applications.
MSDN Hooks Good overview.
HTH
Upvotes: 0
Reputation: 1741
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:
ActiveX Controls: Subclassing a Windows Control
** Subclassing Windows Forms Controls May be the most pertinent.
Upvotes: 1
Reputation: 22220
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 );
Upvotes: 2