コード例 #1
0
        internal static int DwmExtendFrameIntoClientArea(IntPtr hWnd,
                                                         ref WindowsMargins
                                                         pMarInset)
        {
            IntPtr dwmDll = LoadLibrary("dwmapi.dll");

            if (dwmDll == IntPtr.Zero)
            {
                return(Marshal.GetLastWin32Error());
            }
            IntPtr dwmFunction = GetProcAddress(dwmDll,
                                                "DwmExtendFrameIntoClientArea");

            if (dwmFunction == IntPtr.Zero)
            {
                return(Marshal.GetLastWin32Error());
            }
            var call =
                (DwmExtendFrameIntoClientAreaDelegate)
                Marshal.GetDelegateForFunctionPointer(dwmFunction,
                                                      typeof(
                                                          DwmExtendFrameIntoClientAreaDelegate
                                                          ));
            int result = call(hWnd, ref pMarInset);

            FreeLibrary(dwmDll);
            return(result);
        }
コード例 #2
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_HOTKEY)
            {
                ScreenshotTask info = GetParamteresFromUI(true);
                _worker = new Thread(() => Screenshot.CaptureWindow(ref info))
                {
                    IsBackground = true
                };
                _worker.SetApartmentState(ApartmentState.STA);
                _worker.Start();
            }
            if (m.Msg == WM_DWMCOMPOSITIONCHANGED)
            {
                WindowsApi.DwmIsCompositionEnabled(ref _dwmComposited);

                if (_dwmComposited)
                {
                    ssButton.Location = new Point(ssButton.Location.X, 310);
                    var margin = new WindowsMargins(0, 0, 0, 35);
                    WindowsApi.DwmExtendFrameIntoClientArea(Handle, ref margin);
                }
                else
                {
                    ssButton.Location = new Point(ssButton.Location.X, 305);
                }
            }
        }
コード例 #3
0
        public MainForm()
        {
            DoubleBuffered = true;
            Icon           = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            InitializeComponent();

            if (WindowsApi.DwmIsCompositionEnabled(ref _dwmComposited) == 0)
            {
                if (_dwmComposited)
                {
                    ssButton.Location = new Point(ssButton.Location.X, 310);
                    var margin = new WindowsMargins(0, 0, 0, 35);
                    WindowsApi.DwmExtendFrameIntoClientArea(Handle, ref margin);
                }
            }

            _windowId = GetHashCode();
            WindowsApi.RegisterHotKey(Handle, _windowId, MOD_ALT,
                                      (int)Keys.PrintScreen);

            object value;

            _registryKey =
                Registry.CurrentUser.CreateSubKey(@"Software\AeroShot");
            if ((value = _registryKey.GetValue("LastPath")) != null &&
                value.GetType() == (typeof(string)))
            {
                if (((string)value).Substring(0, 1) == "*")
                {
                    folderTextBox.Text      = ((string)value).Substring(1);
                    clipboardButton.Checked = true;
                }
                else
                {
                    folderTextBox.Text = (string)value;
                    diskButton.Checked = true;
                }
            }
            else
            {
                folderTextBox.Text =
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }

            if ((value = _registryKey.GetValue("WindowSize")) != null &&
                value.GetType() == (typeof(long)))
            {
                var b = new byte[8];
                for (int i = 0; i < 8; i++)
                {
                    b[i] = (byte)(((long)value >> (i * 8)) & 0xff);
                }
                resizeCheckbox.Checked = (b[0] & 1) == 1;
                windowWidth.Value      = b[1] << 16 | b[2] << 8 | b[3];
                windowHeight.Value     = b[4] << 16 | b[5] << 8 | b[6];
            }

            if ((value = _registryKey.GetValue("Opaque")) != null &&
                value.GetType() == (typeof(long)))
            {
                var b = new byte[8];
                for (int i = 0; i < 8; i++)
                {
                    b[i] = (byte)(((long)value >> (i * 8)) & 0xff);
                }
                opaqueCheckbox.Checked = (b[0] & 1) == 1;
                if ((b[0] & 2) == 2)
                {
                    opaqueType.SelectedIndex = 0;
                }
                if ((b[0] & 4) == 4)
                {
                    opaqueType.SelectedIndex = 1;
                }

                checkerValue.Value = b[1] + 2;

                var hex = new StringBuilder(6);
                hex.AppendFormat("{0:X2}", b[2]);
                hex.AppendFormat("{0:X2}", b[3]);
                hex.AppendFormat("{0:X2}", b[4]);
                colourHexBox.Text = hex.ToString();
            }
            else
            {
                opaqueType.SelectedIndex = 0;
            }
            if ((value = _registryKey.GetValue("CapturePointer")) != null &&
                value.GetType() == (typeof(int)))
            {
                mouseCheckbox.Checked = ((int)value & 1) == 1;
            }

            groupBox1.Enabled = resizeCheckbox.Checked;
            groupBox2.Enabled = opaqueCheckbox.Checked;
            groupBox3.Enabled = mouseCheckbox.Checked;

            _ssButtonImage = Resources.capture;
        }
