简体   繁体   English

在Windows 10平板电脑模式下关闭Win Form应用程序后返回开始菜单

[英]Return to start menu after closing win form application in Windows 10 tablet mode

I have a winform application (C#) that I am running on a windows tablet which is running in tablet mode. 我有一个在平板电脑模式下运行的Windows平板电脑上运行的Winform应用程序(C#)。 When I close the application however, the screen goes to the desktop, which in tablet mode is just the taskbar with a blank screen. 但是,当我关闭应用程序时,屏幕转到桌面,在平板电脑模式下,桌面只是空白的任务栏。 It's not until you click on the screen that it pulls up the start menu. 直到您单击屏幕时,它才会拉起开始菜单。

This appears to be consistent with any winform applications running in tablet mode for some reason, but regardless I would like to find a way to simply bring up the start menu after closing the application. 由于某种原因,这似乎与在平板电脑模式下运行的任何winform应用程序一致,但是无论我想找到一种方法在关闭应用程序后简单地调出开始菜单。

I have tried to simulate a mouse click after the application closes with calling (credit to https://www.gamedev.net/topic/321029-how-to-simulate-a-mouse-click-in-c/ ): 我尝试在应用程序关闭后通过调用模拟鼠标单击(贷记到https://www.gamedev.net/topic/321029-how-to-simulate-a-mouse-click-in-c/ ):

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

private const int MOUSEEVENTF_LEFTDOWN = 0x02;    

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}

but this does not work. 但这不起作用。 I have tried playing with the taskbar settings to see if it can be fixed through Windows with no luck. 我试过玩任务栏设置,看它是否可以通过Windows修复而没有运气。

Does anyone know how to simply bring up the start menu after closing a winform application by code or by settings? 有谁知道在通过代码或设置关闭Winform应用程序后如何简单地调出开始菜单?

I resolved the problem with help from this post: SendKeys.Send and Windows Key 我在这篇文章的帮助下解决了该问题: SendKeys.Send和Windows Key

It looks like rather than sending a mouse click, sending a key down followed by a key up of the LWin key does the trick: 看起来就像发送鼠标按下,而不是发送鼠标单击,然后发送LWin键的向上键可以解决问题:

    [DllImport("user32.dll")]
    private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    private const int KEYEVENTF_EXTENDEDKEY = 1;
    private const int KEYEVENTF_KEYUP = 2;


    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
         keybd_event((byte)Keys.LWin, 0, KEYEVENTF_EXTENDEDKEY, 0);
         keybd_event((byte)Keys.LWin, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
    }

Of course, this code needs some additional checks to make sure we are actually in tablet mode. 当然,此代码需要进行一些其他检查,以确保我们实际上处于平板电脑模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM