Guest User

Untitled

a guest
Jan 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. GUITHREADINFO gti = new GUITHREADINFO();
  2. IntPtr hWnd = GetForegroundWindow();
  3. uint processId;
  4. uint activeThreadId = GetWindowThreadProcessId(hWnd, out processId);
  5. if (GetInfo(activeThreadId, out gti))
  6. {
  7. int EM_REPLACESEL = 0x00C2;
  8.  
  9. int error = Marshal.GetLastWin32Error();
  10. int result = SendMessageW(gti.hwndCaret, EM_REPLACESEL, -1, passed);//3rd param doesn't change anything
  11. error = Marshal.GetLastWin32Error();
  12. }
  13.  
  14. [DllImport("User32.dll", EntryPoint = "SendMessageW", SetLastError = true, CharSet = CharSet.Unicode)]
  15. public static extern int SendMessageW(IntPtr hWnd, int uMsg, int wParam, string lParam);
  16.  
  17. [DllImport("user32.dll")]
  18. static extern IntPtr GetForegroundWindow();
  19.  
  20. [DllImport("user32.dll", SetLastError = true)]
  21. static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
  22. //"Borrowed" code
  23. public static bool GetInfo(uint hwnd, out GUITHREADINFO lpgui)
  24. {
  25. uint lpdwProcessId;
  26. uint threadId = GetWindowThreadProcessId(hwnd, out lpdwProcessId);
  27.  
  28. lpgui = new GUITHREADINFO();
  29. lpgui.cbSize = Marshal.SizeOf(lpgui);
  30.  
  31. return GetGUIThreadInfo(threadId, ref lpgui);
  32. }
  33.  
  34. [StructLayout(LayoutKind.Sequential)]
  35. public struct RECT
  36. {
  37. public int iLeft;
  38. public int iTop;
  39. public int iRight;
  40. public int iBottom;
  41. }
  42.  
  43. [StructLayout(LayoutKind.Sequential)]
  44. public struct GUITHREADINFO
  45. {
  46. public int cbSize;
  47. public int flags;
  48. public IntPtr hwndActive;
  49. public IntPtr hwndFocus;
  50. public IntPtr hwndCapture;
  51. public IntPtr hwndMenuOwner;
  52. public IntPtr hwndMoveSize;
  53. public IntPtr hwndCaret;
  54. public RECT rectCaret;
  55. }
Add Comment
Please, Sign In to add comment