0 out of 1 rated this helpful - Rate this topic

AddClipboardFormatListener function

Applies to: desktop apps only

Places the given window in the system-maintained clipboard format listener list.

Syntax

BOOL WINAPI AddClipboardFormatListener(
  __in  HWND hwnd
);

Parameters

hwnd [in]

Type: HWND

A handle to the window to be placed in the clipboard format listener list.

Return value

Type: BOOL

Returns TRUE if successful, FALSE otherwise. Call GetLastError for additional details.

Remarks

When a window has been added to the clipboard format listener list, it is posted a WM_CLIPBOARDUPDATE message whenever the contents of the clipboard have changed.

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

WM_CLIPBOARDUPDATE
RemoveClipboardFormatListener
GetClipboardSequenceNumber

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
See The Old New Thing for sample usage
See "The clipboard viewer linked list is no longer the responsibility of applications to maintain, unless they want to" for rationale and sample usage.
What EXACTLY does this function do?
The function description is SORELY lacking. What the heck does it do!?

Edit: This set of APIs (AddClipboardFormatListener, RemoveClipboardFormatListener, WM_CLIPBOARDUPDATE) was probably created after the problems with the previous set of APIs (ChangeClipboardChain, SetClipboardViewer, WM_DRAWCLIPBOARD). The problems were that the previous set of APIs depended on the programs itself to maintain the clipboard chain, just like the old, pre-Win3.1 hook APIs, and thus was fragile. If you kill a process that used the previous set of APIs, all the windows that came after the window that got killed was yanked out as well, as the next window varible was inside the process that got killed. It was error-prone as well, programs that do not implement WM_CHANGECBCHAIN properly could affect the operation of the ChangeClipboardChain function, and windows that do not pass on WM_DRAWCLIPBOARD messages could affect all of the windows that came after that window.


Edit 2: Wow.. all that text there, Yohawn, and not a single answer. Good job. Idiot.

Edit 3: That was very useful information.

Please add more explanation.

The description is not adequate to use this API. Please add more explanation like when this can be used. Probably…with a sample code.

[Conrad] Actually it's quite simple: All you need is your window handle, to start getting notification call AddClipboardFormatListener with your window handle, then later to stop getting updates call RemoveClipboardFormatListener http://msdn.microsoft.com/en-us/library/ms649050(v=VS.85).aspx.

Every time you get the WM_XXX message fetch the clipboard formats your application is interrested in. To handle the notification, add a WM_CLIPBOARDUPDATE handler into your message queue handler function.