Пример #1
0
 private void MainForm_Load(object sender, System.EventArgs e)
 {
     RestoreClips();
     //Register CTRL+SHIFT+D & CTRL+E
     //http://msdn.microsoft.com/en-us/library/windows/desktop/ms646279(v=vs.85).aspx
     //APIFuncs.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), APIFuncs.Constants.CTRL + APIFuncs.Constants.SHIFT, (int)'V');
     APIFuncs.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), APIFuncs.Constants.CTRL, (int)'E');
 }
Пример #2
0
        /*
         * http://www.codeguru.com/forum/showthread.php?t=474426
         * http://stackoverflow.com/questions/46030/c-sharp-force-form-focus
         * http://chabster.blogspot.com/2010/03/focus-and-window-activation-in-win32.html
         */
        private void SetForegroundWindowInternal(IntPtr hwnd)
        {
            if (APIFuncs.IsIconic(hwnd))
            {
                APIFuncs.ShowWindowAsync(hwnd, APIFuncs.SW_RESTORE);
            }

            APIFuncs.ShowWindowAsync(hwnd, APIFuncs.SW_SHOW);

            APIFuncs.SetForegroundWindow(hwnd);

            // Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
            // Converted to Delphi by Ray Lischner
            // Published in The Delphi Magazine 55, page 16
            // Converted to C# by Kevin Gale
            IntPtr foregroundWindow = APIFuncs.GetForegroundWindow();
            IntPtr Dummy            = IntPtr.Zero;

            uint foregroundThreadId = APIFuncs.GetWindowThreadProcessId(foregroundWindow, Dummy);
            uint thisThreadId       = APIFuncs.GetWindowThreadProcessId(hwnd, Dummy);

            if (APIFuncs.AttachThreadInput(thisThreadId, foregroundThreadId, true))
            {
                APIFuncs.BringWindowToTop(hwnd); // IE 5.5 related hack
                APIFuncs.SetForegroundWindow(hwnd);
                APIFuncs.AttachThreadInput(thisThreadId, foregroundThreadId, false);
            }

            if (APIFuncs.GetForegroundWindow() != hwnd)
            {
                // Code by Daniel P. Stasinski
                // Converted to C# by Kevin Gale
                IntPtr Timeout = IntPtr.Zero;
                APIFuncs.SystemParametersInfo(APIFuncs.SPI_GETFOREGROUNDLOCKTIMEOUT, 0, Timeout, 0);
                APIFuncs.SystemParametersInfo(APIFuncs.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Dummy, APIFuncs.SPIF_SENDCHANGE);
                APIFuncs.BringWindowToTop(hwnd); // IE 5.5 related hack
                APIFuncs.SetForegroundWindow(hwnd);
                APIFuncs.SystemParametersInfo(APIFuncs.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Timeout, APIFuncs.SPIF_SENDCHANGE);
            }
        }
Пример #3
0
 private void UnregisterClipboardViewer()
 {
     APIFuncs.ChangeClipboardChain(this.Handle, ClipboardViewerNext);
 }
Пример #4
0
 private void RegisterClipboardViewer()
 {
     ClipboardViewerNext = APIFuncs.SetClipboardViewer(this.Handle);
 }
Пример #5
0
        /*protected override void SetVisibleCore(bool value)
         * {
         * if (!fHideStartup)
         * {
         *  base.SetVisibleCore(value);
         * }
         * else
         * {
         *  fHideStartup = false;
         * }
         * }*/

        protected override void WndProc(ref Message m)
        {
            switch ((APIFuncs.Msgs)m.Msg)
            {
            case APIFuncs.Msgs.WM_SETFOCUS:
            {
                fExtApp = APIFuncs.GetActiveWindow();
                break;
            }

            case APIFuncs.Msgs.WM_HOTKEY:
            {
                Keys key       = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
                int  Modifiers = ((int)m.LParam & 0xFFFF);
                switch (key)
                {
                case Keys.E:
                {
                    if (Modifiers == APIFuncs.Constants.CTRL)
                    {
                        listBoxClips.SelectedIndex = listBoxClips.Items.Count - 1;
                        Show();
                        WindowState     = FormWindowState.Normal;
                        fCallFromHotkey = true;
                    }
                    break;
                }

                case Keys.V:
                {
                    if ((Modifiers == (APIFuncs.Constants.CTRL + APIFuncs.Constants.SHIFT)))
                    {
                        QuickPaste qp = new QuickPaste();
                        qp.Show();
                        fCallFromHotkey = true;
                    }
                    break;
                }

                default:
                    break;
                }
                break;
            }

            case APIFuncs.Msgs.WM_QUERYENDSESSION:
            {
                fShutdownApp = true;
                break;
            }

            case APIFuncs.Msgs.WM_DRAWCLIPBOARD:
            {
                if (!fInitialRun)
                {
                    InsertClip();
                    if (ClipboardViewerNext != System.IntPtr.Zero)
                    {
                        APIFuncs.SendMessage(ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                    }
                }
                else
                {
                    fInitialRun = false;
                }
                break;
            }

            case APIFuncs.Msgs.WM_CHANGECBCHAIN:
            {
                if (m.WParam == ClipboardViewerNext)
                {
                    ClipboardViewerNext = m.LParam;
                }
                else
                {
                    if (ClipboardViewerNext != System.IntPtr.Zero)
                    {
                        APIFuncs.SendMessage(ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                    }
                }
                break;
            }

            default:
            {
                base.WndProc(ref m);
                break;
            }
            }
        }
Пример #6
0
 private void MainForm_Closed(object sender, System.EventArgs e)
 {
     APIFuncs.UnregisterHotKey(this.Handle, this.GetType().GetHashCode());
     UnregisterClipboardViewer();
     SaveClips();
 }
Пример #7
0
        private void InsertClip()
        {
            IDataObject iData = Clipboard.GetDataObject();

            if (iData != null)
            {
                //Handle TXT clipboard
                if (iData.GetDataPresent(DataFormats.Text))
                {
                    IntPtr  hwnd = APIFuncs.GetForegroundWindow();
                    Int32   pid  = APIFuncs.GetWindowProcessID(hwnd);
                    Process p    = Process.GetProcessById(pid);

                    ClipItem Item = new ClipItem(p.MainModule.FileName);
                    Item.Content = iData.GetData(DataFormats.StringFormat).ToString();
                    Item.Type    = ClipItem.EType.eText;
                    if (fLocalCopy == false)
                    {
                        bool foundedDuplicate = false;
                        foreach (ClipItem clip in listBoxClips.fClips)
                        {
                            if (clip.Content == Item.Content)
                            {
                                //Add stats
                                Item.Count = ++clip.Count;
                                bool foundedMFU = false;
                                foreach (ClipItem mfclip in listBoxMFU.fMFU)
                                {
                                    if (mfclip.Content == Item.Content)
                                    {
                                        foundedMFU   = true;
                                        mfclip.Count = Item.Count;
                                        listBoxMFU.fMFU.Remove(mfclip);
                                        listBoxMFU.fMFU.Add(mfclip);
                                        break;
                                    }
                                }
                                if (!foundedMFU)
                                {
                                    listBoxMFU.fMFU.Add(Item);
                                    listBoxMFU.Items.Add(listBoxMFU.fMFU.Count.ToString());
                                }

                                //Duplicate
                                if (Properties.Settings.Default.AvoidDuplicate)
                                {
                                    foundedDuplicate = true;
                                    listBoxClips.fClips.Remove(clip);
                                    listBoxClips.fClips.Add(clip);
                                    break;
                                }
                            }
                        }
                        listBoxMFU.Refresh();
                        //EO Duplicate
                        if (!foundedDuplicate)
                        {
                            listBoxClips.fClips.Add(Item);
                            listBoxClips.Items.Add(listBoxClips.fClips.Count.ToString());
                        }
                        trayIcon.ShowBalloonTip(500, Properties.Resources.ClipOfTypeText, Item.Content, ToolTipIcon.Info);
                    }
                    else
                    {
                        fLocalCopy = false;
                    }
                    listBoxClips.Refresh();
                }

                //Handle Bitmap element
                if (iData.GetDataPresent(DataFormats.Bitmap))
                {
                    IntPtr  hwnd = APIFuncs.GetForegroundWindow();
                    Int32   pid  = APIFuncs.GetWindowProcessID(hwnd);
                    Process p    = Process.GetProcessById(pid);

                    ClipItem Item = new ClipItem(p.MainModule.FileName);
                    Item.Image = (Bitmap)iData.GetData(DataFormats.Bitmap);
                    Item.Type  = ClipItem.EType.eImage;
                    if (fLocalCopy == false)
                    {
                        listBoxClips.fClips.Add(Item);
                        listBoxClips.Items.Add(listBoxClips.fClips.Count.ToString());
                        trayIcon.ShowBalloonTip(500, Properties.Resources.ClipOfTypeImage, Item.Image.Size.ToString(), ToolTipIcon.Info);
                    }
                    else
                    {
                        fLocalCopy = false;
                    }
                }

#warning Handle files element

                /*
                 *      string[] type = iData.GetFormats();
                 *      int a = type.Length;
                 *      if (a == 3)
                 *      {
                 *          int b = 3;
                 *      }
                 */
            }
        }