C# EM_CHARFROMPOS how to cast a point to Intptr?
See the question and my original answer on StackOverflowThe code must be different if you target a Rich edit control vs an Edit control, but you can get inspiration from .NET's code (and you can define multiple versions of SendMessage that suit your needs):
For a text box: https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/TextBoxBase.cs,1754
...
var pt = (IntPtr)MAKELONG(pt.X, pt.Y);
SendMessage(handle, EM_CHARFROMPOS, 0, pt);
...
public static int MAKELONG(int low, int high) {
return (high << 16) | (low & 0xffff);
}
[DllImport("user32", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
For a rich text box: https://referencesource.microsoft.com/#system.windows.forms/winforms/Managed/System/WinForms/RichTextBox.cs,2323
...
var pt = new POINT(pt.X, pt.Y);
SendMessage(handle, EM_CHARFROMPOS, 0, pt);
...
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
}
[DllImport("user32", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, POINT lParam);