Can not use Alt + F4 to close program when WPF application have a Webview - webview

My application have a Webview. It's fullscreen application. The problem is when I press Alt+F4, the application is not exit, nothing happen.
I think the Webview swallow the focus because: When I press Window key > Show start menu > press Window key again > Hide start menu > Alt + F4 > The application exit as expected.
I found that WPF WebBrowser have WebBrowserShortcutsEnabled but i can't find something like that in Windows community toolkit WebView.
Please help me to make Alt + F4 works. Thank you!

I had the same issue and solved it pragmatically by handling the WebView's AcceleratorKeyPressed event (checking for Alt+F4 and closing the window in this case).
MainWindow.xaml:
<Controls:WebView ... AcceleratorKeyPressed="WebView_AcceleratorKeyPressed"/>
MainWindow.xaml.cs:
private void WebView_AcceleratorKeyPressed(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlAcceleratorKeyPressedEventArgs e)
{
if (e.VirtualKey == Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.VirtualKey.F4 && Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
Close();
}

Related

Javascript void(0)

I came across this piece of code in a website I was asked to help with.
`
<script>
function removeLinks(links) {
if (!arguments[0]) return;
var a = arguments[0];
$(".WaGadgetMenuHorizontal a:not(.wa-authenticateLoginLink), .WaGadgetMenuVertical a:not(.wa-authenticateLoginLink),.WaGadgetMobilePanel a:not(.wa-authenticateLoginLink)").each(function() {
var curhref=$(this).attr('href').split("/")[3];
if (
(typeof(a)=='string' && a==curhref)||
(typeof(a)=='object' && ($.inArray(curhref, a)>-1))
) {
$(this).attr("href", "javascript:void(0)").css("cursor","context-menu");
}
});
}
removeLinks("Philanthropy");
</script>`
This makes the Philanthropy link unclickable but there are 2 issues to be resolved.
Clicking the Philanthropy link shows the words Javascript:void(0) in the bottom left of the screen
Clicking the Philanthropy link takes you to whatever page you were on previously which is confusing to users, especially on the mobile version of the website where you simply jump from the click on the link to whatever previous page you were on. AT least on the PC you are still on the link with the previous page in the background so to speak.
Is there a way to remove the message that shows at the bottom left of the screen and to click on the link and stay on the link unless you click away to another link?
I tried to modify the code with different things that I found online but nothing seems to work

Selenium code to click/tap on a link, which opens a new tab on ipad/iphone

I have been trying to click/tap on a link using selenium, which opens a new tab on ipad/iphone. The test, I have written is working fine on desktop but it is not clicking the element, when it runs on ipad/iphone (saucelab). The step, which clicks the element is Passed (no error) but the click is not happened and there is only one window handle (parent) available. When I try to click on the element manually (on saucelab as well on physical device), it works fine & the new tab opens. Tried with different locators & all identifies the element correctly. Tried with different methods like javascript, actions, TouchActions, long press & release and even send keys. I observed the same behavior in other sites as well.
It seems like a generic issue. Please help me to fix this.
Similar scenario: Verify clicking on the link 'Google’s Terms of Service' on page "https://www.google.com/gmail/about/policy/" opens a new tab.
code segment
driverThread.get().get("https://www.google.com/gmail/about/policy/");
String parentHandle = driverThread.get().getWindowHandle();
System.out.println("Parent Handle --- " + parentHandle);
WebElement element = driverThread.get().findElement(By.cssSelector("body > main > section > section > div > p:nth-child(2) > a"));
element.click(); // **please help me to click/tap this element**
String newHandle = null;
System.out.println("Window Handles size --- " + driverThread.get().getWindowHandles().size());
for (String handle : driverThread.get().getWindowHandles()) {
System.out.println("Handle --- " + handle);
if(!handle.equalsIgnoreCase(parentHandle))
newHandle = handle;
}
driverThread.get().switchTo().window(newHandle);
System.out.println("New Tab URL --- "+ driverThread.get().getCurrentUrl());
You can use this code for clicking on the link :
WebElement element = driverThread.get().findElement(By.linkText("Google’s Terms of Service"));
element.click();
try out this code ! hope this will help you resolve your issue.

How to make modal form un-minimize after a Show Desktop (or windows + D)

When I start my application, the first and only form that shows is a login form in modal:
frmLogin = new TfrmLogin(Application);
frmLogin->Init();
if(frmLogin->ShowModal() == mrCancel)
{
//this will exit the application because user cancel the login
return -1;
}
There is code happening after the ShowModal which open the main form (not in modal) of the application.
When I press Show Desktop or do windows + D and I'm still on the modal form for the login, I can't get the login back when clicking on the taskbar.
1. Is there a way to un-minimize the modal login after a 'Show Desktop'?
2. Also, if I open my application and the login appears, I can't seem to be able to close it when right-clicking on it in the taskbar > 'Close windows'. Is there a way to close it by the taskbar? (It close perfectly when using the red 'x' in the corner of the login form though)
I'm using c++ Builder 10.1 Berlin
As #Remy Lebeau suggested, I came to the solution by overriding the CreateParams() function.
In my Login.h
protected:
virtual void __fastcall CreateParams(TCreateParams &Params);
In my Login.cpp
void __fastcall TfrmLogin::CreateParams(TCreateParams &Params)
{
TForm::CreateParams(Params);
Params.ExStyle = WS_EX_APPWINDOW;
Params.WndParent = GetDesktopWindow();
}
My code is based on the Delphi example found here:
https://forums.embarcadero.com/thread.jspa?threadID=244599
Now, my Login form is able to be un-minimized after a ctrl + D!
Hopes this helps other c++ builder programmers out there.

How to achieve modal dialogs from NotifyIcon context menu?

I've got a shell tray icon with an attached context menu. The problem I'm having is that calling ShowDialog() from a context menu Clicked handler does not result in a modal dialog.
It's easy to reproduce this with a default C# project. Simply add the following code to the Form1.cs file:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ToolStripMenuItem contextMenuShowMsg = new System.Windows.Forms.ToolStripMenuItem();
contextMenuShowMsg.Name = "contextMenuShowMsg";
contextMenuShowMsg.Text = "Show MessageBox...";
contextMenuShowMsg.Click += new System.EventHandler(this.contextMenuShowMsg_Click);
ContextMenuStrip contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
contextMenuStrip.Items.Add(contextMenuShowMsg);
NotifyIcon notifyIcon = new NotifyIcon();
notifyIcon.Text = "DlgTest";
notifyIcon.Icon = SystemIcons.Application;
notifyIcon.Visible = true;
notifyIcon.ContextMenuStrip = contextMenuStrip;
}
private void contextMenuShowMsg_Click(object sender, EventArgs e)
{
MessageBox.Show(this, "Test MessageBox");
}
If you build and run this, you will be able to get two message boxes on the screen by simply choosing the context menu item twice. Shouldn't this be modal? Replacing this with a call to ShowDialog() for another form results in the same non-modal behavior.
My best guess is that the NotifyIcon isn't specifically tied to the Form, as it would be in a typical Windows application. But I don't see any way of doing that.
Any ideas? Thanks in advance for any help!
I would suggest doing two things before you attempt to display a modal message box:
Make your icon's owner-window visible.
Give it focus.
Once you've done that, the this in the MessageBox.Show becomes a legal "modality parent".
Heck, it even makes more sense that the message box will be displayed on top of whatever program generated it, right? That way, the user has some context for what the message box is about!
You will need to keep track of activations of your system tray menu, and disable it when a dialog is open.

