【MoreWindows工作筆記12】WM_DRAWCLIPBOARD 監視剪下板

來源:互聯網
上載者:User

if thewindow being removed is the last window in the chain

// 【MoreWindows工作筆記12】WM_DRAWCLIPBOARD 監視剪下板// 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 clipboard viewer chain.     s_hwnd_new_clipboard_viewer = SetClipboardViewer(hDlg);    // 把hwnd加入監視鏈,返回上一個加入的視窗控制代碼,如果是第一個,則傳回值為NULL。新加的視窗在鏈條頭部,成為“當前監視器”CenterWindow(hDlg);    s_hwnd_edit_clipboard_info = 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)      s_hwnd_new_clipboard_viewer = (HWND)lParam;    else      SendMessage(s_hwnd_new_clipboard_viewer, message, wParam, lParam);  // 4-3 Process the WM_DRAWCLIPBOARD message.   case WM_DRAWCLIPBOARD:  //剪下板內容發生變化    if (OpenClipboard(hDlg)) {      UINT clipboard_format = EnumClipboardFormats(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.       ChangeClipboardChain(hDlg, s_hwnd_new_clipboard_viewer);EndDialog(hDlg, FALSE);return TRUE;}break;}return FALSE;}

 



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.