sendmessage (user32)
Last changed: thediscover22450@gmail.com-92.139.119.87

.
Summary
Sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.

To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.

C# Signature:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

Common C# Overloads:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, ref StringBuilder lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern void SendMessage(HandleRef hWnd, uint msg, IntPtr wParam, ref RECT lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(HandleRef hWnd, uint msg, IntPtr wParam, ref POINT lParam);

VB Signature:

Declare Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer,
   ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

Common VB Overloads:

<DllImport("user32.dll", CharSet=CharSet.Auto)> _
static extern IntPtr SendMessage(HandleRef hWnd, Integer msg, IntPtr wParam, StringBuilder lParam)

<DllImport("user32.dll", CharSet=CharSet.Auto)> _
static extern IntPtr SendMessage(HandleRef hWnd, Integer msg, IntPtr wParam, RECT lParam)

<DllImport("user32.dll", CharSet=CharSet.Auto)> _
static extern IntPtr SendMessage(HandleRef hWnd, Integer msg, IntPtr wParam, POINT lParam)

Notes:

1) Use IntPtr instead of UIntrPtr: The UIntPtr type is not CLS-compliant

2) NEVER use "int" or "integer" as wParam or lParam. Your code WILL crash on 64-bit windows. ONLY use IntPtr, a "ref" structure, or an "out" structure.

3) NEVER use "bool", "int", or "integer" as the return value. Your core WILL crash on 64-bit windows. ONLY use IntPtr. It's not safe to use bool - pInvoke cannot marshal an IntPtr to a boolean.

4) Use "IntPtr" as the return value, EVEN if the message says it doesn't return any useful information.

5) "msg" is always a 4-bit integer (do not use IntPtr). It is safe to use both "int" and "uint" (32-bit only), but Microsoft technically defines "msg" as a "double word" - which is the same as "Uint32"

6) You can replace "hWnd" with "IntPtr" instead of "HandleRef". However, you are taking a risk in doing this - it may cause your code to crash with race conditions - .NET can and will dispose your window handles out from under your message causing all sorts of nasty problems!

Tips & Tricks:

1) As the number of messages are varied, just keep overloading the function as you need.

Alternative Managed API:

Do you know one? Please contribute it!..

Documentation
SendMessage on MSDN