WatiN: Print Dialog

I have a screen that pops up on load with a print dialog using javascript.
I've just started using WatiN to test my application. This screen is the last step of the test.
What happens is sometimes WatiN closes IE before the dialog appears, sometimes it doesn't and the window hangs around. I have ie.Close() in the test TearDown but it still gets left open if the print dialog is showing.
What I'm trying to avoid is having the orphaned IE window. I want it to close all the time.
I looked up DialogHandlers and wrote this:
var printDialogHandler = new PrintDialogHandler(PrintDialogHandler.ButtonsEnum.Cancel);
ie.DialogWatcher.Add(printDialogHandler);
And placed it before the button click that links to the page, but nothing changed.
The examples I saw had code that would do something like:
someDialogHandler.WaitUntilExists() // I might have this function name wrong...
But PrintDialogHandler has no much member.
I initially wasn't trying to test that this dialog comes up (just that the page loads and checking some values on the page) but I guess it would be more complete to wait and test for the existence of the print dialog.
Not exactly sure about your situation, but we had a problem with a popup window that also displayed a print dialog box when loaded. Our main problem was that we forgot to create a new IE instance and attach it to the popup. Here is the working code:
btnCoverSheetPrint.Click(); //Clicking this button will open a new window and a print dialog
IE iePopup = IE.AttachToIE(Find.ByUrl(new Regex(".+_CoverPage.aspx"))); //Match url ending in "_CoverPage.aspx"
WatiN.Core.DialogHandlers.PrintDialogHandler pdhPopup = new WatiN.Core.DialogHandlers.PrintDialogHandler(WatiN.Core.DialogHandlers.PrintDialogHandler.ButtonsEnum.Cancel);
using (new WatiN.Core.DialogHandlers.UseDialogOnce(iePopup.DialogWatcher, pdhPopup)) //This will use the DialogHandler once and then remove it from the DialogWatcher
{
//At this point the popup window will be open, and the print dialog will be canceled
//Use the iePopup object to manage the new window in here.
}
iePopup.Close(); // Close the popup once we are done.
This worked for me:
private void Print_N_Email(Browser ie)
{
//Print and handle dialog.
ie.Div(Find.ById("ContentMenuLeft")).Link(Find.ByText(new Regex("Print.*"))).Click();//orig
Browser ie2 = Browser.AttachTo(typeof(IE), Find.ByUrl(new Regex(".*Print.*")));
System.Threading.Thread.Sleep(1000);
PrintDialogHandler pdh = new PrintDialogHandler(PrintDialogHandler.ButtonsEnum.Cancel);
new UseDialogOnce(ie2.DialogWatcher, pdh);
ie2.Close();
}
You still might want to check your browser AutoClose property ie.AutoClose

Resources