2024-02-10 20:59:17 +00:00
|
|
|
|
using System;
|
2024-07-21 13:04:55 +00:00
|
|
|
|
using System.ComponentModel;
|
2024-02-10 20:59:17 +00:00
|
|
|
|
using System.Windows.Forms;
|
2024-03-03 18:39:57 +00:00
|
|
|
|
using RyzStudio.Windows.Forms;
|
2024-02-10 20:59:17 +00:00
|
|
|
|
|
|
|
|
|
namespace ClipboardWatcher
|
|
|
|
|
{
|
|
|
|
|
public partial class MainForm : Form
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
private IntPtr _clipboardViewer;
|
|
|
|
|
private bool _isMonitoring = false;
|
|
|
|
|
private int _lineCount = 0;
|
2024-02-10 20:59:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
memoBox1.TextBox.WordWrap = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnShown(e);
|
|
|
|
|
|
|
|
|
|
button2.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnClosing(e);
|
|
|
|
|
|
|
|
|
|
this.IsMonitoring = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-10 20:59:17 +00:00
|
|
|
|
protected override void WndProc(ref Message m)
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
if ((m.Msg == RyzStudio.Runtime.InteropServices.User32.WM_DRAWCLIPBOARD) && this.IsMonitoring)
|
2024-02-10 20:59:17 +00:00
|
|
|
|
{
|
|
|
|
|
AddClipboardText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.WndProc(ref m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsMonitoring
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
get => _isMonitoring;
|
2024-02-10 20:59:17 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
_isMonitoring = value;
|
2024-02-10 20:59:17 +00:00
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
_clipboardViewer = (_isMonitoring ? RyzStudio.Runtime.InteropServices.User32.SetClipboardViewer(this.Handle) : default);
|
2024-02-10 20:59:17 +00:00
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
button2.LabelText = (_isMonitoring ? "Sto&p" : "&Start") + " Monitoring";
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
#region Main Menu
|
|
|
|
|
|
2024-02-10 20:59:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// New
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void newToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Clipboard.Clear();
|
|
|
|
|
|
|
|
|
|
this.IsMonitoring = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Close
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void exitToolStripMenuItem2_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
this.Close();
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Options
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
// do nothing
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Help
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void viewHelpToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
RyzStudio.Diagnostics.Process.Execute(AppResource.AppHelpURL);
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// About
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-21 13:04:55 +00:00
|
|
|
|
var form = new RyzStudio.Windows.ThemedForms.AboutForm();
|
|
|
|
|
form.ProductURL = AppResource.AppProductURL;
|
|
|
|
|
form.AuthorURL = AppResource.AppAuthorURL;
|
|
|
|
|
form.CompanyURL = AppResource.AppCompanyURL;
|
|
|
|
|
form.ProductCopyrightStartYear = 2024;
|
|
|
|
|
//form.ProductLogo = AppResource.icon_64;
|
|
|
|
|
|
|
|
|
|
form.ShowDialog();
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-02-10 20:59:17 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Start/stop monitoring
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void button3_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Clipboard.Clear();
|
|
|
|
|
|
|
|
|
|
this.IsMonitoring = !this.IsMonitoring;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clear
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void button4_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Clipboard.Clear();
|
|
|
|
|
|
|
|
|
|
memoBox1.Text = string.Empty;
|
2024-07-21 13:04:55 +00:00
|
|
|
|
_lineCount = 0;
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void memoBox1_DragOver(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
{
|
|
|
|
|
if (this.IsMonitoring)
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void memoBox1_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsMonitoring)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
|
|
|
|
|
if (fileList == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string item in fileList)
|
|
|
|
|
{
|
|
|
|
|
memoBox1.Text += item + Environment.NewLine;
|
2024-07-21 13:04:55 +00:00
|
|
|
|
_lineCount++;
|
2024-03-03 18:39:57 +00:00
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
UIControl.SetText(this, $"Clipboard Monitor ({_lineCount.ToString()})");
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void AddClipboardText()
|
|
|
|
|
{
|
|
|
|
|
if (!Clipboard.ContainsText())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var clipboardText = Clipboard.GetText();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(clipboardText))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memoBox1.Text += clipboardText.Trim() + Environment.NewLine;
|
2024-07-21 13:04:55 +00:00
|
|
|
|
_lineCount++;
|
2024-03-03 18:39:57 +00:00
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
UIControl.SetText(this, $"Clipboard Monitor ({_lineCount.ToString()})");
|
2024-03-03 18:39:57 +00:00
|
|
|
|
|
2024-07-21 13:04:55 +00:00
|
|
|
|
UIControl.BringToFront(this);
|
2024-02-10 20:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|