[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);
Declare Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer,
ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr
None.
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
Please add some more!
//C#
public static String GetWindowText(IntPtr hWnd)
{
IntPtr txtLength;
IntPtr retValue;
IntPtr zeroVal = new IntPtr(0);
//Get the length of the text
retValue = SendMessage(hWnd,WM_GETTEXTLENGTH,zeroVal,zeroVal);
//Setup the size of the sb
txtLength = retValue;
StringBuilder sb = new StringBuilder(txtLength.ToInt32() + 1);
//Get the text of the window/control
retValue = SendMessage(hWnd,WM_GETTEXT,txtLength,sb);
//Return a string
return sb.ToString();
}
Do you know one? Please contribute it!..