mastintin wrote:txt, bat file not work properly yet ( I've looked )
The preview is for a service that some installed program provides, Images and text files are easily preview-able so there is no service.
mastintin wrote:txt, bat file not work properly yet ( I've looked )
#include <hbclass.ch>
FUNCTION ExaVal( cString )
LOCAL nX, nVal
LOCAL cNewString := upper(AllTrim( cString ))
LOCAL nLen := Len( cNewString )
LOCAL nNumber := 0
FOR nX := 1 TO nLen
nVal := At( SubStr( cNewString, nX, 1 ), "0123456789ABCDEF" ) - 1
if nVal<0
return 0
endif
nNumber += ( nVal * ( 16 ** ( nLen - nX ) ) )
NEXT
RETURN nNumber
FUNC iidFromString(str)
LOCAL r
//example: {00000000-0000-0000-0000-000000000000}
// 12345678901234567890123456789012345678
// 1 2 3
if len(str)<>38 .or. ;
substr(str,1,1) <> "{" .or. substr(str,38,1) <> "}" .or. ;
substr(str,10,1) <> "-" .or. substr(str,15,1) <> "-" .or. ;
substr(str,20,1) <> "-" .or. substr(str,25,1) <> "-"
return {}
endif
r := Array(11)
r[1] := ExaVal(substr(str,2,8))
r[2] := ExaVal(substr(str,11,4))
r[3] := ExaVal(substr(str,16,4))
r[4] := ExaVal(substr(str,21,2))
r[5] := ExaVal(substr(str,23,2))
r[6] := ExaVal(substr(str,26,2))
r[7] := ExaVal(substr(str,28,2))
r[8] := ExaVal(substr(str,30,2))
r[9] := ExaVal(substr(str,32,2))
r[10] := ExaVal(substr(str,34,2))
r[11] := ExaVal(substr(str,36,2))
return r
CLASS IUnknown
DATA iPtr
METHOD New(iptr) CONSTRUCTOR
METHOD AddRef()
Destructor Release()
METHOD QueryInterface(riid, dest)
METHOD SetPtr(ptr)
endclass
METHOD New(iptr) CLASS IUnknown
::iPtr := iptr
return Self
METHOD SetPtr(ptr) CLASS IUnknown
if Valtype(::iPtr) == "P"
::Release()
endif
::iPtr := ptr
if Valtype(::iPtr) == "P"
::AddRef()
endif
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#include <hbstack.h>
#include <hbapiitm.h>
#include <stdio.h>
/* 0*/ typedef HRESULT (__stdcall *IUnknown_QueryInterface )(void* This,REFIID riid,void **ppvObject);
/* 1*/ typedef ULONG (__stdcall *IUnknown_AddRef )(void* This);
/* 2*/ typedef ULONG (__stdcall *IUnknown_Release )(void* This);
void* GetFunctionPtr(void* ptrInt,int id)
{
void** _i = (void**)(*(void**)ptrInt);
return _i+id;
}
GUID GUIDFromArray(PHB_ITEM pArr)
{
GUID ret;
ret.Data1 = (unsigned long)(hb_itemGetND(hb_itemArrayGet(pArr,1)));
ret.Data2 = (unsigned short)hb_itemGetNL(hb_itemArrayGet(pArr,2));
ret.Data3 = (unsigned short)hb_itemGetNL(hb_itemArrayGet(pArr,3));
ret.Data4[0] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,4));
ret.Data4[1] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,5));
ret.Data4[2] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,6));
ret.Data4[3] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,7));
ret.Data4[4] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,8));
ret.Data4[5] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,9));
ret.Data4[6] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,10));
ret.Data4[7] = (unsigned char)hb_itemGetNL(hb_itemArrayGet(pArr,11));
return ret;
}
HB_FUNC( COCREATEINSTANCE ) //clsid, ctx, riid, dest
{
GUID clsid = GUIDFromArray(hb_param(1, HB_IT_ARRAY ));
DWORD ctx = hb_parnl( 2 );
GUID riiid = GUIDFromArray(hb_param(3, HB_IT_ARRAY ));
void* ptr;
//wchar_t test[50];
//StringFromGUID2(&clsid,test,50);
//MessageBoxW(0,test,L"CLSID",MB_OK);
//StringFromGUID2(&riiid,test,50);
//MessageBoxW(0,test,L"RIIID",MB_OK);
HRESULT hr;
#if defined(__cplusplus)
hr = CoCreateInstance( clsid, 0, ctx, riiid, ( void ** ) &ptr );
#else
hr = CoCreateInstance( &clsid, 0, ctx, &riiid, ( void ** ) &ptr );
#endif
if(ptr)
hb_storptr(ptr, 4);
else
hb_stor(4);
hb_retnl(hr);
}
HB_FUNC( IUNKNOWN_QUERYINTERFACE )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
if(ptr)
{
IUnknown_QueryInterface* fn = (IUnknown_QueryInterface*)GetFunctionPtr(ptr,0);
GUID riiid = GUIDFromArray(hb_param(1, HB_IT_ARRAY ));
void* pvObject;
HRESULT ret = (*fn)(ptr,&riiid,&pvObject);
if( pvObject != 0 )
hb_storptr(pvObject,2);
else
hb_stor(2);
hb_retnl(ret);
} else
{
hb_stor(2); //nil
hb_retnl(0x8032001C); //A required pointer is null.
}
}
HB_FUNC( IUNKNOWN_ADDREF )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
ULONG ret;
if( ptr )
{
IUnknown_AddRef* fn = (IUnknown_AddRef*)GetFunctionPtr(ptr,1);
ret = (*fn)(ptr);
} else
{
ret = 0x8032001C; //A required pointer is null.
}
hb_retnl(ret);
}
HB_FUNC( IUNKNOWN_RELEASE )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
ULONG ret;
if( ptr )
{
IUnknown_Release* fn = (IUnknown_Release*)GetFunctionPtr(ptr,2);
ret = (*fn)(ptr);
} else
{
ret = 0x8032001C; //A required pointer is null.
}
hb_retnl(ret);
}
#pragma ENDDUMP
#include <hbclass.ch>
/* From ShObjIdl.idl
[
object,
uuid(8895b1c6-b41f-4c1c-a562-0d564250836f),
]
interface IPreviewHandler : IUnknown
{
HRESULT SetWindow(
[in] HWND hwnd,
[in] const RECT *prc);
HRESULT SetRect([in] const RECT *prc);
HRESULT DoPreview();
HRESULT Unload();
HRESULT SetFocus();
HRESULT QueryFocus([out] HWND* phwnd);
HRESULT TranslateAccelerator([in] MSG* pmsg);
}
*/
#define IID_IPreviewHandler {0x8895b1c6,0xb41f,0x4c1c,0xa5,0x62,0x0d,0x56,0x42,0x50,0x83,0x6f}
class IPreviewHandler FROM IUnknown
METHOD SetWindow(hwnd,prc)
METHOD SetRect(prc)
METHOD DoPreview()
METHOD Unload()
METHOD SetFocus()
METHOD QueryFocus(phwnd)
//METHOD TranslateAccelerator(pmsg); msg strunct non handled
endclass
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#include <hbstack.h>
#include <hbapiitm.h>
/* 3*/typedef HRESULT (__stdcall *IPreviewHandler_SetWindow)(void* This,HWND hwnd,const RECT *prc);
/* 4*/typedef HRESULT (__stdcall *IPreviewHandler_SetRect)(void* This,const RECT *prc);
/* 5*/typedef HRESULT (__stdcall *IPreviewHandler_DoPreview)(void* This);
/* 6*/typedef HRESULT (__stdcall *IPreviewHandler_Unload)(void* This);
/* 7*/typedef HRESULT (__stdcall *IPreviewHandler_SetFocus)(void* This);
/* 8*/typedef HRESULT (__stdcall *IPreviewHandler_QueryFocus)(void* This,HWND* phwnd);
/* 9*/typedef HRESULT (__stdcall *IPreviewHandler_TranslateAccelerator)(void* This,MSG* pmsg);
void* GetFunctionPtr(void* ptrInt,int id);
HB_FUNC( IPREVIEWHANDLER_SETWINDOW )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IPreviewHandler_SetWindow* fn = (IPreviewHandler_SetWindow*)GetFunctionPtr(ptr,3);
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
RECT rc,*prc = NULL;
HRESULT retVal;
if( hb_param(2, HB_IT_ARRAY) != 0 )
{
rc.top = hb_parvni( 2, 1);
rc.left = hb_parvni( 2, 2);
rc.bottom = hb_parvni( 2, 3);
rc.right = hb_parvni( 2, 4);
prc = &rc;
} else prc = 0;
retVal = (*fn)(ptr,hWnd,prc);
hb_retnl(retVal);
}
HB_FUNC( IPREVIEWHANDLER_SETRECT )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IPreviewHandler_SetRect* fn = (IPreviewHandler_SetRect*)GetFunctionPtr(ptr,4);
RECT rc,*prc = NULL;
HRESULT retVal;
if( hb_param(1, HB_IT_ARRAY) != 0 )
{
rc.top = hb_parvni( 1, 1);
rc.left = hb_parvni( 1, 2);
rc.bottom = hb_parvni( 1, 3);
rc.right = hb_parvni( 1, 4);
prc = &rc;
} else prc = 0;
retVal = (*fn)(ptr,prc);
hb_retnl(retVal);
}
HB_FUNC( IPREVIEWHANDLER_DOPREVIEW )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IPreviewHandler_DoPreview* fn = (IPreviewHandler_DoPreview*)GetFunctionPtr(ptr,5);
HRESULT retVal;
retVal = (*fn)(ptr);
hb_retnl(retVal);
}
HB_FUNC( IPREVIEWHANDLER_UNLOAD )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IPreviewHandler_Unload* fn = (IPreviewHandler_Unload*)GetFunctionPtr(ptr,6);
HRESULT retVal;
retVal = (*fn)(ptr);
hb_retnl(retVal);
}
HB_FUNC( IPREVIEWHANDLER_SETFOCUS )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IPreviewHandler_SetFocus* fn = (IPreviewHandler_SetFocus*)GetFunctionPtr(ptr,7);
HRESULT retVal;
retVal = (*fn)(ptr);
hb_retnl(retVal);
}
HB_FUNC( IPREVIEWHANDLER_QUERYFOCUS )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IPreviewHandler_QueryFocus* fn = (IPreviewHandler_QueryFocus*)GetFunctionPtr(ptr,7);
HWND hWnd;
HRESULT retVal;
retVal = (*fn)(ptr,&hWnd);
#ifndef _WIN64
hb_stornl((long)hWnd,1);
#else
hb_stornll((HB_LONGLONG)hWnd,1);
#endif
hb_retnl(retVal);
}
#pragma ENDDUMP
#include <hbclass.ch>
/* From propsys.idl
[
uuid(b7d14566-0509-4cce-a71f-0a554233bd9b),
object,
pointer_default(unique)
]
interface IInitializeWithFile : IUnknown
{
HRESULT Initialize([in, string] LPCWSTR pszFilePath, [in] DWORD grfMode);
}
*/
#define IID_IInitializeWithFile {0xb7d14566,0x0509,0x4cce,0xa7,0x1f,0x0a,0x55,0x42,0x33,0xbd,0x9b}
class IInitializeWithFile FROM IUnknown
METHOD Initialize(pszFilePath,grfMode)
endclass
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#include <hbstack.h>
#include <hbapiitm.h>
/* 3*/typedef HRESULT (__stdcall *IInitializeWithFile_Initialize)(void* This,LPCWSTR pszFilePath, DWORD grfMode);
void* GetFunctionPtr(void* ptrInt,int id);
LPWSTR UTF8toUTF16( LPCSTR utf8 );
HB_FUNC( IINITIALIZEWITHFILE_INITIALIZE )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IInitializeWithFile_Initialize* fn = (IInitializeWithFile_Initialize*)GetFunctionPtr(ptr,3);
LPCWSTR pszFilePath = UTF8toUTF16(hb_parc(1));
DWORD grfMode = hb_parnl(2);
HRESULT retVal;
retVal = (*fn)(ptr,pszFilePath,grfMode);
hb_xfree( (void*) pszFilePath);
hb_retnl(retVal);
}
#pragma ENDDUMP
#include <hbclass.ch>
/* From propsys.idl
[
uuid(b824b49d-22ac-4161-ac8a-9916e8fa3f7f),
object,
pointer_default(unique)
]
interface IInitializeWithStream : IUnknown
{
[local] HRESULT Initialize([in, annotation("_In_")] IStream *pstream, [in, annotation("_In_")] DWORD grfMode);
[call_as(Initialize)] HRESULT RemoteInitialize([in] IStream *pstream, [in] DWORD grfMode);
}*/
#define IID_IInitializeWithStream {0xb824b49d,0x22ac,0x4161,0xac,0x8a,0x99,0x16,0xe8,0xfa,0x3f,0x7f}
class IInitializeWithStream FROM IUnknown
METHOD Initialize(pstream, grfMode)
endclass
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#include <hbstack.h>
#include <hbapiitm.h>
/* 3*/typedef HRESULT (__stdcall *IInitializeWithStream_Initialize)(void* This,IStream *pstream, DWORD grfMode);
void* GetFunctionPtr(void* ptrInt,int id);
HB_FUNC( IINITIALIZEWITHSTREAM_INITIALIZE )
{
PHB_ITEM pSelf = hb_stackSelfItem();
void* ptr = hb_itemGetPtr(hb_itemArrayGet(pSelf,1));
IInitializeWithStream_Initialize* fn = (IInitializeWithStream_Initialize*)GetFunctionPtr(ptr,3);
IStream* pstream = (IStream*) hb_parptr(1);
DWORD grfMode = hb_parnl(2);
HRESULT retVal;
retVal = (*fn)(ptr,pstream,grfMode);
hb_retnl(retVal);
}
#pragma ENDDUMP
#include <fivewin.ch>
#include <winapi.ch>
function main()
local oDlg
local oPreview
// IMPORTANT!!
CoInitialize()
DEFINE WINDOW oDlg FROM 0,0 TO 650,650 PIXEL TITLE "Test"
oPreview := TPreviewControl():New(30,10,oDlg, 600,600)
oPreview:AcceptDropFile()
@ 8,8 BUTTON "Clear" ACTION oPreview:Clear() PIXEL SIZE 32,16 OF oDlg
ACTIVATE WINDOW oDlg CENTERED
return nil
CLASS TPreviewControl FROM TControl
CLASSDATA lRegistered AS LOGICAL
DATA pPreview INIT 0
DATA pStream INIT 0
METHOD New( nRow, nCol, oWnd, nWidth, nHeight ) CONSTRUCTOR
METHOD Destroy()
METHOD SetFile(cFile)
METHOD AcceptDropFile()
METHOD Clear()
METHOD DropFiles( hDrop )
METHOD Resize()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
ENDCLASS
METHOD New( nRow, nCol, oWnd, nWidth, nHeight ) CLASS TPreviewControl
DEFAULT nRow := 10, nCol := 10, oWnd := GetWndDefault(), nWidth := 64, nHeight := 64
::oWnd := oWnd
::nId := ::GetNewId()
::nStyle := nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_CLIPCHILDREN )
::nTop := nRow
::nLeft := nCol
::nBottom := ::nTop + nHeight - 1
::nRight := ::nLeft + nWidth
::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
::Create()
oWnd:AddControl( Self )
return Self
METHOD Destroy()
::Clear()
return ::Super:Destroy()
METHOD Clear() CLASS TPreviewControl
if valtype(::pPreview) == "O"
::pPreview:Unload()
endif
if Valtype(::pStream) == "P"
DestroyStream(::pStream)
endif
::pPreview := 0
::pStream := 0
return nil
#define HKEY_CLASSES_ROOT 2147483648 // 0x80000000
#define IID_IPreviewHandler {0x8895b1c6,0xb41f,0x4c1c,0xa5,0x62,0x0d,0x56,0x42,0x50,0x83,0x6f}
#define IID_IInitializeWithFile {0xb7d14566,0x0509,0x4cce,0xa7,0x1f,0x0a,0x55,0x42,0x33,0xbd,0x9b}
#define IID_IInitializeWithStream {0xb824b49d,0x22ac,0x4161,0xac,0x8a,0x99,0x16,0xe8,0xfa,0x3f,0x7f}
#define CLSCTX_INPROC_SERVER 0x1
#define CLSCTX_LOCAL_SERVER 0x4
METHOD SetFile(cFile) CLASS TPreviewControl
LOCAL cExtension, cKey, cid, nError, cls
LOCAL pInit
::Clear()
cExtension := substr(cFile,rat(".",cFile))
cKey = cExtension + "\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}"
cid := ""
//get preview guid
nError = RegQueryValue( HKEY_CLASSES_ROOT, cKey, @cid )
if nError <> 0
cKey := Space(100)
RegQueryValue( HKEY_CLASSES_ROOT, cExtension, @cKey )
cKey := StrTran( cKey, Chr(0), "" )
cKey := Alltrim(cKey) + "\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}"
nError = RegQueryValue( HKEY_CLASSES_ROOT, cKey, @cid )
endif
// crete the preview object
if nError = 0
cid := StrTran( cid, Chr(0), "" )
cls := iidFromString(cid)
nError := CoCreateInstance( cls, nOr( CLSCTX_INPROC_SERVER, CLSCTX_LOCAL_SERVER), IID_IPreviewHandler, @::pPreview )
endif
if Valtype(::pPreview) == "P"
::pPreview := IPreviewHandler():New(::pPreview)
//init the preview
::pPreview:QueryInterface(IID_IInitializeWithFile, @pInit)
if Valtype(pInit) == "P"
pInit := IInitializeWithFile():New(pInit)
pInit:Initialize(cFile, /*STGM_READ*/0)
else
::pPreview:QueryInterface(IID_IInitializeWithStream, @pInit)
if Valtype(pInit) == "P"
pInit := IInitializeWithStream():New(pInit)
::pStream := GetStream(cFile)
pInit:Initialize(::pStream, /*STGM_READ*/0)
else
::pPreview := 0
endif
endif
endif
if valtype(::pPreview) == "O"
::pPreview:SetWindow(::hWnd, GetClientRect( ::hWnd ))
::pPreview:DoPreview()
endif
return self
METHOD Resize()
::pPreview:SetRect( GetClientRect( ::hWnd ))
return self
METHOD AcceptDropFile() CLASS TPreviewControl
DragAcceptFiles( ::hWnd, .T. )
return Self
METHOD DropFiles( hDrop ) CLASS TPreviewControl
LOCAL files
files = DragQueryFiles( hDrop )
::SetFile( files[1])
return Self
#pragma BEGINDUMP
#define CINTERFACE
#define COBJMACROS
#include <Ole2.h>
#include <hbapi.h>
#include <unknwn.h>
LPWSTR UTF8toUTF16( LPCSTR utf8 );
HB_FUNC( GETSTREAM ) // cFileName
{
wchar_t* cFileName = UTF8toUTF16(hb_parc(1));
HANDLE hFile = CreateFileW(cFileName,FILE_READ_DATA,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL );
DWORD dwSize = GetFileSize( hFile, NULL );
HGLOBAL hGlobal= GlobalAlloc(GPTR, dwSize );
BYTE * pByte = (BYTE *)GlobalLock(hGlobal);
LPSTREAM pStream;
ReadFile(hFile,pByte,dwSize,&dwSize,NULL);
GlobalUnlock(hGlobal);
CloseHandle( hFile );
CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
hb_xfree( (void*) cFileName);
hb_retptr(pStream);
}
HB_FUNC( DESTROYSTREAM ) // stream
{
LPSTREAM pStream = hb_parptr(1);
HGLOBAL hGlobal;
if( pStream )
{
GetHGlobalFromStream(pStream,&hGlobal);
if(hGlobal)
GlobalFree(hGlobal);
IUnknown_Release(pStream);
}
hb_ret();
}
#pragma ENDDUMP
mastintin wrote:Nages. You ar this key in regedit ?
HKEY_CLASSES_ROOT\.xls\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}"\Default :=" {00020827-0000-0000-C000-000000000046}"
AntoninoP wrote:every com object must be registered, add the uuid from another pc is useless.
AntoninoP wrote:Hello,
I am starting with apologies for the long post. Here a little experiment I am doing at home.
It is an harbour/com interface, an I am starting with IPreviewHadler. For now the file are created by hand, but i am writing an harbour program that create them from idl.
.....
#pragma option push -b -a8 -pc -A- /*P_O_Push*/
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 6.00.0366 */
/* Compiler settings for shobjidl.idl:
Oicf, W1, Zp8, env=Win32 (32b run)
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
//@@MIDL_FILE_HEADING( )
#pragma warning( disable: 4049 ) /* more than 64k source lines */
/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__
#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/
#ifndef __shobjidl_h__
#define __shobjidl_h__
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/* Forward Declarations */
#ifndef __IPreviewHandler_FWD_DEFINED__
#define __IPreviewHandler_FWD_DEFINED__
typedef interface IPreviewHandler IPreviewHandler;
#endif /* __IPreviewHandler_FWD_DEFINED__ */
#ifndef __IInitializeWithFile_FWD_DEFINED__
#define __IInitializeWithFile_FWD_DEFINED__
typedef interface IInitializeWithFile IInitializeWithFile;
#endif /* __IInitializeWithFile_FWD_DEFINED__ */
#ifndef __IInitializeWithStream_FWD_DEFINED__
#define __IInitializeWithStream_FWD_DEFINED__
typedef interface IInitializeWithStream IInitializeWithStream;
#endif /* __IInitializeWithStream_FWD_DEFINED__ */
#ifdef __cplusplus
extern "C"{
#endif
void * __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void * );
/* interface __MIDL_itf_shobjidl_0000 */
/* [local] */
#ifndef _WINRESRC_
#ifndef _WIN32_IE
#define _WIN32_IE 0x0501
#else
#if (_WIN32_IE < 0x0400) && defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0500)
#error _WIN32_IE setting conflicts with _WIN32_WINNT setting
#endif
#endif
#endif
extern RPC_IF_HANDLE __MIDL_itf_shobjidl_0000_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_shobjidl_0000_v0_0_s_ifspec;
#ifndef __IPreviewHandler_INTERFACE_DEFINED__
#define __IPreviewHandler_INTERFACE_DEFINED__
/* interface IPreviewHandler */
/* [uuid][object] */
EXTERN_C const IID IID_IPreviewHandler;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("8895b1c6-b41f-4c1c-a562-0d564250836f")
IPreviewHandler : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE SetWindow(
/* [in] */ HWND hwnd,
/* [in] */ const RECT *prc) = 0;
virtual HRESULT STDMETHODCALLTYPE SetRect(
/* [in] */ const RECT *prc) = 0;
virtual HRESULT STDMETHODCALLTYPE DoPreview( void) = 0;
virtual HRESULT STDMETHODCALLTYPE Unload( void) = 0;
virtual HRESULT STDMETHODCALLTYPE SetFocus( void) = 0;
virtual HRESULT STDMETHODCALLTYPE QueryFocus(
/* [out] */ HWND *phwnd) = 0;
virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator(
/* [in] */ MSG *pmsg) = 0;
};
#else /* C style interface */
typedef struct IPreviewHandlerVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IPreviewHandler * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IPreviewHandler * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IPreviewHandler * This);
HRESULT ( STDMETHODCALLTYPE *SetWindow )(
IPreviewHandler * This,
/* [in] */ HWND hwnd,
/* [in] */ const RECT *prc);
HRESULT ( STDMETHODCALLTYPE *SetRect )(
IPreviewHandler * This,
/* [in] */ const RECT *prc);
HRESULT ( STDMETHODCALLTYPE *DoPreview )(
IPreviewHandler * This);
HRESULT ( STDMETHODCALLTYPE *Unload )(
IPreviewHandler * This);
HRESULT ( STDMETHODCALLTYPE *SetFocus )(
IPreviewHandler * This);
HRESULT ( STDMETHODCALLTYPE *QueryFocus )(
IPreviewHandler * This,
/* [out] */ HWND *phwnd);
HRESULT ( STDMETHODCALLTYPE *TranslateAccelerator )(
IPreviewHandler * This,
/* [in] */ MSG *pmsg);
END_INTERFACE
} IPreviewHandlerVtbl;
interface IPreviewHandler
{
CONST_VTBL struct IPreviewHandlerVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IPreviewHandler_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IPreviewHandler_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IPreviewHandler_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IPreviewHandler_SetWindow(This,hwnd,prc) \
( (This)->lpVtbl -> SetWindow(This,hwnd,prc) )
#define IPreviewHandler_SetRect(This,prc) \
( (This)->lpVtbl -> SetRect(This,prc) )
#define IPreviewHandler_DoPreview(This) \
( (This)->lpVtbl -> DoPreview(This) )
#define IPreviewHandler_Unload(This) \
( (This)->lpVtbl -> Unload(This) )
#define IPreviewHandler_SetFocus(This) \
( (This)->lpVtbl -> SetFocus(This) )
#define IPreviewHandler_QueryFocus(This,phwnd) \
( (This)->lpVtbl -> QueryFocus(This,phwnd) )
#define IPreviewHandler_TranslateAccelerator(This,pmsg) \
( (This)->lpVtbl -> TranslateAccelerator(This,pmsg) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IPreviewHandler_INTERFACE_DEFINED__ */
#ifndef __IInitializeWithFile_INTERFACE_DEFINED__
#define __IInitializeWithFile_INTERFACE_DEFINED__
/* interface IInitializeWithFile */
/* [unique][object][uuid] */
EXTERN_C const IID IID_IInitializeWithFile;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("b7d14566-0509-4cce-a71f-0a554233bd9b")
IInitializeWithFile : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Initialize(
/* [string][in] */ LPCWSTR pszFilePath,
/* [in] */ DWORD grfMode) = 0;
};
#else /* C style interface */
typedef struct IInitializeWithFileVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IInitializeWithFile * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IInitializeWithFile * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IInitializeWithFile * This);
HRESULT ( STDMETHODCALLTYPE *Initialize )(
IInitializeWithFile * This,
/* [string][in] */ LPCWSTR pszFilePath,
/* [in] */ DWORD grfMode);
END_INTERFACE
} IInitializeWithFileVtbl;
interface IInitializeWithFile
{
CONST_VTBL struct IInitializeWithFileVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IInitializeWithFile_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IInitializeWithFile_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IInitializeWithFile_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IInitializeWithFile_Initialize(This,pszFilePath,grfMode) \
( (This)->lpVtbl -> Initialize(This,pszFilePath,grfMode) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IInitializeWithFile_INTERFACE_DEFINED__ */
#ifndef __IInitializeWithStream_INTERFACE_DEFINED__
#define __IInitializeWithStream_INTERFACE_DEFINED__
/* interface IInitializeWithStream */
/* [unique][object][uuid] */
EXTERN_C const IID IID_IInitializeWithStream;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")
IInitializeWithStream : public IUnknown
{
public:
virtual /* [local] */ HRESULT STDMETHODCALLTYPE Initialize(
/* [annotation][in] */
IStream *pstream,
/* [annotation][in] */
DWORD grfMode) = 0;
};
#else /* C style interface */
typedef struct IInitializeWithStreamVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IInitializeWithStream * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IInitializeWithStream * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IInitializeWithStream * This);
/* [local] */ HRESULT ( STDMETHODCALLTYPE *Initialize )(
IInitializeWithStream * This,
/* [annotation][in] */
IStream *pstream,
/* [annotation][in] */
DWORD grfMode);
END_INTERFACE
} IInitializeWithStreamVtbl;
interface IInitializeWithStream
{
CONST_VTBL struct IInitializeWithStreamVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IInitializeWithStream_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IInitializeWithStream_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IInitializeWithStream_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IInitializeWithStream_Initialize(This,pstream,grfMode) \
( (This)->lpVtbl -> Initialize(This,pstream,grfMode) )
#endif /* COBJMACROS */
#endif /* C style interface */
/* [call_as] */ HRESULT STDMETHODCALLTYPE IInitializeWithStream_RemoteInitialize_Proxy(
IInitializeWithStream * This,
/* [in] */ IStream *pstream,
/* [in] */ DWORD grfMode);
void __RPC_STUB IInitializeWithStream_RemoteInitialize_Stub(
IRpcStubBuffer *This,
IRpcChannelBuffer *_pRpcChannelBuffer,
PRPC_MESSAGE _pRpcMessage,
DWORD *_pdwStubPhase);
#endif /* __IInitializeWithStream_INTERFACE_DEFINED__ */
#ifdef __cplusplus
}
#endif
#endif
#pragma option pop /*P_O_Pop*/
// Our first DialogBox sample
#include "FiveWin.ch"
#include <fivewin.ch>
#define HKEY_CLASSES_ROOT 2147483648 // 0x80000000
memvar oPreview
function main()
local oDlg
local hStream
local cFile
public oPreview
// IMPORTANT!!
cFile:= cGetfile("coge","*.*")
if !empty( cfile )
DEFINE WINDOW oDlg FROM 0,0 TO 650,650 PIXEL TITLE "Test"
GenHPreview( cFile, oDlg )
ACTIVATE WINDOW oDlg CENTERED
endif
return nil
Function GenHPreview( cFile, oDlg )
local cCLSString
CoInitialize()
cCLSString := SeekCLSString( cFile )
oPreview := CreateHPreviewC( cCLSString )
ADDPREVIEWC(oDlg:hWnd, {10,10,610,610}, cFile,oPreview )
Return nil
Function SeekCLSString( cFile )
local cExtension
local cKey := ""
local oReg
local cShellExe := "\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}"
local cValue
if !Empty( cFile )
cExtension := cFileExt( cFile )
if Empty( cExtension )
MsgInfo( "not Extension File" )
Return nil
endif
cExtension := "."+ cExtension
cKey := cExtension + cShellExe
// msginfo(cKey)
oReg := TReg32():New( HKEY_CLASSES_ROOT, ckey )
cValue := oReg:Get()
if Empty( cValue )
oreg:Close()
// msginfo(cKey)
oReg := TReg32():New( HKEY_CLASSES_ROOT, cExtension )
cValue := oReg:Get()
if Empty( cValue )
oReg:Close()
MsgInfo( "Clave no encontrada" )
Return nil
endif
cKey := cValue + cShellExe
// msginfo(cKey)
oReg := TReg32():New( HKEY_CLASSES_ROOT, cKey )
cValue := oReg:Get()
if Empty( cValue )
MsgInfo( "Clave no encontrada" )
Return nil
endIf
endif
endif
Return cValue
#pragma BEGINDUMP
#define CINTERFACE
#define COBJMACROS
#if ( __BORLANDC__ <= 0x582 )
#include <Shextra.h>
#endif
#include <windows.h>
#include <hbapi.h>
#include <CommCtrl.h>
#include <ShObjIdl.h>
#include <Shlwapi.h>
#include <ShlGuid.h>
LPWSTR AnsiToWide( LPSTR cAnsi );
const IID IID_IPreviewHandler = {0x8895b1c6, 0xb41f, 0x4c1c, {0xa5, 0x62,
0x0d, 0x56, 0x42, 0x50, 0x83, 0x6f}};
HB_FUNC( CREATEHPREVIEWC ) // clsStr
{
CLSID cls;
IPreviewHandler* pRet=0;
CLSIDFromString( AnsiToWide(( char * ) hb_parc( 1 )),&cls);
if( CoCreateInstance( &cls, 0, CLSCTX_INPROC_SERVER |CLSCTX_LOCAL_SERVER, &IID_IPreviewHandler, ( void ** ) &pRet ) ==S_OK )
{
#ifndef _WIN64
hb_retnl( (long) pRet ) ;
#else
hb_retnll( (long long) pRet );
#endif
return ;
}
// MessageBoxW(0,cKey,cExtension,MB_OK);
#ifndef _WIN64
hb_retnl( (long) 0 );
#else
hb_retnll( (long long) 0 );
#endif
return ;
}
EXTERN_C const IID IID_IInitializeWithFile = {0xb7d14566, 0x0509, 0x4cce, {0xa7,
0x1f, 0x0a, 0x55, 0x42, 0x33, 0xbd, 0x9b}};
EXTERN_C const IID IID_IInitializeWithStream =
{ 0xB824B49D, 0x22AC, 0x4161, { 0xAC, 0x8A, 0x99, 0x16, 0xE8, 0xFA, 0x3F, 0x7F } };
HB_FUNC( ADDPREVIEWC ) // hWnd, {nTop, nLeft, nBottom, nRight}, cFileName,pPreview
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnl( 4 );
#define RET hb_retnl( (long) pPreview );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnll( 4 );
#define RET hb_retnll( (long long) pPreview );
#endif
RECT rectPreview;
LPWSTR cFileName = AnsiToWide(( char * ) 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;
}
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( UnloadPreviewC ) //preview
{
#ifndef _WIN64
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnl( 1 );
#else
IPreviewHandler* pPreview = ( IPreviewHandler* ) hb_parnll( 1 );
#endif
if( pPreview )
{
IPreviewHandler_Unload(pPreview);
}
}
#pragma ENDDUMP
#include "FiveWin.ch"
#include <fivewin.ch>
#define HKEY_CLASSES_ROOT 2147483648 // 0x80000000
#define HKEY_LOCAL_MACHINE 2147483650
function main()
local aPreviewHandler:= {}
local cKey := "SOFTWARE\Microsoft\Windows\CurrentVersion\PreviewHandlers"
local oReg := TReg32():New( HKEY_LOCAL_MACHINE, ckey )
local nHandle, cValue, n := 0
while REGENUMValue( oReg:nHandle, n++, @cValue ) == 0
aadd( aPreviewHandler, { cValue, oreg:get(cValue) } )
end
XBrowser aPreviewHandler
oReg:close()
return nil
//--------------------------------------------------------------------
mastintin wrote:for view Previewhandlers instaled :
Progetto: test, Ambiente: xFive_Pelles:
[1]:Harbour.Exe test.prg /m /n0 /gc1 /es2 /iC:\Work\fwh\include /ic:\work\xHarbour\Include /jC:\Work\Errori\PREVIE~2\I18n\Main.hil /iinclude;c:\work\fwh\include;c:\work\xHarbour\include /oObj\test.c
xHarbour 1.2.3 Intl. (SimpLex) (Build 20140725)
Copyright 1999-2014, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'test.prg'...
Generating international list to 'C:\Work\Errori\PREVIE~2\I18n\Main.hil'...
Generating C source output to 'Obj\test.c'...
Done.
Lines 89, Functions/Procedures 3, pCodes 275
[1]:Bcc32.Exe -M -c -O2 -tW -v- -X -DHB_FM_STATISTICS_OFF -DHB_NO_DEFAULT_API_MACROS -DHB_NO_DEFAULT_STACK_MACROS -DHB_OS_WIN_32 -IC:\Work\fwh\include -IC:\Work\bcc582\Include;c:\work\xHarbour\Include -nC:\Work\Errori\PREVIE~2\Obj test.c
Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland
test.c:
Error E2209 test.prg 97: Unable to open include file 'Shextra.h'
Error E2451 test.prg 117: Undefined symbol 'IPreviewHandler' in function HB_FUN_CREATEHPREVIEWC
Error E2451 test.prg 153: Undefined symbol 'IPreviewHandler' in function HB_FUN_ADDPREVIEWC
Error E2188 test.prg 153: Expression syntax in function HB_FUN_ADDPREVIEWC
Error E2140 test.prg 160: Declaration is not allowed here in function HB_FUN_ADDPREVIEWC
Error E2140 test.prg 161: Declaration is not allowed here in function HB_FUN_ADDPREVIEWC
Error E2140 test.prg 162: Declaration is not allowed here in function HB_FUN_ADDPREVIEWC
Error E2451 test.prg 163: Undefined symbol 'IInitializeWithFile' in function HB_FUN_ADDPREVIEWC
Error E2451 test.prg 164: Undefined symbol 'IInitializeWithStream' in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 173: Call to function 'IPreviewHandler_QueryInterface' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 174: Call to function 'IPreviewHandler_QueryInterface' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 179: Call to function 'IPreviewHandler_Unload' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 186: Call to function 'IInitializeWithFile_Initialize' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 203: Call to function 'IInitializeWithStream_Initialize' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 211: Call to function 'hb_parvni' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 212: Call to function 'hb_parvni' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 213: Call to function 'hb_parvni' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 214: Call to function 'hb_parvni' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 216: Call to function 'IPreviewHandler_SetWindow' with no prototype in function HB_FUN_ADDPREVIEWC
Warning W8065 test.prg 217: Call to function 'IPreviewHandler_DoPreview' with no prototype in function HB_FUN_ADDPREVIEWC
Error E2451 test.prg 225: Undefined symbol 'IPreviewHandler' in function HB_FUN_UnloadPreviewC
Error E2188 test.prg 225: Expression syntax in function HB_FUN_UnloadPreviewC
Warning W8065 test.prg 231: Call to function 'IPreviewHandler_Unload' with no prototype in function HB_FUN_UnloadPreviewC
*** 11 errors in Compile ***
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 49 guests