http://msdn.microsoft.com/en-gb/library/bb776867.aspx
将Windows中的预览处理程序描述为
Preview handlers are called when an
item is selected to show a
lightweight,rich,read-only preview
of the file’s contents in the view’s
reading pane. This is done without
launching the file’s associated
application.
和……
A preview handler is a hosted
application. Hosts include the
Microsoft Windows Explorer in Windows
Vista or Microsoft Outlook 2007.
是否有一些Delphi VCL代码可以用作这种处理程序的起点?
解决方法
>您必须使用IPreviewHandler
,InitializeWithFile,InitializeWithStream
,IPreviewHandlerFrame
,IPreviewHandlerVisuals接口.
这是这些接口的头文件的delphi转换
uses Windows,ActiveX,AxCtrls,ShlObj,ComObj; type IIPreviewHandler = interface(IUnkNown) ['{8895b1c6-b41f-4c1c-a562-0d564250836f}'] function Setwindow(hwnd: HWND; var RectangleRef: TRect): HRESULT; stdcall; function SetRect(var RectangleRef: TRect): HRESULT; stdcall; function DoPreview(): HRESULT; stdcall; function Unload(): HRESULT; stdcall; function SetFocus(): HRESULT; stdcall; function QueryFocus(phwnd: HWND): HRESULT; stdcall; function TranslateAccelerator(PointerToWindowMessage: MSG): HRESULT; stdcall; end; IInitializeWithFile = interface(IUnkNown) ['{b7d14566-0509-4cce-a71f-0a554233bd9b}'] function Initialize(pszFilePath: LPWSTR; grfMode: DWORD):HRESULT;stdcall; end; IInitializeWithStream = interface(IUnkNown) ['{b824b49d-22ac-4161-ac8a-9916e8fa3f7f}'] function Initialize(pstream: IStream; grfMode: DWORD): HRESULT; stdcall; end; IIPreviewHandlerFrame = interface(IUnkNown) ['{fec87aaf-35f9-447a-adb7-20234491401a}'] function GetwindowContext(pinfo: HWND): HRESULT; stdcall; function TranslateAccelerator(PointerToWindowMessage: MSG): HRESULT; stdcall; end; IIPreviewHandlerVisuals = interface(IUnkNown) ['{8327b13c-b63f-4b24-9b8a-d010dcc3f599}'] function SetBackgroundColor(color: COLORREF ): HRESULT; stdcall; function SetFont(plf:LOGFONTW): HRESULT; stdcall; function SetTextColor(color: COLORREF): HRESULT; stdcall; end;
>你必须创建一个com dll,其中包含一个来自这些接口的类IIPreviewHandler,IIPreviewHandlerVisuals,IOleWindow,IObjectWithSite来管理可视化,第二个类来加载要显示的文件.这个类必须来自IPreviewHandler,IInitializeWithStream.
这样的事情
TMyPreviewHandler = class(IIPreviewHandler,IObjectWithSite) TMyStream = class(IIPreviewHandler,IInitializeWithStream,IStream)
>现在,您必须为父接口创建自己的方法实现.
这是您需要实现的方法列表.
IPreviewHandler – > DoPreview,Setwindow,SetRect,Unload,SetFocus,TranslateAccelerator,QueryFocus.
IObjectWithSite – > GetSite,SetSite.
IOleWindow – > Getwindow
IPreviewHandlerVisuals – > SetBackgroundColor,SetFont,SetColor
InitializeWithStream – >初始化
>最后,您必须在系统中注册您的com以及将使用PrevieHandler类的文件扩展名.
>将此项目作为起点Windows Preview Handler Pack
(用C#编写)和本文View Data Your Way With Our Managed Preview Handler Framework