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

.
Summary
Sends the specified message to a window or windows.

C# Signatures:

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

//Overload for string lParam (e.g. WM_GETTEXT)
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,    
[Out] StringBuilder lParam);

VB Signatures:

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

<DllImport("User32.dll", CharSet:=CharSet.Auto, Entrypoint:="SendMessage")> _
Private Shared Function SendMessageString(ByVal hwnd As IntPtr, _
   ByVal wMsg As Integer, ByVal wparam As IntPtr, ByVal lparam As String) As IntPtr
End Function

User-Defined Types:

None.

Notes:

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

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

3) VB: Imports System. Runtime. InteropServices

Tips & Tricks:

Please add some more!

Sample Code:

//C#

public static String GetWindowText(IntPtr hWnd)

{

    IntPtr txtLength;
    IntPtr retValue;
    IntPtr zeroVal = new IntPtr(0);

    //Get the length of the text
    retValue = Win32Api.SendMessage(hWnd,Win32Api.WM_GETTEXTLENGTH,zeroVal,zeroVal);

    //Setup the size of the sb
    txtLength= new IntPtr(retValue.ToInt32() + 1);

    StringBuilder sb = new StringBuilder(txtLength.ToInt32());

    //Get the text of the window/control
    retValue =  Win32Api.SendMessage(hWnd,Win32Api.WM_GETTEXT,txtLength,sb);

    //Return a string
    return sb.ToString();

}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
SendMessage on MSDN