Posts

Showing posts with the label Windows API

Donate

How To Change Position A Windows Forms MessageBox in C#

Here's a tip from CODE PROJECT on positioning message box. This utilize c++ dlls. using System.Runtime.InteropServices; using System.Threading; [DllImport("user32.dll")] static extern IntPtr FindWindow(IntPtr classname, string title); // extern method: FindWindow [DllImport("user32.dll")] static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool rePaint); // extern method: MoveWindow [DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr hwnd, out Rectangle rect); // extern method: GetWindowRect void FindAndMoveMsgBox( int x, int y, bool repaint, string title) { Thread thr = new Thread(() => // create a new thread { IntPtr msgBox = IntPtr.Zero; // while there's no MessageBox, FindWindow returns IntPtr.Zero while ((msgBox = FindWindow(IntPtr.Zero, title)) == IntPtr.Zero) ; // after the while loop, msgBox is

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

Donate