my wpf application hosts an electron window by HwndSource, all has been working for several years on electron 10.1.6, now following the docs break changes and try to upgrade to 20.3.0. changes only:
in main, require('#electron/remote/main').initialize();
in preload, const remote = require('#electron/remote');
when create BrowserWindow set sandbox = false; contextIsolation = false; nodeIntegration = true; and require('#electron/remote/main').enable(win.webContents);
then mouse click between wpf part and this electron window.
within 10.1.6, keyboard focus will jump between.
within 20.3.2, i can click any buttons in electron area, but can not input anything for its textbox, by snoop, i can see the keyboard focus always on wpf parent window. seems electron can not take keyboard focus from wpf window.
after BrowserWindow show, i have tried wnd.focus(); wnd.focusOnWebView(); wnd.webContents.focus(); even call blur() first then focus(), or an addon extension that call win32 api SetFocus(HWND), but no lucky.
any suggestion here? it blocks me now, also cannot google any helpful solution.
already workaround, no matter wpf or electron, they are win32 window, we can get its handle and monitor message, when WM_PARENTNOTIFY is coming and once if WM_LBUTTONDOWN detected then SetFocus.
case WM_PARENTNOTIFY:
if (LOWORD(wParam) == WM_LBUTTONDOWN)
SetFocus(hwnd);
break;
Related
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".
If your other program is a Winforms program, you need to add a reference to
System.Windows.Forms.Integration.dll
and add a call to ElementHost.EnableModelessKeyboardInterop(Window window) like shown below:
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;
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!
I am facing an unexpected behavior of Keyboard showing and hiding in UWP app working on tablet with windows 10.
After carefully testing again and again i noticed that this issue comes when you have focus on input box and keyboard is opened for it. Now focusing next input needs layout adjustment so that it should not be hidden by keyboard. When you try to focus next element, by default previously opened keyboard hides and now i'm not able to open keyboard un till this new input box lose focus and manually gain focus again.
So for controlling this issue i want to prevent automatic hide and show of keyboard every time i switch focus to new textbox. It should open keyboard once the page load (already found solution using InputPane) and hiding should only be by clicking cancel (x) button.
Please check this video for clearly understanding the issue.
https://www.dropbox.com/s/1c876uwytywio1t/Soft%20Keyboard%20Issue.mp4?dl=0
Please vote this suggestion if anyone else is also facing this issue.
https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/34170142-inputpane-does-not-open-when-focus-is-shifted-to-n
This issue has been partially resolved in windows 10 version 1803 released on 30th April, 2018. In this version InputPane does not hide and show again and again when focus is shifted from one input element to other.
You may try to put a horizontal-stretched placeholder control (let say, StackPanel) at the bottom of your page, then let it the same size the on-screen keyboard does. That could prevent uncontrolled auto-hide trigger being fired (at least I did that trick on UWP mobile app):
// on the window initialization, remember the input pane
this._inputPane = InputPane.GetForCurrentView()
// then, subscribe to the events
_inputPane.Showing = (sender, args) =>
{
args.EnsuredFocusedElementInView = true; // skip default vertical-shift behavior
this._placeholderPane.Height = args.OccludedRect.Height;
}
_inputPane.Hiding = (sender, args) =>
{
this._placeholderPane.Height = 0;
}
Hope it helps on the Win10 desktop same way as it was on mobile one.
P.S. Yes, initially the placeholder pane is zero-height and collapsed.
I'm currently working on a popup program in wpf that gets hidden either by this.hide(); or MainWindow1.WindowState = WindowState.Hidden and "pops up" using MainWindow1.WindowState = WindowState.Normal;
My problem is, that I don't want the Mainwindow to gain any keyboard focus.
So whatever program has the keyboard focus, when the popup gets shown, it should keep it.
I just want it that way, so people don't type entire emails in the not handeling Popup, just because they didn't notice it popping up.
Edit:
I'm not trying to keep focus in any my own program windows but in other windows programs (e.g. Outlook)
Edit2:
Here is a screenshot from my Program, just to clear obscurities about the usage of the PopUp class.
Edit3: Maybe it's possible to set the keyboard focus back to the programm that was focused before?
so people dont type entire emails in
I would recommend that you set the main page controls, or their container, Enabled property to false when the popup is running and reverse when it is not. Hence focusing the user to the popup until its acknowledged.
If you purpose is to show a notification form, check that component: Windows Forms Toolkit NotificationForm
The solution is (as it seems) too easy, all you need to do is:
MainWindow1.Showactivated = false;
this.Show();
This will show the MainWindow while the focus is kept on whatever program had the focus before the MainWindow appeared.
I have two windows form MainForm and MinimizedMainForm. I want to disable Windows+D for both the forms. Parent of both forms is a third form FormBase. I have used following code for disabling the Windows+D
private const in GWL_HWNDPARENT =-8
IntPtr hprog = NativeMethods.FindWindowEx(NativeMethods.FindWindowEx(NativeMethods.FindWindow("Progman", "Program Manager"),
IntPtr.Zero, "SHELLDLL_DefView", ""),
IntPtr.Zero, "SysListView32", "FolderView");
NativeMethods.SetWindowLong(this.Handle, GWL_HWNDPARENT, hprog);
Problem I am facing is my MainForm is never getting minimized if I press Win+D.
and for first launch of MinimizedForm if I i press Win+D it doesnt get minimized.
But for second+ time Load of minimizedMainForm if I press Win+D , Form gets minimized. I have added above code on the FormLoad event of both the forms. MinimizedMainForm is opened when i click on panel on MainForm and vice versa. MainForm is the starting form of my project.
What should I do to stop the form from minimizing on 2nd+ loadForm events?
Maybe instead of preventing minimizing of window what can be minimized, you have to create window what can't be minimized instead: MinimizeBox = false ? (it can't be that simple I bet, but i can't write comments, so here comes a solution =D)
Basically Win + D is not for minimizing the windows but for showing desktop. Win+D = Show desktop. So even if your window does not have minimize box, it will get minimized.
Further, when you press Win+D, it is not your application which handles it but it is the windows itself which is handling it so it will never reach to your application at all so it makes no sense if you handle it in your application.
Try finding out some hack where your application is up, you stop windows from processing Win+D key.
There is a key in registry
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
changing values of hotkeys here will disable the Win+D combination but it is not recommended as you will have to restore it back when you application leaves the focus.
And yes, if you are making a widget, follow the requirements of creating a widget. It will automatically provide you such functionality
I am developing a touchscreen friendly app that also includes a virtual keyboard. My virtual keyboard is in its own window, allowing it to be moved around. The problem is that when I click on a key on the keyboard the text box on the main application window no longer has focus. The switch from the main application being the active window to the keyboard dialog being the active window means that any field on the main window no longer has focus. How can I get around this?
I tried setting the keyboard window as not focusable. Though this is probably good to set, it did not solve my problem.
You could just return focus to the original window asynchronousely:
public static void BackgroundFocus(this UIElement el)
{
Action a = () => el.Focus();
el.Dispatcher.BeginInvoke(DispatcherPriority.Background, a);
}
But this is not ideal, because the original window caption would flicker when losing focus...
Why don't you use Popup instead?
Check out the function SetForegroundWindow() ,
I have used this long time back some where in my project
May be this may help you
Using a Popup, as already suggested, seems like a good solution. As for your custom window, try setting the Window.ShowActivated to false.