-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreviewHandler.h
97 lines (77 loc) · 2.46 KB
/
PreviewHandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// PreviewHandler.h : Declaration of the preview handler
#pragma once
#include "resource.h" // main symbols
#include <atlhandler.h>
#include <atlhandlerimpl.h>
#include <afxext.h>
#include "..\JarredBrowser\JarredBrowserDoc.h"
#include "..\JarredBrowser\JarredBrowserView.h"
#include "JarredBrowserHandlers_i.h"
using namespace ATL;
// CPreviewHandler
class ATL_NO_VTABLE CPreviewHandler :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CPreviewHandler, &CLSID_Preview>,
public CPreviewHandlerImpl <CPreviewHandler>
{
public:
CPreviewHandler()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_PREVIEW_HANDLER)
DECLARE_NOT_AGGREGATABLE(CPreviewHandler)
BEGIN_COM_MAP(CPreviewHandler)
COM_INTERFACE_ENTRY(IObjectWithSite)
COM_INTERFACE_ENTRY(IOleWindow)
COM_INTERFACE_ENTRY(IInitializeWithStream)
COM_INTERFACE_ENTRY(IPreviewHandler)
COM_INTERFACE_ENTRY(IPreviewHandlerVisuals)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
CPreviewHandlerImpl<CPreviewHandler>::FinalRelease();
}
protected:
virtual IPreviewCtrl* CreatePreviewControl()
{
// create your preview control here
CMFCPreviewCtrlImpl *pPreviewCtrl = NULL;
ATLTRY(pPreviewCtrl = new CMFCPreviewCtrlImpl());
return pPreviewCtrl;
}
DECLARE_DOCUMENT(CJarredBrowserDoc)
public:
virtual HRESULT InitializeDocumentPreview(HWND hWndParent, RECT* prc)
{
m_pPreviewCtrl = CreatePreviewControl();
CMFCPreviewCtrlImpl* pCtrl = DYNAMIC_DOWNCAST(CMFCPreviewCtrlImpl, (CObject*) m_pPreviewCtrl);
if (pCtrl == NULL)
{
ATLTRACE2(atlTraceGeneral, 4, L"InitializeDocumentPreview: pointer to preview control is NULL.\n");
return E_POINTER;
}
ASSERT_VALID(pCtrl);
CCreateContext ctx;
ctx.m_pNewViewClass = RUNTIME_CLASS(CJarredBrowserView);
m_pDocument = CreateDocument();
if (m_pDocument == NULL)
{
ATLTRACE2(atlTraceGeneral, 4, L"InitializeDocumentPreview: pointer to document is NULL.\n");
return E_POINTER;
}
m_pDocument->AddRef();
ctx.m_pCurrentDoc = DYNAMIC_DOWNCAST(CJarredBrowserDoc, (CObject*) m_pDocument->GetContainer());
if (!pCtrl->Create(hWndParent, prc, &ctx))
{
ATLTRACE2(atlTraceGeneral, 4, L"InitializeDocumentPreview: preview control creation failed. Error Code: %d\n", GetLastError());
return E_FAIL;
}
return S_OK;
}
};
OBJECT_ENTRY_AUTO(__uuidof(Preview), CPreviewHandler)