//Updates the Form's display using API calls
        public void UpdateFormDisplay(Image backgroundImage)
        {
            IntPtr screenDc = API.GetDC(IntPtr.Zero);
            IntPtr memDc = API.CreateCompatibleDC(screenDc);
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                //Display-image
                Bitmap bmp = new Bitmap(backgroundImage);
                hBitmap = bmp.GetHbitmap(Color.FromArgb(0));  //Set the fact that background is transparent
                oldBitmap = API.SelectObject(memDc, hBitmap);

                //Display-rectangle
                Size size = bmp.Size;
                Point pointSource = new Point(0, 0);
                Point topPos = new Point(this.Left, this.Top);

                //Set up blending options
                API.BLENDFUNCTION blend = new API.BLENDFUNCTION();
                blend.BlendOp = API.AC_SRC_OVER;
                blend.BlendFlags = 0;
                blend.SourceConstantAlpha = 255;
                blend.AlphaFormat = API.AC_SRC_ALPHA;

                API.UpdateLayeredWindow(this.Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, API.ULW_ALPHA);

                //Clean-up
                bmp.Dispose();
                API.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    API.SelectObject(memDc, oldBitmap);
                    API.DeleteObject(hBitmap);
                }
                API.DeleteDC(memDc);
            }
            catch (Exception)
            {
            }
        }
        //Updates the Form's display using API calls
        public void UpdateFormDisplay(Image backgroundImage)
        {
            IntPtr screenDc  = API.GetDC(IntPtr.Zero);
            IntPtr memDc     = API.CreateCompatibleDC(screenDc);
            IntPtr hBitmap   = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                //Display-image
                Bitmap bmp = new Bitmap(backgroundImage);
                hBitmap   = bmp.GetHbitmap(Color.FromArgb(0)); //Set the fact that background is transparent
                oldBitmap = API.SelectObject(memDc, hBitmap);

                //Display-rectangle
                Size  size        = bmp.Size;
                Point pointSource = new Point(0, 0);
                Point topPos      = new Point(this.Left, this.Top);

                //Set up blending options
                API.BLENDFUNCTION blend = new API.BLENDFUNCTION();
                blend.BlendOp             = API.AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = 255;
                blend.AlphaFormat         = API.AC_SRC_ALPHA;

                API.UpdateLayeredWindow(this.Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, API.ULW_ALPHA);

                //Clean-up
                bmp.Dispose();
                API.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    API.SelectObject(memDc, oldBitmap);
                    API.DeleteObject(hBitmap);
                }
                API.DeleteDC(memDc);
            }
            catch (Exception)
            {
            }
        }
Exemple #3
0
        //Updates the Form's display using API calls
        public void UpdateFormDisplay(Image backgroundImage)
        {
            IntPtr screenDc = API.GetDC(IntPtr.Zero);
            IntPtr memDc    = API.CreateCompatibleDC(screenDc);
            IntPtr hBitmap;
            IntPtr oldBitmap;

            try
            {
                //Display-image
                Bitmap   bmp = new Bitmap(backgroundImage);
                Graphics g   = Graphics.FromImage(bmp);

                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                var brushc = new System.Drawing.SolidBrush(Color.FromArgb(255, 255, 255, 255));
                if (counter != 0)
                {
                    List <string> temp     = Currentcountdown();
                    double        timeleft = Int32.Parse(temp[0]);
                    if (temp[2] == "End")
                    {
                        counter = 0;
                    }

                    string hours;
                    string minutes;
                    string seconds;
                    if (Math.Floor(timeleft / 3600) < 10)
                    {
                        hours     = "0" + (Math.Floor(timeleft / 3600));
                        timeleft %= 3600;
                    }
                    else
                    {
                        hours     = (Math.Floor(timeleft / 3600)).ToString();
                        timeleft %= 3600;
                    }

                    if (Math.Floor(timeleft / 60) < 10)
                    {
                        minutes = "0" + (Math.Floor(timeleft / 60));
                    }
                    else
                    {
                        minutes = (Math.Floor(timeleft / 60)).ToString();
                    }

                    if (Math.Floor(timeleft % 60) < 10)
                    {
                        seconds = "0" + (timeleft % 60);
                    }
                    else
                    {
                        seconds = (timeleft % 60).ToString();
                    }

                    g.DrawString(hours + ":" + minutes + ":" + seconds, new Font("Trebuchet MS", 18 * dx), brushc, 10,
                                 40);
                    g.DrawString(
                        Program.TimetableList.ContainsKey(Program.curDay + "" + temp[2].Substring(temp[2].Length - 1))
                            ? Program.TimetableList[Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)].Room
                            : "", new Font("Trebuchet MS", 18 * dx), brushc, 140, 40);
                    string label = temp[2];
                    if ((temp[2].StartsWith("Period") || temp[2].StartsWith("Form")) &&
                        Program.TimetableList.ContainsKey(Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)))
                    {
                        label =
                            Program.TimetableList[Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)]
                            .ClassDescription.Length > 12
                                ? Program.TimetableList[Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)]
                            .ClassCode
                                : Program.TimetableList[Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)]
                            .ClassDescription;
                    }
                    if (temp[2].StartsWith("Go to") &&
                        Program.TimetableList.ContainsKey(Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)))
                    {
                        label = "Go to " + Program
                                .TimetableList[Program.curDay + "" + temp[2].Substring(temp[2].Length - 1)]
                                .ClassCode;
                    }
                    g.DrawString(label, new Font("Trebuchet MS", 14 * dx), brushc, 10, 2);
                    StringFormat stringFormat = new StringFormat();
                    stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                    g.RotateTransform(-90);
                    string k = "Day " + Program.curDay;
                    g.DrawString(k, new Font("Trebuchet MS", 8 * dx), brushc, -63, 2);
                    stringFormat.Dispose();
                }

                hBitmap   = bmp.GetHbitmap(Color.FromArgb(0)); //Set the fact that background is transparent
                oldBitmap = API.SelectObject(memDc, hBitmap);

                //Display-rectangle
                Size  size        = bmp.Size;
                Point pointSource = new Point(0, 0);
                Point topPos      = new Point(Left, Top);

                //Set up blending options
                API.BLENDFUNCTION blend = new API.BLENDFUNCTION();
                blend.BlendOp             = API.AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = Convert.ToByte(counter);
                blend.AlphaFormat         = API.AC_SRC_ALPHA;

                API.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, API.ULW_ALPHA);

                //Clean-up
                brushc.Dispose();
                g.Dispose();
                bmp.Dispose();
                API.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    API.SelectObject(memDc, oldBitmap);
                    API.DeleteObject(hBitmap);
                }
                API.DeleteDC(memDc);
            }
            catch (Exception)
            {
                // ignored
            }
        }