Thread: Curious about thumdnails

  1. #1
    Registered User
    Join Date
    Sep 2003

    Curious about thumdnails

    I'm just curious how can I make my program to draw thumbnail of file of it's type in windows explorer like a .gif file?

    Is there eny resource about this? I'd prefer it for MFC.

    Sorry for my bed English

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    EDIT: Whoops, I just realised your post is asking how to create a thumbnail provider rather than how to get a thumbnail.

    WARNING: The following post is rated R. It contains frequent use of goto.

    - The following code is in C and is adapted from much more complicated C++ code here. See ThumbExtract\FileThumbExtract.cpp in the zip sample.
    - This is not restricted to loading thumbnails for images. Other application install thumbnail providers for their document formats. Unfortunately, the web page thumbnail provider seems to have been removed in XP(?Why?). It is available in previous versions(9x/2000/NT).
    - The sample code simply blits the thumbnail to the screen to keep the code short.
    - This code will be fairly uncomprehensible if you have never seen the shell interfaces, even more so if you are not familiar with COM.
    - Post back if you have queries.

    #include <shlobj.h>
    #include <stdio.h>
    #include <wchar.h>
    #include <tchar.h>
    #define SAFE_RELEASE(pObj)   if (pObj) { (pObj)->lpVtbl->Release(pObj); (pObj) = NULL; }
    #define SAFE_MALLOC_FREE(pv) if (pv)   { IMallocFree(pv); (pv) = NULL; }
    #define HR_TRY(func)         if (FAILED(func)) { printf("Error: %s\n", #func); goto cleanup; }
    VOID IMallocFree(LPVOID pv)
    	static IMalloc * pMalloc;
    	if (!pMalloc) SHGetMalloc(&pMalloc);
    	if (pMalloc)  pMalloc->lpVtbl->Free(pMalloc, pv);
    HRESULT CreateThumbnail(LPOLESTR szPath, LPOLESTR szFile, DWORD dwWidth, DWORD dwHeight, HBITMAP * pThumbnail)
       LPITEMIDLIST pidlURL       = NULL,
                    pidlWorkDir   = NULL;
       DWORD        dwPriority    = 0,
                    dwFlags       = IEIFLAG_ASPECT;
       HRESULT      hr;
       SIZE         size;
       WCHAR        szBuffer[MAX_PATH];
       IExtractImage * peiURL     = NULL;
       IShellFolder  * psfWorkDir = NULL;
       IShellFolder  * psfDesktop = NULL;
   = dwWidth; = dwHeight;
       HR_TRY(hr = SHGetDesktopFolder(&psfDesktop));
       HR_TRY(hr = psfDesktop->lpVtbl->ParseDisplayName(psfDesktop, NULL, NULL, szPath, NULL, &pidlWorkDir, NULL));
       HR_TRY(hr = psfDesktop->lpVtbl->BindToObject(psfDesktop, pidlWorkDir, NULL, &IID_IShellFolder, &psfWorkDir));
       HR_TRY(hr = psfWorkDir->lpVtbl->ParseDisplayName(psfWorkDir, NULL, NULL, szFile, NULL, &pidlURL, NULL));
       HR_TRY(hr = psfWorkDir->lpVtbl->GetUIObjectOf(psfWorkDir, NULL, 1, &pidlURL, &IID_IExtractImage, NULL, &peiURL));
       HR_TRY(hr = peiURL->lpVtbl->GetLocation(peiURL, szBuffer, MAX_PATH, &dwPriority, &size, 16, &dwFlags));
       HR_TRY(hr = peiURL->lpVtbl->Extract(peiURL, pThumbnail));
       return hr;
    int main(void)
    	HRESULT hr;
    	HBITMAP hBitmap;
    	if (FAILED(
    	   hr = CreateThumbnail(L"C:\\Documents and Settings\\User\\My Documents\\",
    	                             L"test.gif", 120, 120, &hBitmap)
    		TCHAR msg[256];
    		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, hr, LANG_USER_DEFAULT, msg, 256, NULL);
    		_tprintf(_T("hr = %x, msg = %s\n"), hr, msg);
    		HDC hdc      = CreateCompatibleDC(NULL);
    		HBITMAP hOld = SelectObject(hdc, hBitmap);
    		BitBlt(GetDC(NULL), 0, 0, 120, 120, hdc, 0, 0, SRCCOPY); 
    		SelectObject(hdc, hOld);
    	return 0;
    Last edited by anonytmouse; 03-08-2004 at 10:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Curious GCC error messages
    By Mario F. in forum Tech Board
    Replies: 1
    Last Post: 11-22-2006, 04:57 PM
  2. C++ and the internet, just curious
    By AdamLAN in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2004, 05:16 PM
  3. Just curious
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2004, 10:57 AM
  4. A curious question
    By sbongo in forum A Brief History of
    Replies: 7
    Last Post: 01-02-2004, 09:55 PM
  5. Curious About Master Boot Record
    By civix in forum Tech Board
    Replies: 1
    Last Post: 01-26-2003, 02:19 AM