If thewindow being removed is the last window in the chain
// [MoreWindows work Note 12] WM_DRAWCLIPBOARD monitoring clipboard // http://blog.csdn.net/morewindows/article/details/17655429// By MoreWindows (http://blog.csdn.net/MoreWindows) bool callback DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {static HWND s_hwnd_new_clipboard_viewer = NULL; static HWND s_hwnd_edit_clipboard_info = NULL; switch (message) {case WM_INITDIALOG: // 4-1 Add the window to the clipbo Ard viewer chain. s_hwnd_new_clipboard_viewer = SetClipboardViewer (hDlg); // Add hwnd to the monitoring chain and return the last added window handle. If it is the first, the return value is NULL. The newly added window is in the chain header and becomes "current monitor" CenterWindow (hDlg); counter = GetDlgItem (hDlg, IDC_EDIT_CLIPBOARD_INFO); return FALSE; // 4-2 Process the WM_CHANGECBCHAIN message. case WM_CHANGECBCHAIN: if (HWND) wParam = s_hwnd_new_clipboard_viewer) rows = (HWND) lParam; else SendMessage (response, message, wParam, lParam ); // 4-3 Process the WM_DRAWCLIPBOARD message. Case WM_DRAWCLIPBOARD: // The clipboard content changes. if (OpenClipboard (hDlg) {UINT clipboard_format = partition (0); HGLOBAL global_memory = GetClipboardData (clipboard_format ); DWORD data_size = GlobalSize (global_memory); CloseClipboard (); WCHAR clipboard_info [1024]; swprintf (clipboard_info, L "Clipboard \ r \ n Data Format = % x \ r \ n Data Address = 0x % x \ r \ n Data Size = % d", clipboard_format, global_memory, Data_size); if (clipboard_format = CF_UNICODETEXT) {LPCWSTR clipboard_data = (LPCWSTR) GlobalLock (global_memory); if (clipboard_data! = NULL) {wcscat (clipboard_info, L "\ r \ nData: \ r \ n"); WCHAR buffer [1024]; DWORD data_size = GlobalSize (global_memory ); for (size_t I = 0; I <data_size; I ++) buffer [I] = clipboard_data [I]; buffer [data_size] = L' \ 0'; wcscat (clipboard_info, buffer) ;}} SetWindowTextW (s_hwnd_edit_clipboard_info, clipboard_info);} return FALSE; case WM_COMMAND: switch (LOWORD (wParam) {case IDOK: case IDCANCEL: // 4-4 Remove the window from the clipboard viewer chain before it is destroyed. changeconboardchain (hDlg, s_hwnd_new_clipboard_viewer); EndDialog (hDlg, FALSE); return TRUE;} break;} return FALSE ;}