SetClipboardViewer function
Applies to: desktop apps only
Adds the specified window to the chain of clipboard viewers. Clipboard viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of the clipboard changes.
Syntax
HWND WINAPI SetClipboardViewer( __in HWND hWndNewViewer );
Parameters
- hWndNewViewer [in]
-
Type: HWND
A handle to the window to be added to the clipboard chain.
Return value
Type: HWND
If the function succeeds, the return value identifies the next window in the clipboard viewer chain. If an error occurs or there are no other windows in the clipboard viewer chain, the return value is NULL. To get extended error information, call GetLastError.
Remarks
The windows that are part of the clipboard viewer chain, called clipboard viewer windows, must process the clipboard messages WM_CHANGECBCHAIN and WM_DRAWCLIPBOARD. Each clipboard viewer window calls the SendMessage function to pass these messages to the next window in the clipboard viewer chain.
A clipboard viewer window must eventually remove itself from the clipboard viewer chain by calling the ChangeClipboardChain function — for example, in response to the WM_DESTROY message.
Examples
For an example, see Adding a Window to the Clipboard Viewer Chain.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- ChangeClipboardChain
- GetClipboardViewer
- SendMessage
- Conceptual
- Clipboard
Send comments about this topic to Microsoft
Build date: 3/6/2012
- 9/20/2011
- Jack Tripper
- 2/14/2009
- Halomfalom
- 9/1/2010
- MichaelJT
- 9/1/2010
- MichaelJT
SetClipboardViewer() does not set the last error to 0 on success. Therefore it's impossible to tell whether a 0 return value is an error condition or the end of the clipboard chain. The suggested solution is to explicitly clear the last error before calling SetClipboardViewer, like this:
SetLastError(0);
HWND nextViewer = SetClipboardViewer(wnd);
if (nextViewer == NULL && GetLastError() != 0) {
// SetClipboardViewer failed...
}
SetClipboardViewer() also sends a WM_DRAWCLIPBOARD message to the newly added viewer before it returns. Therefore, the last error must be cleared at the end of the WM_DRAWCLIPBOARD handler as well:
case WM_DRAWCLIPBOARD: {
// handle msg
/* ... */
// forward msg to next viewer
if (nextViewer)
SendMessage(nextViewer, msg, wparam, lparam);
// clear error to avoid confusing SetClipboardViewer() return
SetLastError(0);
return 0;
}
Hi !
I would like to know if there is an equivalent of the SetClipboardViewer function on the .NET compact framework.
Background : I write an application for a WM6 pocket PC in C# that runs in the background and should check the contents of the clipboard whenever its contents has been changed by any other application running on the device.
Several posts explain how to do that for the "full framework" by using User32.dll SetClipboardViewer described in this article:
http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c7315/
http://www.developer.com/net/csharp/article.php/3359891
http://www.radsoftware.com.au/articles/clipboardmonitor.aspx
However, I can't find the equivalent of SetClipboardViewer in the CF.
Any suggestion is welcome. Thanks for your time !
Fabien
[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.
- 1/12/2008
- FabienMSDN
- 1/15/2008
- Noelle Mallory