# Function Reference

# _ClipBoard_ChangeChain

Removes a specified window from the chain of clipboard viewers

#include <Clipboard.au3>
_ClipBoard_ChangeChain ( $hRemove, $hNewNext )

## Parameters

$hRemove | Handle to the window to be removed from the chain. The handle must have been passed to the _ClipBoard_SetViewer() function.
$hNewNext | Handle to the window that follows the $hRemove window in the clipboard viewer chain. This is the handle returned by _ClipBoard_SetViewer(), unless the sequence was changed in response to a $WM_CHANGECBCHAIN message.

## Return Value

None.

## Remarks

The window identified by $hNewNext replaces the $hRemove window in the chain.
The _ClipBoard_SetViewer() function sends a $WM_CHANGECBCHAIN message to the first window in the clipboard viewer chain.

## Related

_ClipBoard_SetViewer

## See Also

Search ChangeClipboardChain in MSDN Library.

## Example

    #include "Extras\HelpFileInternals.au3"

    #include <Clipboard.au3>
    #include <GUIConstantsEx.au3>
    #include <SendMessage.au3>
    #include <WindowsNotifsConstants.au3>
    #include <WindowsStylesConstants.au3>

    Global $g_hNext = 0

    Example()

    Func Example()
        Local $hGUI

        ; Create GUI
        $hGUI = GUICreate("Clipboard", 600, 400)
        _MemoCreate(2, 2, 596, 396, $WS_VSCROLL)
        GUISetState(@SW_SHOW)

        ; Initialize clipboard viewer
        $g_hNext = _ClipBoard_SetViewer($hGUI)

        GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")
        GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Shut down clipboard viewer
        _ClipBoard_ChangeChain($hGUI, $g_hNext)
    EndFunc   ;==>Example

    ; Handle $WM_CHANGECBCHAIN messages
    Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg
        ; Show that message was received
        _MemoWrite("***** $WM_CHANGECBCHAIN *****")

        ; If the next window is closing, repair the chain
        If $wParam = $g_hNext Then
            $g_hNext = $lParam
            ; Otherwise pass the message to the next viewer
        ElseIf $g_hNext <> 0 Then
            _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd")
        EndIf
    EndFunc   ;==>WM_CHANGECBCHAIN

    ; Handle $WM_DRAWCLIPBOARD messages
    Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg
        ; Display any text on clipboard
        _MemoWrite(_ClipBoard_GetData())

        ; Pass the message to the next viewer
        If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam)
    EndFunc   ;==>WM_DRAWCLIPBOARD