#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
Silvio.Falconi wrote:Antonio,
any solution with borland bc582 ?
mastintin wrote:I spent part of a c ++ code and it works with xls and doc files.
When you have finished public code
Silvio.Falconi wrote:Can I show the preview of a file with Image class ?
sample I have namedoc.doc or noname.pdf can I show the preview on dialog ?
#include <hbapi.h>
#include <windows.h>
#include <shobjidl.h>
HB_FUNC( CREATEHPREVIEW ) //preview
{
#ifndef _WIN64
#define RET hb_retnl( (long) pPreview );
#else
#define RET hb_retnll( (long long) pPreview );
#endif
LPWSTR cFileName = UTF8toUTF16( hb_parc( 1 ) );
LPCWSTR cExtension = wcsrchr(cFileName,L'.');
CLSID cls;
wchar_t clsStr[250];
wchar_t cKey[250];
LONG nLen=250;
IPreviewHandler* pPreview=0;
HRESULT hr;
if(cExtension == 0 ) {
pPreview = 0;
RET
return;
}
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) )
{
pPreview = 0;
RET
return;
}
}
CLSIDFromString( clsStr,&cls);
if( S_OK == CoCreateInstance(cls, NULL, CLSCTX_INPROC_SERVER |CLSCTX_LOCAL_SERVER, __uuidof(IPreviewHandler),(LPVOID*)&pPreview) )
{
RET
return;
}
MessageBoxW(0,cKey,cExtension,MB_OK);
pPreview = 0;
RET
return;
}
HB_FUNC( ADDPREVIEWH ) // hWnd, {nTop, nLeft, nBottom, nRight}, cFileName, pPreview
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnl( 4 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnll( 4 );
#endif
RECT rectPreview;
LPWSTR cFileName = UTF8toUTF16( hb_parc( 3 ) );
LPCWSTR cExtension = wcsrchr(cFileName,L'.');
IInitializeWithFile* pFile;
IInitializeWithStream* pIStream;
if(pPreview==0)
{
MessageBoxW(0,L"no pPreview",cExtension,MB_OK);
RET
return;
}
pPreview->QueryInterface(__uuidof( IInitializeWithFile ), (LPVOID*)&pFile );
pPreview->QueryInterface(__uuidof( IInitializeWithStream ), (LPVOID*)&pIStream );
if(pFile==0 && pIStream==0)
{
MessageBoxW(0,L"no pfile no pStream",cExtension,MB_OK);
pPreview->Unload();
pPreview = 0;
RET
return;
}
if(pFile!=0)
{
pFile->Initialize( 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);
pIStream->Initialize( 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);
pPreview->SetWindow( hWnd, &rectPreview );
pPreview->DoPreview();
// pPreview->Unload();
delete pIStream ;
/*
#ifndef _WIN64
hb_retnl( (long) pIStream );
#else
hb_retnll( (long long) pIStream );
#endif
*/
}
HB_FUNC( UNLOADHPREVIEW ) //preview
{
#ifndef _WIN64
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnl( 1 );
#else
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnll( 1 );
#endif
pPreview->Unload();
}
#include <fivewin.ch>
memvar oPreview
function main()
local oDlg
local hStream
local cFile
public oPreview
// IMPORTANT!!
cFile:= cGetfile("coge","*.*")
if !empty( cfile )
CoInitialize()
DEFINE WINDOW oDlg FROM 0,0 TO 650,650 PIXEL TITLE "Test"
oPreview := CreateHPreview( cFile )
AddPreviewH( oDlg:hWnd, {10,10,610,610}, cFile , oPreview )
ACTIVATE WINDOW oDlg CENTERED
endif
return nil
pPreview->Unload();
pPreview->Release();
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 95 guests