Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
<DllImport("user32.dll", SetLastError:=true)> _
Public Function AddClipboardFormatListener(hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)>Boolean
VB Signature:
Declare Function AddClipboardFormatListener Lib "user32.dll" (hWnd As Long) As Boolean
User-Defined Types:
None.
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
AddClipboardFormatListener is much simpler than setting up a clipboard viewer window. The Format listener doesn't require maintaining the chain of clipboard notifications. The AddClipboardFormatListener() API was added with Windows XP and Windows Server 2008.
Tips & Tricks:
Please add some!
Sample Code:
Please add some!
// C# Example:
// Declare the API method for placing the given window in the system-maintained clipboard format listener list.
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AddClipboardFormatListener(IntPtr hwnd);
// Declare the API method for removing the given window from the system-maintained clipboard format listener list.
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
// Here is the message sent when the contents of the clipboard have changed.
private const int WM_CLIPBOARDUPDATE = 0x031D;
// Here is how to add our window to the Clipboard Format Listener:
AddClipboardFormatListener(this.Handle);
// Here is how to process The Message:
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (iData.GetDataPresent(DataFormats.Text))
{
string text = (string)iData.GetData(DataFormats.Text);
// do something with it
}
else if (iData.GetDataPresent(DataFormats.Bitmap))
{
Bitmap image = (Bitmap)iData.GetData(DataFormats.Bitmap);
// do something with it
}
// you can also check for more formats and process accordingly
}
}
// When closing your program, first remove the format listener:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
RemoveClipboardFormatListener(this.Handle); // Remove our window from the clipboard's format listener list.
}
Places the given window in the system-maintained clipboard format listener list. The window will then receive a WM_CLIPBOARDUPDATE message when the clipboard contents have changed.
2/21/2022 10:07:11 AM - -66.109.156.237
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).