示例#1
0
        protected void OnThumbnail(uint width, uint height)
        {
            this.thumbBoxSize = height;
            Bitmap temp = GenerateScaledBitmap(this.pictureBitmap, width, height);

            ThumbnailAPI.DwmSetIconicThumbnail(this.Handle, temp.GetHbitmap(), 0);
        }
示例#2
0
        protected void OnLivePreview(uint width, uint height)
        {
            if (0 >= width || 0 >= height)
            {
                width  = this.thumbBoxSize;
                height = this.thumbBoxSize;
            }
            Bitmap temp = GenerateScaledBitmap(this.pictureBitmap, width, height);

            ThumbnailAPI.DwmSetIconicLivePreviewBitmap(this.Handle, temp.GetHbitmap(), IntPtr.Zero, 0);
        }
示例#3
0
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            // Get a handle to a copy of this form's system (window) menu.
            IntPtr hSysMenu = ThumbnailAPI.GetSystemMenu(this.Handle, false);

            ThumbnailAPI.AppendMenu(hSysMenu, ThumbnailAPI.MF_SEPARATOR, 0, string.Empty);
            ThumbnailAPI.AppendMenu(hSysMenu, ThumbnailAPI.MF_STRING, SYSMENU_REFRESH_ID, "&Refresh");
            ThumbnailAPI.AppendMenu(hSysMenu, ThumbnailAPI.MF_SEPARATOR, 0, string.Empty);
            ThumbnailAPI.AppendMenu(hSysMenu, ThumbnailAPI.MF_STRING, SYSMENU_OPTIONS_ID, "&Options…");
            ThumbnailAPI.AppendMenu(hSysMenu, ThumbnailAPI.MF_STRING, SYSMENU_WUNDERGROUND_ID, "Open &Wunderground…");
        }
示例#4
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch (m.Msg)
            {
            case ThumbnailAPI.WM_SYSCOMMAND:
                this.OnCommand((int)m.WParam);
                break;

            case ThumbnailAPI.WM_DWMSENDICONICTHUMBNAIL:
                this.OnThumbnail(ThumbnailAPI.HIWORD((uint)m.LParam), ThumbnailAPI.LOWORD((uint)m.LParam));
                break;

            case ThumbnailAPI.WM_DWMSENDICONICLIVEPREVIEWBITMAP:
                this.OnLivePreview(ThumbnailAPI.HIWORD((uint)m.LParam), ThumbnailAPI.LOWORD((uint)m.LParam));
                break;
            }

            base.WndProc(ref m);
        }
示例#5
0
        public WeatherThumb()
        {
            InitializeComponent();

            int iTrue = 1;

            ThumbnailAPI.DwmSetWindowAttribute(
                this.Handle,
                ThumbnailAPI.DWMWINDOWATTRIBUTE.DWMWA_FORCE_ICONIC_REPRESENTATION,
                ref iTrue,
                sizeof(int)
                );
            ThumbnailAPI.DwmSetWindowAttribute(
                this.Handle,
                ThumbnailAPI.DWMWINDOWATTRIBUTE.DWMWA_HAS_ICONIC_BITMAP,
                ref iTrue,
                sizeof(int)
                );

            this.UpdateZipCode();
        }
示例#6
0
        public void UpdateWeather()
        {
            WeatherResponse response = checker.GetWeather();

            Bitmap iconBitmap = GetWeatherBitmap(response.Conditions);

            iconBitmap.MakeTransparent();
            Bitmap iconComplete;

            using (Graphics g = Graphics.FromImage(iconBitmap)) {
                Font  tempFont = new Font("Arial", 64);
                SizeF tempSize = g.MeasureString(response.Temperature, tempFont);
                iconComplete = new Bitmap(iconBitmap.Width + tempFont.Height, iconBitmap.Height + tempFont.Height, PixelFormat.Format32bppRgb);
                using (Graphics cg = Graphics.FromImage(iconComplete)) {
                    cg.FillRectangle(
                        this.backgroundColor,
                        new Rectangle(
                            0,
                            0,
                            iconComplete.Width,
                            iconComplete.Height
                            )
                        );
                    cg.DrawImageUnscaled(
                        iconBitmap,
                        new Point((iconComplete.Width / 2) - (iconBitmap.Width / 2), 0)
                        );

                    /*
                     * cg.FillRectangle(
                     *  this.backgroundColor,
                     *  new Rectangle(
                     *      0,
                     *      iconComplete.Height - (int)tempSize.Height,
                     *      iconComplete.Width,
                     *      (int)tempSize.Height
                     *  )
                     * );
                     */
                    cg.DrawString(
                        response.Temperature,
                        tempFont,
                        Brushes.Black,
                        new Point(
                            (iconComplete.Width / 2) - ((int)tempSize.Width / 2),
                            iconComplete.Height - (int)tempSize.Height
                            )
                        );
                }
            }

            this.pictureBitmap = new Bitmap(iconComplete);

            //iconComplete.MakeTransparent();
            IntPtr hBitmap = ThumbnailAPI.MakeIcon(iconComplete, 128, true);

            this.Icon = Icon.FromHandle(hBitmap);
            //ThumbnailAPI.DestroyIcon( hBitmap );

            this.Text = response.ConditionsRaw;

            //this.pictureBitmap = GetWeatherBitmap( response.Conditions );
            //this.pictureBitmap.MakeTransparent();

            ThumbnailAPI.DwmInvalidateIconicBitmaps(this.Handle);
            this.Invalidate();
            this.Update();
            this.Refresh();
            Application.DoEvents();
        }