none
How do i display the windows 10 volume flyout using C# (or VB) RRS feed

  • Question

  • So is there any way to have the windows 10 taskbar volume flyout (the uwp thing not the old win32 applet) show up? Perhaps something like the app-commandline urls ("ms-actioncenter:" opens the action center...). Or maybe by getting the handle of this thing?

    Wednesday, March 18, 2020 8:15 AM

Answers

  • Ok.

    I did some tests and a way to display it is with UIAutomation

    Tested on Windows 10 (french), I added a test on "Speakers" from your image =>

    // Add a reference to UIAutomationClient.dll and UIAutomationTypes.dll
    
    IntPtr hWndTray = FindWindow("Shell_TrayWnd", null);
    IntPtr hWndTrayNotify = FindWindowEx(hWndTray, IntPtr.Zero, "TrayNotifyWnd", null);
    IntPtr hWndSysPager = FindWindowEx(hWndTrayNotify, IntPtr.Zero, "SysPager", null);
    IntPtr hWndToolbar = FindWindowEx(hWndSysPager, IntPtr.Zero, "ToolbarWindow32", null);
    
    AutomationElement ae1 = AutomationElement.FromHandle(hWndToolbar);
    AutomationElementCollection aeCollection = ae1.FindAll(TreeScope.Subtree, Condition.TrueCondition);
    foreach (AutomationElement aeChild in aeCollection)
    {
        string sName = aeChild.Current.Name;
        // Test french or english name
        if (sName.Contains("Haut-parleurs") || sName.Contains("Speakers"))
        {
            object buttonPattern = null;
            if (aeChild.TryGetCurrentPattern(InvokePattern.Pattern, out buttonPattern))
            {
                System.Threading.Thread.Sleep(100);
                ((InvokePattern)buttonPattern).Invoke();
            }
        }
    }

    Declarations :

            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    • Marked as answer by at19AV20 Wednesday, March 18, 2020 3:17 PM
    Wednesday, March 18, 2020 2:25 PM

All replies

  • the uwp thing not the old win32 applet

    Which one ?

    Have you a screenshot ?

    In the doc, there is ms-settings:apps-volume

    but it does not work on my version

    • Edited by Castorix31 Wednesday, March 18, 2020 9:07 AM
    Wednesday, March 18, 2020 8:44 AM
  • I meant the taskbar flyout - which has a single slider and is accessed by clicking on the sound icon on the taskbar. ms-settings:apps-volume opens the volume settings in the settings app. Sorry for not clarifying earlier!

    www.techjunkie.com/wp-content/uploads/2016/08/windows-10-volume-taskbar.jpg

    Here is an image of what I want to access⏫


    • Edited by at19AV20 Wednesday, March 18, 2020 12:47 PM
    Wednesday, March 18, 2020 12:33 PM
  • Ok.

    I did some tests and a way to display it is with UIAutomation

    Tested on Windows 10 (french), I added a test on "Speakers" from your image =>

    // Add a reference to UIAutomationClient.dll and UIAutomationTypes.dll
    
    IntPtr hWndTray = FindWindow("Shell_TrayWnd", null);
    IntPtr hWndTrayNotify = FindWindowEx(hWndTray, IntPtr.Zero, "TrayNotifyWnd", null);
    IntPtr hWndSysPager = FindWindowEx(hWndTrayNotify, IntPtr.Zero, "SysPager", null);
    IntPtr hWndToolbar = FindWindowEx(hWndSysPager, IntPtr.Zero, "ToolbarWindow32", null);
    
    AutomationElement ae1 = AutomationElement.FromHandle(hWndToolbar);
    AutomationElementCollection aeCollection = ae1.FindAll(TreeScope.Subtree, Condition.TrueCondition);
    foreach (AutomationElement aeChild in aeCollection)
    {
        string sName = aeChild.Current.Name;
        // Test french or english name
        if (sName.Contains("Haut-parleurs") || sName.Contains("Speakers"))
        {
            object buttonPattern = null;
            if (aeChild.TryGetCurrentPattern(InvokePattern.Pattern, out buttonPattern))
            {
                System.Threading.Thread.Sleep(100);
                ((InvokePattern)buttonPattern).Invoke();
            }
        }
    }

    Declarations :

            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    • Marked as answer by at19AV20 Wednesday, March 18, 2020 3:17 PM
    Wednesday, March 18, 2020 2:25 PM
  • Thanks a lot!

    Just a small question - does it work if my taskbar in hidden with

    int intReturn = FindWindow("Shell_traywnd", "");
    SetWindowPos(intReturn, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
    ?

    Wednesday, March 18, 2020 3:18 PM
  • Thanks a lot!

    Just a small question - does it work if my taskbar in hidden with

    int intReturn = FindWindow("Shell_traywnd", "");
    SetWindowPos(intReturn, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
    ?

    No...

    But you should not hide the Taskbar this way.

    The properties of the Taskbar can be managed with SHAppBarMessage

    Wednesday, March 18, 2020 3:51 PM
  • I see. Thanks!
    Wednesday, March 18, 2020 3:54 PM