コード例 #1
0
        // Change the taskbar
        private bool UpdateTaskbar(AccentPolicy accent)
        {
            // Get size of struct
            var accentStructSize = Marshal.SizeOf(accent);
            var accentPtr = Marshal.AllocHGlobal(accentStructSize);
            Marshal.StructureToPtr(accent, accentPtr, false);

            // Construct data parameter
            var data = new WindowCompositionAttributeData();
            data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
            data.SizeOfData = accentStructSize;
            data.Data = accentPtr;

            // Get all processes 
            Process[] explorerProcesses = Process.GetProcessesByName("explorer");

            // Taskbar will be the first process
            IntPtr hWnd = explorerProcesses[0].MainWindowHandle;

            // Check if function executes
            if (SetWindowCompositionAttribute(hWnd, ref data))
            {
                // Free memory associated with accentPtr
                Marshal.FreeHGlobal(accentPtr);
                return true;
            }
            else
            {
                return false;
            }
        }
コード例 #2
0
 internal static extern bool GetWindowCompositionAttribute(IntPtr point, ref WindowCompositionAttributeData data);
コード例 #3
0
        ///////////////////////////////////////////////////////
        ////                  METHODS                     /////
        ///////////////////////////////////////////////////////

        // Update current parameters
        public void UpdateParameters()
        {
            // Variable for our new accent policy
            var newAccentPolicy = new AccentPolicy();

            
            // Get size of struct
            var accentStructSize = 1024;
            var accentPtr = Marshal.AllocHGlobal(accentStructSize);
            Marshal.StructureToPtr(newAccentPolicy, accentPtr, false);

            // Construct data parameter
            var data = new WindowCompositionAttributeData();
            data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
            data.SizeOfData = accentStructSize;
            data.Data = accentPtr;
            Console.WriteLine("Before: {0} {1} {2}", data.Data, data.SizeOfData, data.Attribute);

            // Get all processes 
            Process[] explorerProcesses = Process.GetProcessesByName("explorer");

            Console.WriteLine("Logic: {0} {1}", explorerProcesses[0].ProcessName, explorerProcesses[0].Id);
            IntPtr hWnd = explorerProcesses[0].MainWindowHandle;

            try {
                // Check if function executes
                GetWindowCompositionAttribute(hWnd, ref data);

                Console.WriteLine("After: {0} {1} {2}", data.Data, data.SizeOfData, data.Attribute);

            } catch (Exception e) {
                Console.WriteLine("Error occurred: {0}", e);
            } finally
            {
                // Free memory associated with accentPtr
                //Marshal.FreeHGlobal(accentPtr);
            }


        }