Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GUITHREADINFO gti = new GUITHREADINFO();
- IntPtr hWnd = GetForegroundWindow();
- uint processId;
- uint activeThreadId = GetWindowThreadProcessId(hWnd, out processId);
- if (GetInfo(activeThreadId, out gti))
- {
- int EM_REPLACESEL = 0x00C2;
- int error = Marshal.GetLastWin32Error();
- int result = SendMessageW(gti.hwndCaret, EM_REPLACESEL, -1, passed);//3rd param doesn't change anything
- error = Marshal.GetLastWin32Error();
- }
- [DllImport("User32.dll", EntryPoint = "SendMessageW", SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern int SendMessageW(IntPtr hWnd, int uMsg, int wParam, string lParam);
- [DllImport("user32.dll")]
- static extern IntPtr GetForegroundWindow();
- [DllImport("user32.dll", SetLastError = true)]
- static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
- //"Borrowed" code
- public static bool GetInfo(uint hwnd, out GUITHREADINFO lpgui)
- {
- uint lpdwProcessId;
- uint threadId = GetWindowThreadProcessId(hwnd, out lpdwProcessId);
- lpgui = new GUITHREADINFO();
- lpgui.cbSize = Marshal.SizeOf(lpgui);
- return GetGUIThreadInfo(threadId, ref lpgui);
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct RECT
- {
- public int iLeft;
- public int iTop;
- public int iRight;
- public int iBottom;
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct GUITHREADINFO
- {
- public int cbSize;
- public int flags;
- public IntPtr hwndActive;
- public IntPtr hwndFocus;
- public IntPtr hwndCapture;
- public IntPtr hwndMenuOwner;
- public IntPtr hwndMoveSize;
- public IntPtr hwndCaret;
- public RECT rectCaret;
- }
Add Comment
Please, Sign In to add comment