Navigation
Artikel
Stuff
RSS Feeds
|
Sourcecodes - Clipboard SpySprachenübersicht/C / C++/ C#/System Keywords: Spy Clipboard Code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; namespace ClipboardSpy { public class ClipboardSpyWindow : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; public ClipboardSpyWindow() { InitializeComponent(); m_NextClipboardViewer = WinAPI.SetClipboardViewer(this.Handle); } protected override void WndProc(ref System.Windows.Forms.Message m) { // defined in winuser.h const int WM_DRAWCLIPBOARD = 0x308; const int WM_CHANGECBCHAIN = 0x030D; switch(m.Msg) { case WM_DRAWCLIPBOARD: DisplayClipboardData(); WinAPI.SendMessage(m_NextClipboardViewer, m.Msg, m.WParam, m.LParam); break; case WM_CHANGECBCHAIN: if (m.WParam == m_NextClipboardViewer) m_NextClipboardViewer = m.LParam; else WinAPI.SendMessage(m_NextClipboardViewer, m.Msg, m.WParam, m.LParam); break; default: base.WndProc(ref m); break; } } public void DisplayClipboardData() { listBoxClipboardContent.Items.Clear(); IDataObject d = Clipboard.GetDataObject(); if(d.GetDataPresent(DataFormats.Bitmap)) listBoxClipboardContent.Items.Add("Bitmap!"); if(d.GetDataPresent(DataFormats.CommaSeparatedValue)) listBoxClipboardContent.Items.Add("CommaSeparatedValue"); if(d.GetDataPresent(DataFormats.Dib)) listBoxClipboardContent.Items.Add("Dib"); if(d.GetDataPresent(DataFormats.Dif)) listBoxClipboardContent.Items.Add("Dif"); if(d.GetDataPresent(DataFormats.EnhancedMetafile)) listBoxClipboardContent.Items.Add("EnhancedMetafile"); if(d.GetDataPresent(DataFormats.Html)) listBoxClipboardContent.Items.Add("Html"); if(d.GetDataPresent(DataFormats.Riff)) listBoxClipboardContent.Items.Add("Riff"); if(d.GetDataPresent(DataFormats.Rtf)) listBoxClipboardContent.Items.Add("Rtf"); if(d.GetDataPresent(DataFormats.Text)) { string tmp = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); listBoxClipboardContent.Items.Add("Text: " + tmp); } if(d.GetDataPresent(DataFormats.Tiff)) listBoxClipboardContent.Items.Add("Tiff"); if(d.GetDataPresent(DataFormats.UnicodeText)) listBoxClipboardContent.Items.Add("UnicodeText"); if(d.GetDataPresent(DataFormats.WaveAudio)) listBoxClipboardContent.Items.Add("WaveAudio"); } // Die verwendeten Ressourcen bereinigen. protected override void Dispose( bool disposing ) { WinAPI.ChangeClipboardChain(this.Handle, m_NextClipboardViewer); if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Vom Windows Form-Designer generierter Code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> private void InitializeComponent() { this.listBoxClipboardContent = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // // listBoxClipboardContent // this.listBoxClipboardContent.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.listBoxClipboardContent.Location = new System.Drawing.Point(0, 0); this.listBoxClipboardContent.Name = "listBoxClipboardContent"; this.listBoxClipboardContent.Size = new System.Drawing.Size(296, 277); this.listBoxClipboardContent.TabIndex = 0; // // ClipboardSpyWindow // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.listBoxClipboardContent); this.Name = "ClipboardSpyWindow"; this.Text = "ClipboardSpy"; this.ResumeLayout(false); } #endregion /// <summary> /// Der Haupteinstiegspunkt für die Anwendung. /// </summary> [STAThread] static void Main() { Application.Run(new ClipboardSpyWindow()); } private System.Windows.Forms.ListBox listBoxClipboardContent; IntPtr m_NextClipboardViewer; } public class WinAPI { [DllImport("User32.dll")] public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer); [DllImport("User32.dll", CharSet=CharSet.Auto)] public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext); [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam); } } Gibt es noch irgendwelche Fragen, oder wollen Sie über den Artikel diskutieren? Sprachenübersicht/C / C++/ C#/System/Clipboard Spy |