예제 #1
0
 public override System.Windows.Forms.DialogResult EditSettings(System.Windows.Forms.IWin32Window parent)
 {
     using (SettingsForm Form = new SettingsForm(this))
     {
         return Form.ShowDialog(parent);
     }
 }
예제 #2
0
/*
#warning experimental

        const int R2_NOTXORPEN = 10;

        [DllImport("gdi32.dll", ExactSpelling = true)]
        private static extern int SetROP2(HandleRef context, int drawMode);


        private SharedDeviceContext _Context = null;
        private Pen _Marker = null;
        private IntPtr _OriginalBrush;
        private IntPtr _OriginalPen;
        private int _OldMode;


        private void PrepareContext()
        {
            this._Marker = new Pen(NativeMethods.PS_SOLID, 4, 0x000000FF);
            this._Context = new SharedDeviceContext(IntPtr.Zero);

            HandleRef DC = new HandleRef(this._Context, this._Context.Handle);

            this._OriginalBrush = NativeMethods.SelectObject(DC, new HandleRef(null, NativeMethods.GetStockObject(NativeMethods.HOLLOW_BRUSH)));
            this._OriginalPen = NativeMethods.SelectObject(DC, new HandleRef(this._Marker, this._Marker.Handle));

            this._OldMode = SetROP2(DC, R2_NOTXORPEN);
        }

        private void ReleaseContext()
        {
            HandleRef DC = new HandleRef(this._Context, this._Context.Handle);

            SetROP2(DC, this._OldMode);

            NativeMethods.SelectObject(DC, new HandleRef(this, this._OriginalPen));
            NativeMethods.SelectObject(DC, new HandleRef(this, this._OriginalBrush));

            this._Context.Dispose();
            this._Marker.Dispose();
        }


        private IntPtr OnKeyboardEvent(int code, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
        {
            if ((code < 0) || (lParam.vkCode != NativeMethods.VK_SNAPSHOT))
            {
                return NativeMethods.CallNextHookEx(new HandleRef(this._KeyboardHook, this._KeyboardHook.Handle), code, wParam, ref lParam);
            }

            if (!(this._IsPrintScreenKeyDown = ((lParam.flags & NativeMethods.LLKHF_UP) == 0)))
            {
                if (this._IsSearchMode)
                {
                    this._IsSearchMode = false;
                    IntPtr Window = this._SelectedWindow;

                    if (Window != IntPtr.Zero)
                    {
                        this._SelectedWindow = IntPtr.Zero;

                        RECT windowBounds;

                        if (NativeMethods.GetWindowRect(new HandleRef(null, Window), out windowBounds))
                        {
                            NativeMethods.Rectangle(new HandleRef(this._Context, this._Context.Handle), windowBounds.Left, windowBounds.Top, windowBounds.Right, windowBounds.Bottom);

                            this.ReleaseContext();
                        }


                        JobManager.AddJob(Window);
                    }
                }
                else if ((lParam.flags & NativeMethods.LLKHF_ALTDOWN) != 0)
                {
                    this.ShowSettingsForm();
                }
                else if (NativeMethods.IsKeyDown(NativeMethods.VK_SHIFT))
                {
                    JobManager.AddJob(ImageBounds.ForegroundWindow);
                }
                else if (NativeMethods.IsKeyDown(NativeMethods.VK_CONTROL))
                {
                    JobManager.AddJob(ImageBounds.VirtualScreen);
                }
                else
                {
                    JobManager.AddJob(ImageBounds.CurrentScreen);
                }
            }

            return new IntPtr(1);
        }

#warning Keeps searching if user Win+L while searching

        private IntPtr OnMouseEvent(int code, IntPtr wParam, ref MSLLHOOKSTRUCT lParam)
        {
            if ((code >= 0) && (wParam == new IntPtr(NativeMethods.WM_MOUSEMOVE)) && this._IsPrintScreenKeyDown)
            {
                if (!this._IsSearchMode)
                {
                    this.PrepareContext();
                }

                this._IsSearchMode = true;

                IntPtr Window = NativeMethods.WindowFromPoint(lParam.pt);

                if (Window != IntPtr.Zero)
                {
                    IntPtr SelectedWindow = this._SelectedWindow;
                    this._SelectedWindow = Window;

                    if (Window != SelectedWindow)
                    {
                        RECT windowBounds;

                        NativeMethods.GetWindowRect(new HandleRef(null, SelectedWindow), out windowBounds);
                        NativeMethods.Rectangle(new HandleRef(this._Context, this._Context.Handle), windowBounds.Left, windowBounds.Top, windowBounds.Right, windowBounds.Bottom);

                        NativeMethods.GetWindowRect(new HandleRef(null, Window), out windowBounds);
                        NativeMethods.Rectangle(new HandleRef(this._Context, this._Context.Handle), windowBounds.Left, windowBounds.Top, windowBounds.Right, windowBounds.Bottom);

                    }
                }
            }

            return NativeMethods.CallNextHookEx(new HandleRef(this._MouseHook, this._MouseHook.Handle), code, wParam, ref lParam);
        }
        */
        #endregion


        private void CreateSettingsForm(object e)
        {
            SettingsForm form = new SettingsForm();

            form.HandleCreated += new EventHandler(this.SettingsFormHandleCreated);
            form.HandleDestroyed += new EventHandler(this.SettingsFormHandleDestroyed);

            Application.Run(form);
        }