Ejemplo n.º 1
0
        new public void Update()
        {
            if (bitmap == null)
            {
                bitmap = new Bitmap(tb.Bounds.Width, tb.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }

            //bitmap = new Bitmap(W, H, PixelFormat.Format32bppArgb);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;

                g.FillRectangle(background, 0, 0, tb.Bounds.Width, tb.Bounds.Height);

                if (tb.Position == TaskbarPosition.Bottom)
                {
                    g.DrawLine(edge, 0, 0, tb.Bounds.Width, 0);
                }
                else if (tb.Position == TaskbarPosition.Top)
                {
                    g.DrawLine(edge, 0, tb.Bounds.Height - 1, tb.Bounds.Width, tb.Bounds.Height - 1);
                }
                else if (tb.Position == TaskbarPosition.Left)
                {
                    g.DrawLine(edge, tb.Bounds.Width - 1, 0, tb.Bounds.Width - 1, tb.Bounds.Height - 1);
                }
                else if (tb.Position == TaskbarPosition.Right)
                {
                    g.DrawLine(edge, 0, 0, 0, tb.Bounds.Height - 1);
                }

                //g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                //int midy = (int)Math.Round(tb.Bounds.Height / 2f);
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                if (tb.Position == TaskbarPosition.Bottom || tb.Position == TaskbarPosition.Top)
                {
                    string    time         = DateTime.Now.ToString("h:mm:ss tt");
                    Rectangle textbounds   = new Rectangle(42, 0, tb.Bounds.Width - 52, tb.Bounds.Height);
                    Rectangle shadowbounds = new Rectangle(42, 1, tb.Bounds.Width - 52, tb.Bounds.Height);
                    TextRenderer.DrawText(g, "SecureDesktop", font, shadowbounds, shadow, (TextFormatFlags.VerticalCenter | TextFormatFlags.Left));
                    TextRenderer.DrawText(g, "SecureDesktop", font, textbounds, Color.White, (TextFormatFlags.VerticalCenter | TextFormatFlags.Left));

                    TextRenderer.DrawText(g, time, font, shadowbounds, shadow, (TextFormatFlags.VerticalCenter | TextFormatFlags.Right));
                    TextRenderer.DrawText(g, time, font, textbounds, Color.White, (TextFormatFlags.VerticalCenter | TextFormatFlags.Right));

                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                    g.DrawImage(Properties.Resources.lock_icon, 5, (int)Math.Round(tb.Bounds.Height / 2f - Properties.Resources.lock_icon.Size.Height / 2f));
                }
                else
                {
                    string    time         = DateTime.Now.ToString("h:mm tt");
                    Rectangle textbounds   = new Rectangle(0, 42, tb.Bounds.Width, tb.Bounds.Height - 52);
                    Rectangle shadowbounds = new Rectangle(0, 43, tb.Bounds.Width, tb.Bounds.Height - 52);
                    TextRenderer.DrawText(g, "Secure Desktop", font, shadowbounds, shadow, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Top | TextFormatFlags.WordBreak));
                    TextRenderer.DrawText(g, "Secure Desktop", font, textbounds, Color.White, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Top | TextFormatFlags.WordBreak));

                    TextRenderer.DrawText(g, time, font, shadowbounds, shadow, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom | TextFormatFlags.WordBreak));
                    TextRenderer.DrawText(g, time, font, textbounds, Color.White, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom | TextFormatFlags.WordBreak));



                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                    g.DrawImage(Properties.Resources.lock_icon, (int)Math.Round(tb.Bounds.Width / 2f - Properties.Resources.lock_icon.Size.Width / 2f), 5);
                }
            }

            IntPtr screenDc  = WinAPI.GetDC(IntPtr.Zero);
            IntPtr memDc     = WinAPI.CreateCompatibleDC(screenDc);
            IntPtr hBitmap   = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                hBitmap   = bitmap.GetHbitmap(Color.FromArgb(0));
                oldBitmap = WinAPI.SelectObject(memDc, hBitmap);

                Size  size                 = new Size(bitmap.Width, bitmap.Height);
                Point pointSource          = new Point(0, 0);
                Point topPos               = new Point(tb.Bounds.Left, tb.Bounds.Top);
                WinAPI.BLENDFUNCTION blend = new WinAPI.BLENDFUNCTION();
                blend.BlendOp             = WinAPI.AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = 0xFF;
                blend.AlphaFormat         = WinAPI.AC_SRC_ALPHA;

                WinAPI.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, WinAPI.ULW_ALPHA);
            }
            finally
            {
                WinAPI.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    WinAPI.SelectObject(memDc, oldBitmap);
                    WinAPI.DeleteObject(hBitmap);
                }
                WinAPI.DeleteDC(memDc);

                //WinAPI.SetWindowPos(this.Handle, WinAPI.HWND_TOPMOST, 0, 0, 0, 0, WinAPI.SWP_NOMOVE | WinAPI.SWP_NOSIZE | WinAPI.SWP_SHOWWINDOW);
            }
        }
