在Visual C ++中保存时,只有Grabbing Icon显示为黑色

时间:2018-12-10 07:03:09

标签: c++ visual-c++ save cursor icons

我想将图标保存到VC ++中的文件中。请找到我正在使用的以下代码。我可以保存所有成功保存的图标。但是,当我尝试将抓取图标保存到本地硬盘时,图像周围会出现黑色背景。

请找到以下代码段。

在此处输入代码

 CURSORINFO ci;
    ci.cbSize = sizeof(ci);
    GetCursorInfo(&ci);
    HICON hico = ci.hCursor;
    ICONINFO iconInfo;
    GetIconInfo(ci.hCursor, &iconInfo);

    BYTE  buf[4096];
    LONG cbSize = 0;

    PICTDESC pd = {sizeof(pd), PICTYPE_ICON};
    pd.icon.hicon = ci.hCursor;
    CComPtr<IPicture> pPict = NULL;
    CComPtr<IStream>  pStrm = NULL;
    BOOL res = FALSE;
    res = SUCCEEDED( ::CreateStreamOnHGlobal(NULL, TRUE, &pStrm) );
    res = SUCCEEDED( ::OleCreatePictureIndirect(&pd, IID_IPicture, FALSE, (void**)&pPict) );
    res = SUCCEEDED( pPict->SaveAsFile( pStrm, TRUE, &cbSize ) );

    if( res )
    {
              // rewind stream to the beginning
               LARGE_INTEGER li = {0};
               pStrm->Seek(li, STREAM_SEEK_SET, NULL);
             // write to file
             HANDLE hFile = ::CreateFile("E:\\abc.jpeg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
               if( INVALID_HANDLE_VALUE != hFile )
                  {
                   DWORD dwWritten = 0, dwRead = 0, dwDone = 0;
                          while( dwDone < cbSize )
                                  {
                                   if( SUCCEEDED(pStrm->Read(buf, sizeof(buf), &dwRead)) )
                                        {
                                           ::WriteFile(hFile, buf, dwRead, &dwWritten, NULL);
                                             if( dwWritten != dwRead )
                                                     break;
                                                   dwDone += dwRead;
                                          }
                                         else
                                            break;
                     }
                            _ASSERTE(dwDone == cbSize);
                          ::CloseHandle(hFile);
            }

    }

请找到下面的抓取图标。enter image description here

这仅适用于gmail中的手形图标。请找到下图。 enter image description here

谢谢您的帮助。

0 个答案:

没有答案