ListGetPreviewBitmap
ListGetPreviewBitmap is called to retrieve a bitmap for the thumbnails view. Please only implement and export this function if it makes sense to show preview pictures for the supported file types! This function is new in version 1.4. It requires Total Commander >=6.5, but is ignored by older versions.
Declaration:
HBITMAP __stdcall ListGetPreviewBitmap(char* FileToLoad,int width,int height,
char* contentbuf,int contentbuflen);
Description of parameters:
FileToLoad The name of the file for which to load the preview bitmap.
width Requested maximum width of the bitmap.
height Requested maximum height of the bitmap
contentbuf The first 8 kBytes (8k) of the file. Often this is enough data to show a reasonable preview, e.g. the first few lines of a text file.
contentbuflen The length of the data passed in contentbuf. Please note that contentbuf is not a 0 terminated string, it may contains 0 bytes in the middle! It's just the 1:1 contents of the first 8k of the file.
Return value:
Return a device-dependent bitmap created with e.g. CreateCompatibleBitmap.
Notes:
1. This function is only called in Total Commander 6.5 and later. The plugin version will be >= 1.4.
2. The bitmap handle goes into possession of Total Commander, which will delete it after using it. The plugin must not delete the bitmap handle!
3. Make sure you scale your image correctly to the desired maximum width+height! Do not fill the rest of the bitmap - instead, create a bitmap which is SMALLER than requested! This way, Total Commander can center your image and fill the rest with the default background color.
The following sample code will stretch a bitmap with dimensions bigwidth*bigheight down to max. width*height keeping the correct aspect ratio (proportions):
HBITMAP __stdcall ListGetPreviewBitmap(char* FileToLoad,int width,int height,
char* contentbuf,int contentbuflen)
{
int w,h;
int stretchx,stretchy;
OSVERSIONINFO vx;
BOOL is_nt;
BITMAP bmpobj;
HBITMAP bmp_image,bmp_thumbnail,oldbmp_image,oldbmp_thumbnail;
HDC maindc,dc_thumbnail,dc_image;
POINT pt;
// check for operating system: Windows 9x does NOT support the HALFTONE stretchblt mode!
vx.dwOSVersionInfoSize=sizeof(vx);
GetVersionEx(&vx);
is_nt=vx.dwPlatformId==VER_PLATFORM_WIN32_NT;
// here you load your image
bmp_image=SomeHowLoadImageFromFile(FileToLoad);
if (bmp_image && GetObject(bmp_image,sizeof(bmpobj),&bmpobj)) {
bigx=bmpobj.bmWidth;
bigy=bmpobj.bmHeight;
// do we need to stretch?
if ((bigx>=width || bigy>=height) && (bigx>0 && bigy>0)) {
stretchy=MulDiv(width,bigy,bigx);
if (stretchy<=height) {
w=width;
h=stretchy;
if (h<1) h=1;
} else {
stretchx=MulDiv(height,bigx,bigy);
w=stretchx;
if (w<1) w=1;
h=height;
}
maindc=GetDC(GetDesktopWindow());
dc_thumbnail=CreateCompatibleDC(maindc);
dc_image=CreateCompatibleDC(maindc);
bmp_thumbnail=CreateCompatibleBitmap(maindc,w,h);
ReleaseDC(GetDesktopWindow(),maindc);
oldbmp_image=(HBITMAP)SelectObject(dc_image,bmp_image);
oldbmp_thumbnail=(HBITMAP)SelectObject(dc_thumbnail,bmp_thumbnail);
if(is_nt) {
SetStretchBltMode(dc_thumbnail,HALFTONE);
SetBrushOrgEx(dc_thumbnail,0,0,&pt);
} else {
SetStretchBltMode(dc_thumbnail,COLORONCOLOR);
}
StretchBlt(dc_thumbnail,0,0,w,h,dc_image,0,0,bigx,bigy,SRCCOPY);
SelectObject(dc_image,oldbmp_image);
SelectObject(dc_thumbnail,oldbmp_thumbnail);
DeleteDC(dc_image);
DeleteDC(dc_thumbnail);
DeleteObject(bmp_image);
bmp_image=bmp_thumbnail;
}
}
return bmp_image;
}