コード例 #4
0
ファイル: Dwmapi.cs プロジェクト: dbremner/aeroshot
 internal static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd,
     ref WindowsMargins
         pMarInset);
コード例 #5
0
ファイル: Main.cs プロジェクト: dbremner/aeroshot
        public MainForm() {
            DoubleBuffered = true;
            Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            InitializeComponent();

            _dwmComposited = Dwm.IsCompositionEnabled;
            if (_dwmComposited) {
                ssButton.Location = new Point(ssButton.Location.X, 310);
                var margin = new WindowsMargins(0, 0, 0, 35);
                NativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margin);
            }

            _windowId = GetHashCode();
            NativeMethods.RegisterHotKey(Handle, _windowId, MOD_ALT,
                                      (int) Keys.PrintScreen);

            object value;
            _registryKey =
                Registry.CurrentUser.CreateSubKey(@"Software\AeroShot");
            if ((value = _registryKey.GetValue("LastPath")) != null &&
                value.GetType() == (typeof (string))) {
                if (((string) value).Substring(0, 1) == "*") {
                    folderTextBox.Text = ((string) value).Substring(1);
                    clipboardButton.Checked = true;
                } else {
                    folderTextBox.Text = (string) value;
                    diskButton.Checked = true;
                }
            } else {
                folderTextBox.Text =
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }

            if ((value = _registryKey.GetValue("WindowSize")) != null &&
                value.GetType() == (typeof (long))) {
                var b = new byte[8];
                for (int i = 0; i < 8; i++)
                    b[i] = (byte) (((long) value >> (i*8)) & 0xff);
                resizeCheckbox.Checked = (b[0] & 1) == 1;
                windowWidth.Value = b[1] << 16 | b[2] << 8 | b[3];
                windowHeight.Value = b[4] << 16 | b[5] << 8 | b[6];
            }

            if ((value = _registryKey.GetValue("Opaque")) != null &&
                value.GetType() == (typeof (long))) {
                var b = new byte[8];
                for (int i = 0; i < 8; i++)
                    b[i] = (byte) (((long) value >> (i*8)) & 0xff);
                opaqueCheckbox.Checked = (b[0] & 1) == 1;
                if ((b[0] & 2) == 2)
                    opaqueType.SelectedIndex = 0;
                if ((b[0] & 4) == 4)
                    opaqueType.SelectedIndex = 1;

                checkerValue.Value = b[1] + 2;

                var hex = new StringBuilder(6);
                hex.AppendFormat("{0:X2}", b[2]);
                hex.AppendFormat("{0:X2}", b[3]);
                hex.AppendFormat("{0:X2}", b[4]);
                colourHexBox.Text = hex.ToString();
            } else
                opaqueType.SelectedIndex = 0;
            if ((value = _registryKey.GetValue("CapturePointer")) != null &&
                value.GetType() == (typeof (int)))
                mouseCheckbox.Checked = ((int) value & 1) == 1;

            groupBox1.Enabled = resizeCheckbox.Checked;
            groupBox2.Enabled = opaqueCheckbox.Checked;
            groupBox3.Enabled = mouseCheckbox.Checked;

            _ssButtonImage = Resources.capture;
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: dbremner/aeroshot
        protected override void WndProc(ref Message m) {
            base.WndProc(ref m);

            if (m.Msg == WM_HOTKEY) {
                ScreenshotTask info = GetParamteresFromUI(true);
                _worker = new Thread(() => Screenshot.CaptureWindow(ref info)) {
                    IsBackground = true
                };
                _worker.SetApartmentState(ApartmentState.STA);
                _worker.Start();
            }
            if (m.Msg == WM_DWMCOMPOSITIONCHANGED) {
                _dwmComposited = Dwm.IsCompositionEnabled;

                if (_dwmComposited) {
                    ssButton.Location = new Point(ssButton.Location.X, 310);
                    var margin = new WindowsMargins(0, 0, 0, 35);
                    NativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margin);
                } else
                    ssButton.Location = new Point(ssButton.Location.X, 305);
            }
        }
コード例 #7
0
ファイル: WindowsAPI.cs プロジェクト: Happy-Ferret/aeroshot
 internal static int DwmExtendFrameIntoClientArea(IntPtr hWnd,
                                                  ref WindowsMargins
                                                      pMarInset) {
     IntPtr dwmDll = LoadLibrary("dwmapi.dll");
     if (dwmDll == IntPtr.Zero)
         return Marshal.GetLastWin32Error();
     IntPtr dwmFunction = GetProcAddress(dwmDll,
                                         "DwmExtendFrameIntoClientArea");
     if (dwmFunction == IntPtr.Zero)
         return Marshal.GetLastWin32Error();
     var call =
         (DwmExtendFrameIntoClientAreaDelegate)
         Marshal.GetDelegateForFunctionPointer(dwmFunction,
                                               typeof (
                                                   DwmExtendFrameIntoClientAreaDelegate
                                                   ));
     int result = call(hWnd, ref pMarInset);
     FreeLibrary(dwmDll);
     return result;
 }