It is not an easy task, I quickly made this example of use of IPreviewHandler. But It looks that work only with pdf file
Code: Select all
#include <fivewin.ch>
memvar oPreview
function main()
local oDlg
public oPreview
// IMPORTANT!!
CoInitialize()
DEFINE WINDOW oDlg FROM 0,0 TO 650,650 PIXEL TITLE "Test"
oPreview := AddPreview( oDlg:hWnd, {10,10,610,610}, "C:\Users\aperricone\Downloads\grid.pdf")
ACTIVATE WINDOW oDlg CENTERED
return nil
#pragma BEGINDUMP
#define CINTERFACE
#define COBJMACROS
#include <windows.h>
#include <hbapi.h>
#include <CommCtrl.h>
#include <ShObjIdl.h>
#include <Shlwapi.h>
#include <ShlGuid.h>
LPWSTR AnsiToWide( LPSTR cAnsi );
IPreviewHandler* GetIPreviewHandler(const wchar_t* cExtension)
{
CLSID cls;
wchar_t clsStr[250];
wchar_t cKey[250];
LONG nLen=250;
IPreviewHandler* pRet=0;
HRESULT hr;
if(cExtension == 0 ) return 0;
wcscpy_s(cKey,250, cExtension);
wcscat_s(cKey,250, L"\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
if( ERROR_SUCCESS != RegQueryValueW(HKEY_CLASSES_ROOT, cKey, clsStr, &nLen) )
{
RegQueryValueW(HKEY_CLASSES_ROOT, cExtension, cKey, &nLen);
wcscat_s(cKey,250, L"\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
MessageBoxW(0,cKey,cExtension,MB_OK);
if( ERROR_SUCCESS != RegQueryValueW(HKEY_CLASSES_ROOT, cKey, clsStr, &nLen) )
return 0;
}
CLSIDFromString( clsStr,&cls);
#if defined(__cplusplus)
if((hr = CoCreateInstance( cls, 0, CLSCTX_ALL, IID_IPreviewHandler, ( void ** ) &pRet ) )==S_OK)
#else
if((hr = CoCreateInstance( &cls, 0, CLSCTX_ALL, &IID_IPreviewHandler, ( void ** ) &pRet ) )==S_OK)
#endif
{
return pRet;
}
swprintf(cKey,250,L"%i",hr);
MessageBoxW(0,cKey,cExtension,MB_OK);
return 0;
}
HB_FUNC( ADDPREVIEW ) // hWnd, {nTop, nLeft, nBottom, nRight}, cFileName
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#define RET hb_retnl( (long) pPreview );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#define RET hb_retnll( (long long) pPreview );
#endif
RECT rectPreview;
LPWSTR cFileName = AnsiToWide(( char * ) hb_parc( 3 ));
LPCWSTR cExtension = wcsrchr(cFileName,L'.');
IPreviewHandler* pPreview = GetIPreviewHandler(cExtension);
IInitializeWithFile* pFile;
IInitializeWithStream* pIStream;
if(pPreview==0)
{
MessageBoxW(0,L"no pPreview",cExtension,MB_OK);
RET
return;
}
IPreviewHandler_QueryInterface(pPreview, &IID_IInitializeWithFile,(void**)&pFile );
IPreviewHandler_QueryInterface(pPreview, &IID_IInitializeWithStream,(void**)&pIStream );
if(pFile==0 && pIStream==0)
{
MessageBoxW(0,L"no pfile no pStream",cExtension,MB_OK);
IPreviewHandler_Unload(pPreview);
pPreview = 0;
RET
return;
}
if(pFile!=0)
{
IInitializeWithFile_Initialize(pFile, cFileName, STGM_READ);
} else
{ //pIStream!=0
HANDLE hFile = CreateFileW(cFileName,FILE_READ_DATA,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL );
if( INVALID_HANDLE_VALUE != hFile )
{
DWORD dwSize = GetFileSize( hFile, NULL );
HGLOBAL hGlobal= GlobalAlloc(GPTR, dwSize );
BYTE * pByte = (BYTE *)GlobalLock(hGlobal);
if( pByte )
{
LPSTREAM pStream;
ReadFile(hFile,pByte,dwSize,&dwSize,NULL);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
IInitializeWithStream_Initialize(pIStream, pStream, STGM_READ);
}
CloseHandle( hFile );
}
}
hb_xfree( cFileName );
rectPreview.top = hb_parvni(2,1);
rectPreview.left = hb_parvni(2,2);
rectPreview.bottom = hb_parvni(2,3);
rectPreview.right = hb_parvni(2,4);
IPreviewHandler_SetWindow( pPreview, hWnd, &rectPreview );
IPreviewHandler_DoPreview( pPreview );
RET
}
HB_FUNC( UnloadPreview ) //preview
{
#ifndef _WIN64
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnl( 1 );
#else
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnll( 1 );
#endif
if( pPreview )
{
IPreviewHandler_Unload(pPreview);
}
}
#pragma ENDDUMP