richtextbox - how can i simulate CTRL+C in C# -
I have the following code that works fine in Notepad, but not in Word!
[DllImport ("user32.dll")] Public static extern bool ShowWindow (IntPtr hWnd, int nCmdShow); [DllImport ("user32.dll")] Public stable extern IntPtr GetForegroundWindow (); [DllImport ("user32.dll", SetLastError = true)] Public Static Extrint UIT GetWindowThreadProcessId (IntPtr hWnd, Outside UIT LPDY Processed); [DllImport ("kernel32.dll")] Public static extern uint GetCurrentThreadId (); [DllImport ("user32.dll")] Public Static Extensions Boole AttachThreadInput (UIT idAttach, uint idAttachTo, bool fAttach); [DllImport ("user32.dll")] Public stable extern IntPtr GetFocus (); [DllImport ("user32.dll")] Public stable extern int SendMessage (IntPtr hWnd, uint message, int wParam, StringBuilder lParam); // second overload SendMessage [DllImport ("user32.dll")] Public static extern int SendMessage (IntPtr hWnd, uint message, out int wParam, out int lParam); [DllImport ("user32.dll")] Public static extern c GetWindowText (IntPtr hWnd, StringBuilder text, int count); Public set WM_GETTEXT = 0x0D; Public structure WM_GETTEXTLENGTH = 0x0 e; Public state EM_GETSEL = 0xB0; IntPtr hWnd = WinUser.GetForegroundWindow (); UIT Process ID; UIT ActiveStreadID = WinUser.GetWindowThreadProcessId (HWND, Out Processing); UIT truetoothreadd = WinUser.GetCurrentThreadId (); WinUser.AttachThreadInput (activeThreadId, currentThreadId, true); IntPtr Focus = WinUser.GetFocus (); WinUser.AttachThreadInput (activeThreadId, currentThreadId, Incorrect); Int len = WinUser.SendMessage (FocusHound, Vinusor WM_GETTEXTLENGTH, 0, blank); Stringbilder sb = new string builder (lane); Int numChars = WinUser.SendMessage (Focushandel, Vinusor WM_GETTEXT, len + 1, sb); Int start, next; String selected text = ""; WinUser.SendMessage (FocusHandel, WinUser.EM_GETSEL, start out, out next); Try {SelectedText = sb.ToString (). Substrings (start, next-start); }
Unfortunately, the above return "{Microsoft Word Document}" when choosing Text in WORD or any "Richetbox" How does CTRL Si do?
Note: It works fine in Notepad or on any ordinary text editor.
Are you looking for this:
Comments
Post a Comment