枚举剪切板数据和格式名称



  if(OpenClipboard()) //open clipboard 
  {
    UINT uFormat = 0;
    while(uFormat = EnumClipboardFormats(uFormat)) //emulate format
    {       
      HGLOBAL hGlobal = GetClipboardData(uFormat); //get Clipboard data 
      DWORD dwSize = GlobalSize(hGlobal); //get memory size
      LPVOID pData = GlobalLock(hGlobal); //get memory data point
      //process data
      GlobalUnlock(hGlobal); //unlock global memory
      
      //get format name
      TCHAR szFormat[129] = {0};      
      #define TraceFormat(x) { case(x): _stprintf_s(szFormat, _T("%s"), _T(#x)); break; }
      switch(uFormat)
      {
        TraceFormat(CF_TEXT);
        TraceFormat(CF_BITMAP);
        TraceFormat(CF_METAFILEPICT);
        TraceFormat(CF_SYLK);
        TraceFormat(CF_DIF);
        TraceFormat(CF_TIFF);
        TraceFormat(CF_OEMTEXT);
        TraceFormat(CF_DIB);
        TraceFormat(CF_PALETTE);
        TraceFormat(CF_PENDATA);
        TraceFormat(CF_RIFF);
        TraceFormat(CF_WAVE);
        TraceFormat(CF_UNICODETEXT);
        TraceFormat(CF_ENHMETAFILE);
        TraceFormat(CF_HDROP);
        TraceFormat(CF_LOCALE);
        TraceFormat(CF_OWNERDISPLAY);
        TraceFormat(CF_DSPTEXT);
        TraceFormat(CF_DSPBITMAP);
        TraceFormat(CF_DSPMETAFILEPICT);
        TraceFormat(CF_DSPENHMETAFILE);
        default:
        {
          if(uFormat >= CF_PRIVATEFIRST && uFormat <= CF_PRIVATELAST)
          {
            _stprintf_s(szFormat, _T("CF_PRIVATEFIRST + %d"), uFormat - CF_PRIVATEFIRST);
          }
          else if(uFormat >= CF_GDIOBJFIRST && uFormat <= CF_GDIOBJLAST)
          {
            _stprintf_s(szFormat, _T("CF_GDIOBJFIRST + %d"), uFormat - CF_GDIOBJFIRST);
          }
          else if(GetClipboardFormatName(uFormat, szFormat, 128))
          {
          }
          else
          {
            ASSERT(FALSE);
          }          
          break;
        }
      }

      TRACE(_T("clipboard foramt %08X = \"%s\" (%u) \n"),
        uFormat, szFormat, dwSize);

    }
    
    CloseClipboard(); //close clipboard
  }


你可能感兴趣的:(系统/线程/调试,文档/视,数据库/COM,资源相关)