简体   繁体   中英

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. 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.

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/ ):

[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.

Does anyone know how to simply bring up the start menu after closing a winform application by code or by settings?

I resolved the problem with help from this post: SendKeys.Send and 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:

    [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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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