PostMessageA (user32)
Last changed: -188.40.73.235

.
Summary
Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.

C# Signature:

[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

VB Signature:

Declare Function PostMessageA Lib "user32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute to it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

public const uint WM_KEYDOWN = 0x100;

// get the handle of window
var hWnd = IntPtr.Zero; //use FindWindowEx etc...

// send few messages to the window
PostMessage(hWnd,  WM_KEYDOWN, VkKeyScan('h'), 0);
PostMessage(hWnd,  WM_KEYDOWN, VkKeyScan('e'), 0);
PostMessage(hWnd,  WM_KEYDOWN, VkKeyScan('l'), 0);
PostMessage(hWnd,  WM_KEYDOWN, VkKeyScan('l'), 0);
PostMessage(hWnd,  WM_KEYDOWN, VkKeyScan('o'), 0);

Overloading:

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool PostMessageW(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool PostMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, UIntPtr lParam);
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool PostMessageW(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool PostMessageW(IntPtr hWnd, uint Msg, uint wParam, ref IntPtr lParam);
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool PostMessageW(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool PostMessageW(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);

Documentation