FsGetPreviewBitmap
FsGetPreviewBitmap is called when a file/directory is displayed in thumbnail view. It can be used to return a custom bitmap for that file/directory. This function is new in version 1.4. It requires Total Commander >=7.0, but is ignored by older versions.
Declaration:
int __stdcall FsGetPreviewBitmap(char* RemoteName, int width, int height, HBITMAP* ReturnedBitmap);
Description of parameters:
RemoteName This is the full path to the file or directory whose bitmap is to be retrieved. When extracting a bitmap, you can return a bitmap name here - this ensures that the icon is only cached once in the calling program. The returned bitmap name must not be longer than MAX_PATH characters (including terminating 0!). The bitmap handle must still be returned in ReturnedBitmap!
width, height The maximum dimensions of the preview bitmap. If your image is smaller, or has a different side ratio, then you need to return an image which is smaller than these dimensions! See notes below!
ReturnedBitmap Here you need to return the bitmap handle.
Return value:
The function has to return one of the following values:
FS_BITMAP_NONE There is no preview bitmap.
FS_BITMAP_EXTRACTED The image was extracted and is returned in ReturnedBitmap
FS_BITMAP_EXTRACT_YOURSELF Tells the caller to extract the image by itself. The full local path to the file needs to be returned in RemoteName. The returned bitmap name must not be longer than MAX_PATH.
FS_BITMAP_EXTRACT_YOURSELF_ANDDELETE
Tells the caller to extract the image by itself, and then delete the temporary image file. The full local path to the temporary image file needs to be returned in RemoteName. The returned bitmap name must not be longer than MAX_PATH. In this case, the plugin downloads the file to TEMP and then asks TC to extract the image.
FS_BITMAP_CACHE This value must be ADDED to one of the above values if the caller should cache the image. Do NOT add this image if you will cache the image yourself!
Important notes:
1. This function is only called in Total Commander 7.0 and later. The reported 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.
4. 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):
int __stdcall FsGetPreviewBitmap(char* RemoteName,int width,int height, HBITMAP* ReturnedBitmap)
{
int w,h,bigx,bigy;
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(RemoteName);
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);
*ReturnedBitmap=bmp_thumbnail;
return FS_BITMAP_EXTRACTED | FS_BITMAP_CACHE;
}
*ReturnedBitmap=bmp_image;
return FS_BITMAP_EXTRACTED | FS_BITMAP_CACHE;
}
return FS_BITMAP_NONE;
}