Custom Clipboard Manager

In this article I explain how to use system Clipboard API capabilities, and get an application functionality such as Spike in MS Word.
Recently I got a task to develop an application that enables users to monitor all clipboard text transactions made through Cut/Copy operation inside one application, and to transfer selected data to another application, through a custom paste operation. There was also a request to add two “ENTER” keystrokes at the end of every paste operation.
By default, operating system Clipboard API enables the user, through Cut/Copy/Paste operations, to temporarily store selected data inside a dedicated part of memory, and then to transfer that data into the same or a different application. It also enables only a single Clipboard data transaction, and to get something more, there is a need to develop and use a custom Clipboard Manager application.
According to demands for the app that should be developed, there are several things that Clipboard Manager should do:
-
The prime task is to monitor all data changes inside the system Clipboard made by Cut/Copy operations. When that event occurs the app should get Clipboard data and if it contains plain text, it should store it inside a custom data table.
-
The second task is to enable the user to select textual data from the data table and transfer it to the selected program trough custom Paste operation.
-
The third task is to give the user some extra Hotkey functionalities, like a Hotkey for deleting all memorized data, selecting data for Paste operations, minimizing and maximizing app, pasting all data at once, etc.
There are many ways to resolve those three tasks. The one applied here is by using Window Procedures with its WndProc function and User32 dynamic link library, all parts of Windows 32 API.
Windows operating system and all applications developed to run under it are event-driven. All events that happen at operating system level such as Clipboard changes, Hot Key pressed event, Foreground window has changed, etc., are registered by the operating system and if necessary, the operating system creates a message about that event and sends that message to the application window that is registered for monitoring such an event.
Window Procedures with its WndProc function enables communication between the operating systems and applications. Any created window has its own window procedure. It enables sending, receiving and processing Windows messages.
If there is a need to observe Clipboard changes, such as in this case, it is necessary to register application window Handle to the operating system Clipboard format listener list. That means that every time the content of Clipboard is changed, the operating system shall send a message about that event to the registered application's Window Procedure.
To get messages about what combination of keys is pressed, it is necessary to register the application's Window Handle and Hot Key combination to the system, and every time this key combination is pressed, the system shall send a message about that event to the registered application's Window Procedure.
What is important here is to notice that the system knows where to send a message about a certain event over the registered application window Handle. Also, the system message contains the Handle of the window that raised the observed event and code of the message.
Some of the message codes:
- // WinProc Message/Event Codes
- const int WM_HOTKEY = 0x0312;
- const int WM_CLIPBOARDUPDATE = 0x031D;
- #region- WndProc -
- protected override void WndProc(ref Message m)
- {
- // Listen for operating system Hot Key messages
- if (m.Msg == WM_HOTKEY)
- {
- // Do something
- }
- // Listen for operating system Clipboard changes
- else if (m.Msg == WM_CLIPBOARDUPDATE)
- {
- // Do something
- }
- else
- base.WndProc(ref m);
- }
- #endregion
Of course, before using this function, there is a need to register an application to the operating system for getting the desired messages.
This library contains several functions that are needed for registering the application for monitoring different events.

RomioIT VidsPosted Sep 27, 2021, 1:14 PM
An error occurred while signing: Failed to sign bin\Release\app.publish\Clipboard PROX.exe. SignTool Error: No certificates were found that met all the given criteria. Clipboard PROX
Bilbil ZabeliPosted Apr 25, 2021, 10:16 AM
Your youtube demo asks for age confirmation?!?