Can't select text in RichEditComponent control

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Can't select text in RichEditComponent control



I want to keep my app's window in front of another programs's window.
My app is created with WPF, I set owner with another window's hwnd like this:


// this: my wpf window
WindowInteropHelper helper = new WindowInteropHelper(this);

//The hwnd is handle of window that other program I want to follow
helper.Owner = new IntPtr(hwnd);



Everything is perfect, but I can't select text with mouse within RichEditComponent of the window (the hwnd window).



Any idea to fix this?



Don't know other program write with which language,maybe c++. Handle of other program's window obtained with windows api "FindWindowEx".





Your screen capture is not very useful. Some text seems to be selected ?
– Bertrand
Jun 22 at 8:58




2 Answers
2



If your other program is a Winforms program, you need to add a reference to



System.Windows.Forms.Integration.dll


System.Windows.Forms.Integration.dll



and add a call to ElementHost.EnableModelessKeyboardInterop(Window window) like shown below:


ElementHost.EnableModelessKeyboardInterop(Window window)


WindowInteropHelper helper = new WindowInteropHelper(this);
helper.Owner = new IntPtr(hwnd);

ElementHost.EnableModelessKeyboardInterop(this);



because apparently Winforms and WPF have different ways of handling text input (and therefore also affecting text selection - more specific, copy & paste of selected text - as well).



Other than that, the issue might be the HWND pointer - how do you obtain it?



e.g. this is how you can obtain the main window handle by specifying a process name:


Process process = Process.GetProcessesByName("...")[0];
IntPtr hwnd = process.MainWindowHandle;





Thanks! Don't know other program write with which language,maybe c++. The method you post can't work.Handle of other program's window obtained with windows api "FindWindowEx".
– cqsir
Jun 22 at 9:47






@cqsir it should still work though. Nevertheless, did you try the approach with ElementHost.EnableModelessKeyboardInterop?
– Thomas Flinkow
Jun 22 at 9:53


ElementHost.EnableModelessKeyboardInterop





yes ,I try the approach you post.Dosen't work!
– cqsir
Jun 22 at 9:56





public void SetOwner(Window wnd, int hwnd) if (wnd == null) return; WindowInteropHelper helper = new WindowInteropHelper(wnd); helper.Owner = new IntPtr(hwnd); ElementHost.EnableModelessKeyboardInterop(wnd); //WindowsFormsHost.EnableWindowsFormsInterop();
– cqsir
Jun 22 at 10:01



I had resolved the question by detect Mouse drag event use global hook. When drag start,cancel set owner,and then,when drag finished,set owner with the follow window again.



Use MouseKeyHook to detect global mouse drag event.



https://www.nuget.org/packages/MouseKeyHook



Thanks @Thomas Flinkow again,for your help!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard