Donate

How To Get Textbox Or RichtextBox Value Using pInvoke In Windows API C#

Assuming you already get the pointer handle of the textbox/richtextbox control from source calling function, the snippet to get the content of the edit control is as follows.
public const int GWL_ID = -12;  
 public const int WM_GETTEXT = 0x000D;  
 [DllImport("User32.dll")]  
 public static extern int GetWindowLong(IntPtr hWnd, int index);  
 [DllImport("User32.dll")]  
 public static extern IntPtr SendDlgItemMessage(IntPtr hWnd, int IDDlgItem, int uMsg, int nMaxCount, StringBuilder lpString);  
 [DllImport("User32.dll")]  
 public static extern IntPtr GetParent(IntPtr hWnd);  
 private StringBuilder GetRichEditText(IntPtr hWndRichEdit)  
 {  
   Int32 dwID = GetWindowLong(hWndRichEdit, GWL_ID);  
   IntPtr hWndParent = GetParent(hWndRichEdit);  
   StringBuilder title = new StringBuilder(128);  
   SendDlgItemMessage(hWndParent, dwID,  
     WM_GETTEXT,  
     128, title);  
   return title;  
 } 
Greg

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations