SendMessage - using for forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I Have a question. I use C# to send messages for other wondows.
In my example it is windows notepad.exe
So after I found handle of this window I can send WM_CHAR event.
But I need help with other two types of events.
How can I send
1) Some system key like "F5" ?
2) some combination of them? For example Alt + V ?

This is code which use now.

[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName, String
lpWindowName);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam,
int lParam);


[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, string windowTitle);

private const int WM_KEYDOWN = 256;

int hwnd = FindWindow(null, "1.txt - Notepad");
if (hwnd != 0)
{
IntPtr hwndChild = IntPtr.Zero;
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Edit", null);

int Key = (int)'D';
//send BN_CLICKED message
SendMessage((int)hwndChild, WM_CHAR, (int)Key, 0);

IntPtr first = new IntPtr(1);
IntPtr second = new IntPtr((int)3F);

//send F5
Keys key = Keys.F5;
SendMessage((int)hwndChild, WM_KEYDOWN, (int)key, 1 | (int)3F);
}
 
For Alt=V, use the WM_SYSKEYDOWN followed by WM_SYSKEYUP window message.
For F5, use WM_KEYDOWN followed by WM_KEYUP

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
 
G Himangi said:
For Alt=V, use the WM_SYSKEYDOWN followed by WM_SYSKEYUP window message.
For F5, use WM_KEYDOWN followed by WM_KEYUP

G Himangi said:
For Alt=V, use the WM_SYSKEYDOWN followed by WM_SYSKEYUP window message.
For F5, use WM_KEYDOWN followed by WM_KEYUP

thanks. But I know that. Can you give me an example what I should put in
parametrs?

something like that

SendMessage((int)hwndChild, WM_KEYDOWN, (int)key, LPARAM );
SendMessage((int)hwndChild, WM_KEYUP, (int)key, LPARAM );

The question is what should be in LPARAM ????
 
The LPARAM consists of various flags combined to make an int. The flags are
desribed in the docs for the messages.
 
Back
Top