示例#1
0
        private DwmForm GetDwmForm(Form form)
        {
            if (_form == null)
            {
                _form = new DwmForm(this, form);
            }
            else if (_form.Form != form)
            {
                throw new InvalidOperationException(Resources.Strings.DwmEffectProviderOnlyOneForm);
            }

            return(_form);
        }
示例#2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if ((_form != null) && (_form.Filter != null))
                {
                    _form.Filter.Dispose();
                }
            }

            _form = null;

            base.Dispose(disposing);
        }
示例#3
0
        public static void InstallScript(String filename)
        {
            IntPtr ptr = Process.GetCurrentProcess().MainWindowHandle;

            if (!ptr.Equals(IntPtr.Zero))
            {
                DwmForm control = (DwmForm)DwmForm.FromHandle(ptr);

                if (control != null)
                {
                    InstallScript(control, filename);
                }
            }
        }
示例#4
0
 public TaskBarProgress(DwmForm f)
 {
     this.Owner = f;
     this.Color = TaskBarProgressColor.Green;
 }
 public PreviewToolStripContainer(DwmForm f)
 {
     this.Items = new List <PreviewToolStripItem>();
     this.Owner = f;
 }
示例#6
0
 public OverlayIcon(DwmForm f)
 {
     this.Owner = f;
 }
示例#7
0
            private static FrameHitTestResult DefaultHitTest(DwmForm form, Point point)
            {
                var window = form.Form.Bounds;
                var frame  = new RECT();

                if (!NativeMethods.AdjustWindowRectEx(
                        ref frame,
                        WindowStyles.WS_OVERLAPPEDWINDOW & ~WindowStyles.WS_CAPTION,
                        false,
                        0))
                {
                    throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
                }

                int  row    = 1;
                int  col    = 1;
                bool resize = false;

                if (point.Y >= window.Top && point.Y < window.Top + form.FrameExtent.Top)
                {
                    row    = 0;
                    resize = point.Y < (window.Top - frame.Top);
                }
                else if (point.Y < window.Bottom && point.Y >= window.Bottom - form.FrameExtent.Bottom)
                {
                    row = 2;
                }

                if (point.X >= window.Left && point.X < window.Left + form.FrameExtent.Left)
                {
                    col = 0;
                }
                else if (point.X < window.Right && point.X >= window.Right - form.FrameExtent.Right)
                {
                    col = 2;
                }

                var results = new FrameHitTestResult[][]
                {
                    new FrameHitTestResult[]
                    {
                        FrameHitTestResult.TopLeft,
                        (resize ? FrameHitTestResult.Top : FrameHitTestResult.Caption),
                        FrameHitTestResult.TopRight
                    },
                    new FrameHitTestResult[]
                    {
                        FrameHitTestResult.Left,
                        FrameHitTestResult.Nowhere,
                        FrameHitTestResult.Right
                    },
                    new FrameHitTestResult[]
                    {
                        FrameHitTestResult.BottomLeft,
                        FrameHitTestResult.Bottom,
                        FrameHitTestResult.BottomRight
                    }
                };

                return(results[row][col]);
            }
示例#8
0
 public DwmMessageFilter(DwmEffectProvider owner, DwmForm form)
     : base(form.Form)
 {
     _owner = owner;
     _form  = form;
 }
示例#9
0
        private static void InstallScript(DwmForm form, String filename)
        {
            if (form.InvokeRequired)
            {
                form.BeginInvoke(new InstallScriptHandler(InstallScript), form, filename);
            }
            else
            {
                if (!form.Visible)
                {
                    form.Show();
                }

                if (form.WindowState == FormWindowState.Minimized)
                {
                    form.WindowState = FormWindowState.Normal;
                }

                form.Activate();

                if (Settings.IsAway)
                {
                    if (form.OverlayIcon != null)
                    {
                        form.OverlayIcon.Show();
                    }
                }

                DialogResult result = MessageBox.Show(form,
                                                      "Confirm you would like to install the script: " + filename,
                                                      "cb0t script installer",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    bool install_success = false;

                    try
                    {
                        String     url     = "http://chatrooms.marsproject.net/cb0t/" + filename;
                        byte[]     data    = null;
                        WebRequest request = WebRequest.Create(url);

                        using (WebResponse response = request.GetResponse())
                            using (Stream stream = response.GetResponseStream())
                            {
                                List <byte> list   = new List <byte>();
                                int         size   = 0;
                                byte[]      buffer = new byte[1024];

                                while ((size = stream.Read(buffer, 0, 1024)) > 0)
                                {
                                    list.AddRange(buffer.Take(size));
                                }

                                if (list.Count > 0)
                                {
                                    data = list.ToArray();
                                }
                            }

                        if (data != null)
                        {
                            data = Zip.Decompress(data);

                            if (data != null)
                            {
                                if (data.Length > 0)
                                {
                                    TCPPacketReader reader   = new TCPPacketReader(data);
                                    String          dir_path = Path.Combine(Settings.ScriptPath, filename);

                                    if (!Directory.Exists(dir_path))
                                    {
                                        Directory.CreateDirectory(dir_path);
                                    }

                                    String data_path = Path.Combine(dir_path, "data");

                                    if (!Directory.Exists(data_path))
                                    {
                                        Directory.CreateDirectory(data_path);
                                    }

                                    while (reader.Remaining > 0)
                                    {
                                        String name   = reader.ReadString();
                                        byte   type   = reader;
                                        uint   size   = reader;
                                        byte[] buffer = reader.ReadBytes((int)size);

                                        if (type == 1)
                                        {
                                            File.WriteAllBytes(Path.Combine(data_path, name), buffer);
                                        }
                                        else if (type == 0)
                                        {
                                            File.WriteAllBytes(Path.Combine(dir_path, name), buffer);
                                        }
                                    }

                                    AddToAutoLoad(filename);
                                    install_success = true;
                                }
                            }
                        }
                    }
                    catch { }

                    if (install_success)
                    {
                        MessageBox.Show(form,
                                        filename + " was installed successfully.  Please complete the installation by restarting cb0t now.",
                                        "cb0t script installer",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(form,
                                        filename + " was unable to be installed at this time.",
                                        "cb0t script installer",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }