IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

[C# & WPF] Clipboard Monitor


Sujet :

C#

  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2007
    Messages
    634
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2007
    Messages : 634
    Points : 407
    Points
    407
    Par défaut [C# & WPF] Clipboard Monitor
    Bonsoir à tous,

    je cherche à faire un ClipBoard Monitor en c#/WPF afin de catcher les copies de liens html (un peu comme dans JDownloader pour ceux qui connaissent).

    J'ai trouvé ceci : LIEN, mais il y a du windows.form et ca hérite de Control.

    Une idée ?

    Merci d'avance.

    Cordialement,
    NeoKript

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2007
    Messages
    634
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2007
    Messages : 634
    Points : 407
    Points
    407
    Par défaut
    Salut à tous,
    j'ai modifié le code comme ceci mais ca ne fonctionne pas, une idée ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
       [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        public class ClipboardMonitor : IDisposable
        {
            #region P/Invoke
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            private static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
            [DllImport("User32.dll", CharSet = CharSet.Auto)]
            private static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
            #endregion
            #region Constante
            private const int WM_DRAWCLIPBOARD = 0x0308;
            private const int WM_CHANGECBCHAIN = 0x030D;
            #endregion
            #region Private Fields
            private IntPtr Handle = IntPtr.Zero;
            private IntPtr ClipboardViewerNext = IntPtr.Zero;
            private Boolean Enabled = false;
            #endregion
            #region Properties
     
            public Boolean IsEnabled
            {
                get
                {
                    return (this.Enabled);
                }
                set
                {
                    this.Enabled = value;
                }
            }
     
            #endregion
            #region Event 
            public event ClipboardChangedEventHandler ClipboardChanged = null;
            #endregion
            #region Methods
            public void Start()
            {
                this.Enabled = true;
            }
            public void Stop()
            {
                this.Enabled = false;
            }
     
            public bool FilterMessage(ref Message m)
            {
                if (!this.Enabled)
                {
                    return false;
                }
                switch (m.Msg)
                {
                    case WM_DRAWCLIPBOARD:
                        if (this.ClipboardChanged != null)
                        {
                            try
                            {
                                System.Windows.IDataObject IData = System.Windows.Clipboard.GetDataObject();
                                this.ClipboardChanged(this, new ClipboardChangedEventArgs(IData));
                            }
                            catch
                            {
                            }
                        }
                        SendMessage(this.ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                        return (true);
                    case WM_CHANGECBCHAIN:
                        if (m.WParam == this.ClipboardViewerNext)
                        {
                            this.ClipboardViewerNext = m.LParam;
                        }
                        else
                        {
                            SendMessage(this.ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                        }
                        return (true);
     
                    default:
                        return (false);
                }
            }
            #endregion
            #region IDisposable Members
     
            public void Dispose()
            {
                ChangeClipboardChain(this.Handle, this.ClipboardViewerNext);
                this.Handle = IntPtr.Zero;
                this.ClipboardViewerNext = IntPtr.Zero;
            }
     
            #endregion
            #region Constructor
            public ClipboardMonitor()
            {
                Process P = Process.GetCurrentProcess();
                this.Handle = P.MainWindowHandle;
                this.ClipboardViewerNext = SetClipboardViewer(this.Handle);
            }
            #endregion
            #region Singleton
            private static ClipboardMonitor Singleton = null;
            public static ClipboardMonitor Instance
            {
                get
                {
                    if (Singleton == null)
                        Singleton = new ClipboardMonitor();
                    return (Singleton);
                }
            }
     
            #endregion
    Pour infos :
    SetClipboardViewer retourne 0 (dans le constructeur).

    Merci d'avance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Network Monitor : cas pratique combinant Visio 2010, WPF et WCF
    Par The_badger_man dans le forum Contribuez
    Réponses: 2
    Dernier message: 15/09/2010, 12h08
  2. PB Clipboard
    Par carnifex77850 dans le forum Langage
    Réponses: 3
    Dernier message: 09/11/2002, 13h43
  3. Copier le texte d'un ListBox dans le clipboard.
    Par Clément[Delphi] dans le forum Composants VCL
    Réponses: 3
    Dernier message: 18/08/2002, 08h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo