Dateivorschau



  • Hallo,

    weiß jemand wie man eine Dateivorschau wie beim Windowsexplorer unter Details realisiert?

    Ich möchte eine Vorschau auf ein PDF anzeigen lassen.

    Oli_1977



  • recht kompliziert.

    ich schmeiß dir einfach kommentarlos einen Code hin. Schlau werden musst du daraus selbst 😉

    Gdiplus::Image* Globals::loadPreview (const CString &filename) {
    
      IShellFolder *deskFolder = NULL; 
      HBITMAP hBmpImage = NULL;
      HRESULT hr = SHGetDesktopFolder(&deskFolder); 
      if (!FAILED(hr)) {
    
        CComBSTR oleFile = filename;
        LPITEMIDLIST pidlLocal = NULL; 
        hr = deskFolder->ParseDisplayName(NULL, NULL, oleFile, NULL, &pidlLocal, NULL); 
    
        if (!FAILED(hr)) { 
    	    LPITEMIDLIST l = ILFindLastID(pidlLocal);
          LPITEMIDLIST pidlRelative = ILClone(l); 
          ILRemoveLastID(pidlLocal); 
    
          IShellFolder *appObject = NULL; 
          hr = deskFolder->BindToObject(pidlLocal, NULL, IID_IShellFolder, (void**)&appObject); 
          ILFree(pidlLocal); 
    
          if (!FAILED(hr)) {
    
            IExtractImage* pIExtract = NULL;
            hr = appObject->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlRelative, IID_IExtractImage, 
                                          NULL, (void**)&pIExtract); 
    
            if (!FAILED(hr)) {
              DWORD dwRecClrDepth = 24;
              SIZE prgSize = { IMAGE_WIDTH, IMAGE_HEIGTH };
    
              OLECHAR wszPathBuffer[MAX_PATH];
              DWORD dwPriority = 0;   // IEI_PRIORITY_NORMAL is defined nowhere!
              DWORD dwFlags = IEIFLAG_SCREEN;
              hr = pIExtract->GetLocation(wszPathBuffer, MAX_PATH, &dwPriority,
                                          &prgSize, dwRecClrDepth, &dwFlags);
               // even if we've got shell v4.70+, not all files support thumbnails 
              if(NOERROR == hr || E_PENDING == hr) {
                hr = pIExtract->Extract(&hBmpImage);
              }
              pIExtract->Release();
            } 
            appObject->Release(); 
            ILFree(pidlRelative); 
          } 
        } 
        deskFolder->Release(); 
      }
      Gdiplus::Bitmap* rBmp = NULL;
      if (NOERROR == hr) {
        rBmp = new Gdiplus::Bitmap(hBmpImage, NULL);
      }
      if (NULL != hBmpImage) {
        DeleteObject(hBmpImage);
      }
      return rBmp;
    }
    

Anmelden zum Antworten