Ejemplo n.º 2
0
        new public void Update()
        {
            if (bitmap == null) bitmap = new Bitmap(tb.Bounds.Width, tb.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            //bitmap = new Bitmap(W, H, PixelFormat.Format32bppArgb);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;

                g.FillRectangle(background, 0, 0, tb.Bounds.Width, tb.Bounds.Height);

                if(tb.Position == TaskbarPosition.Bottom)
                    g.DrawLine(edge, 0, 0, tb.Bounds.Width, 0);
                else if (tb.Position == TaskbarPosition.Top)
                    g.DrawLine(edge, 0, tb.Bounds.Height - 1, tb.Bounds.Width, tb.Bounds.Height - 1);
                else if (tb.Position == TaskbarPosition.Left)
                    g.DrawLine(edge, tb.Bounds.Width - 1, 0, tb.Bounds.Width - 1, tb.Bounds.Height - 1);
                else if (tb.Position == TaskbarPosition.Right)
                    g.DrawLine(edge, 0, 0, 0, tb.Bounds.Height - 1);

                //g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                //int midy = (int)Math.Round(tb.Bounds.Height / 2f);
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                if (tb.Position == TaskbarPosition.Bottom || tb.Position == TaskbarPosition.Top)
                {
                    string time = DateTime.Now.ToString("h:mm:ss tt");
                    Rectangle textbounds = new Rectangle(42, 0, tb.Bounds.Width - 52, tb.Bounds.Height);
                    Rectangle shadowbounds = new Rectangle(42, 1, tb.Bounds.Width - 52, tb.Bounds.Height);
                    TextRenderer.DrawText(g, "SecureDesktop", font, shadowbounds, shadow, (TextFormatFlags.VerticalCenter | TextFormatFlags.Left));
                    TextRenderer.DrawText(g, "SecureDesktop", font, textbounds, Color.White, (TextFormatFlags.VerticalCenter | TextFormatFlags.Left));

                    TextRenderer.DrawText(g, time, font, shadowbounds, shadow, (TextFormatFlags.VerticalCenter | TextFormatFlags.Right));
                    TextRenderer.DrawText(g, time, font, textbounds, Color.White, (TextFormatFlags.VerticalCenter | TextFormatFlags.Right));

                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                    g.DrawImage(Properties.Resources.lock_icon, 5, (int)Math.Round(tb.Bounds.Height / 2f - Properties.Resources.lock_icon.Size.Height / 2f));
                }
                else
                {
                    string time = DateTime.Now.ToString("h:mm tt");
                    Rectangle textbounds = new Rectangle(0, 42, tb.Bounds.Width, tb.Bounds.Height - 52);
                    Rectangle shadowbounds = new Rectangle(0, 43, tb.Bounds.Width, tb.Bounds.Height - 52);
                    TextRenderer.DrawText(g, "Secure Desktop", font, shadowbounds, shadow, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Top | TextFormatFlags.WordBreak));
                    TextRenderer.DrawText(g, "Secure Desktop", font, textbounds, Color.White, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Top | TextFormatFlags.WordBreak));

                    TextRenderer.DrawText(g, time, font, shadowbounds, shadow, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom | TextFormatFlags.WordBreak));
                    TextRenderer.DrawText(g, time, font, textbounds, Color.White, (TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom | TextFormatFlags.WordBreak));



                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                    g.DrawImage(Properties.Resources.lock_icon, (int)Math.Round(tb.Bounds.Width / 2f - Properties.Resources.lock_icon.Size.Width / 2f), 5);
                }
            }

            IntPtr screenDc = WinAPI.GetDC(IntPtr.Zero);
            IntPtr memDc = WinAPI.CreateCompatibleDC(screenDc);
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
                oldBitmap = WinAPI.SelectObject(memDc, hBitmap);

                Size size = new Size(bitmap.Width, bitmap.Height);
                Point pointSource = new Point(0, 0);
                Point topPos = new Point(tb.Bounds.Left, tb.Bounds.Top);
                WinAPI.BLENDFUNCTION blend = new WinAPI.BLENDFUNCTION();
                blend.BlendOp = WinAPI.AC_SRC_OVER;
                blend.BlendFlags = 0;
                blend.SourceConstantAlpha = 0xFF;
                blend.AlphaFormat = WinAPI.AC_SRC_ALPHA;

                WinAPI.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, WinAPI.ULW_ALPHA);
            }
            finally
            {
                WinAPI.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    WinAPI.SelectObject(memDc, oldBitmap);
                    WinAPI.DeleteObject(hBitmap);
                }
                WinAPI.DeleteDC(memDc);

                //WinAPI.SetWindowPos(this.Handle, WinAPI.HWND_TOPMOST, 0, 0, 0, 0, WinAPI.SWP_NOMOVE | WinAPI.SWP_NOSIZE | WinAPI.SWP_SHOWWINDOW);
            }
        }