DrawAnimatedRects() private method

private DrawAnimatedRects ( IntPtr hWnd, int idAni, RECT &lprcFrom, RECT &lprcTo ) : bool
hWnd System.IntPtr
idAni int
lprcFrom RECT
lprcTo RECT
return bool
Example #1
0
        internal static void TrayAnimate(Form form, bool down)
        {
            StringBuilder className   = new StringBuilder(255);
            IntPtr        taskbarHwnd = default(IntPtr);
            IntPtr        trayHwnd    = default(IntPtr);

            // Get taskbar handle
            taskbarHwnd = NativeMethods.FindWindow("Shell_traywnd", null);

            if (taskbarHwnd == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            // Get system tray handle
            trayHwnd = NativeMethods.GetWindow(taskbarHwnd, NativeMethods.GW_CHILD);

            do
            {
                if (trayHwnd == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }

                if (NativeMethods.GetClassName(trayHwnd, className, className.Capacity) == 0)
                {
                    throw new Win32Exception();
                }

                if (className.ToString() == "TrayNotifyWnd")
                {
                    break;
                }

                trayHwnd = NativeMethods.GetWindow(trayHwnd, NativeMethods.GW_HWNDNEXT);
            }while (true);

            NativeMethods.RECT systray = default(NativeMethods.RECT);
            NativeMethods.RECT window  = default(NativeMethods.RECT);

            // Fetch the location of the systray from its window handle
            if (!NativeMethods.GetWindowRect(trayHwnd, ref systray))
            {
                throw new Win32Exception();
            }

            // Fetch the location of the window from its window handle
            if (!NativeMethods.GetWindowRect(form.Handle, ref window))
            {
                throw new Win32Exception();
            }

            // Perform the animation
            if (down)
            {
                if (!NativeMethods.DrawAnimatedRects(form.Handle, NativeMethods.IDANI_CAPTION, ref window, ref systray))
                {
                    throw new Win32Exception();
                }
            }
            else
            {
                if (!NativeMethods.DrawAnimatedRects(form.Handle, NativeMethods.IDANI_CAPTION, ref systray, ref window))
                {
                    throw new Win32Exception();
                }
            }
        }