[MoreWindows work Note 12] WM_DRAWCLIPBOARD monitoring clipboard

Source: Internet
Author: User

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 ;}

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.