谁能给个在RichEdit里面插入Ole的例子? 我想实现的是点击那个Ole,实现在本地打开文件观看的功能. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 A Rich Edit Control That Displays Bitmaps and Other OLE Objectshttp://www.codeproject.com/richedit/COleRichEditCtrl.asp 关于这个的实现。我们首先应该明了,我们必须实现一个OLE对象。而且这个对象能够播放GIF.对于播放GIF,代码已经很多了。比较有名气的就是那个谁封装的Gif89a,还不错,我喜欢那个CPictureEx.可以在vchelp找到。有了这个就完了么?当然不是。你还有写一个OLE/COM对象。实现IOleObject等。你是用ATL还是MFC呢?呵呵,我什么也没有用。在这个目录下%program file%\tencent\qq\,你可以看到一个ImageOle.dll,她就是你日夜思念的人!好吧,让我们来看看他的真面目。怎么看?X Ray? 当然不是——OLE/COM Viewer.Click on “All Objects”,View TypeLib... 打开那个文件,你可以看到:[ uuid(0C1CF2DF-05A3-4FEF-8CD4-F5CFC4355A16), helpstring("IGifAnimator Interface"), dual, nonextensible]dispinterface IGifAnimator { properties: methods: [id(0x00000001), helpstring("method LoadFromFile")] void LoadFromFile([in] BSTR FileName); [id(0x00000002), helpstring("method TriggerFrameChange")] VARIANT_BOOL TriggerFrameChange(); [id(0x00000003), helpstring("method GetFilePath")] BSTR GetFilePath(); [id(0x00000004), helpstring("method ShowText")] void ShowText([in] BSTR Text);};这个接口就是我们要的。你可以用ActiveX Control Test Container测试一下。还挺管用的。那么怎么在我们的程序中使用呢?我也没有那么多的时间,先给出代码吧,有时间再说啊,见谅。1 LPLOCKBYTES lpLockBytes = NULL;2 SCODE sc;3 HRESULT hr;4 //print to RichEdit' s IClientSite5 LPOLECLIENTSITE m_lpClientSite;6 //A smart point to IAnimator7 IGifAnimatorPtr m_lpAnimator;8 //ptr 2 storage 9 LPSTORAGE m_lpStorage;10 //the object 2 b insert 211 LPOLEOBJECT m_lpObject;1213 //Create lockbytes14 sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);15 if (sc != S_OK)16 AfxThrowOleException(sc);17 ASSERT(lpLockBytes != NULL);18 19 //use lockbytes to create storage20 sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,21 STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);22 if (sc != S_OK)23 {24 VERIFY(lpLockBytes->Release() == 0);25 lpLockBytes = NULL;26 AfxThrowOleException(sc);27 }28 ASSERT(m_lpStorage != NULL);29 30 //get the ClientSite of the very RichEditCtrl31 GetIRichEditOle()->GetClientSite(&m_lpClientSite);32 ASSERT(m_lpClientSite != NULL);3334 try35 {36 //Initlize COM interface37 hr = ::CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );38 if( FAILED(hr) )39 _com_issue_error(hr);40 41 //Get GifAnimator object42 //here, I used a smart point, so I do not need to free it43 hr = m_lpAnimator.CreateInstance(CLSID_GifAnimator); 44 if( FAILED(hr) )45 _com_issue_error(hr);46 //COM operation need BSTR, so get a BSTR47 BSTR path = strPicPath.AllocSysString();4849 //Load the gif50 hr = m_lpAnimator->LoadFromFile(path);51 if( FAILED(hr) )52 _com_issue_error(hr);53 54 TRACE0( m_lpAnimator->GetFilePath() );55 56 //get the IOleObject57 hr = m_lpAnimator.QueryInterface(IID_IOleObject, (void**)&m_lpObject);58 if( FAILED(hr) )59 _com_issue_error(hr);60 61 //Set it 2 b inserted62 OleSetContainedObject(m_lpObject, TRUE);63 64 //2 insert in 2 richedit, you need a struct of REOBJECT65 REOBJECT reobject;66 ZeroMemory(&reobject, sizeof(REOBJECT));6768 reobject.cbStruct = sizeof(REOBJECT); 69 CLSID clsid;70 sc = m_lpObject->GetUserClassID(&clsid);71 if (sc != S_OK)72 AfxThrowOleException(sc);73 //set clsid74 reobject.clsid = clsid;75 //can be selected76 reobject.cp = REO_CP_SELECTION;77 //content, but not static78 reobject.dvaspect = DVASPECT_CONTENT;79 //goes in the same line of text line80 reobject.dwFlags = REO_BELOWBASELINE; //REO_RESIZABLE |81 reobject.dwUser = 0;82 //the very object83 reobject.poleobj = m_lpObject;84 //client site contain the object85 reobject.polesite = m_lpClientSite;86 //the storage 87 reobject.pstg = m_lpStorage;88 89 SIZEL sizel;90 sizel.cx = sizel.cy = 0;91 reobject.sizel = sizel;92 HWND hWndRT = this->m_hWnd;93 //Sel all text94// ::SendMessage(hWndRT, EM_SETSEL, 0, -1);95// DWORD dwStart, dwEnd;96// ::SendMessage(hWndRT, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);97// ::SendMessage(hWndRT, EM_SETSEL, dwEnd+1, dwEnd+1);98 //Insert after the line of text99 GetIRichEditOle()->InsertObject(&reobject);100 ::SendMessage(hWndRT, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);101 VARIANT_BOOL ret;102 //do frame changing103 ret = m_lpAnimator->TriggerFrameChange();104 //show it105 m_lpObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, m_lpClientSite, 0, m_hWnd, NULL);106 m_lpObject->DoVerb(OLEIVERB_SHOW, NULL, m_lpClientSite, 0, m_hWnd, NULL);107 108 //redraw the window to show animation109 RedrawWindow();110111 if (m_lpClientSite)112 {113 m_lpClientSite->Release();114 m_lpClientSite = NULL;115 }116 if (m_lpObject)117 {118 m_lpObject->Release();119 m_lpObject = NULL;120 }121 if (m_lpStorage)122 {123 m_lpStorage->Release();124 m_lpStorage = NULL;125 }126 127 SysFreeString(path);128 }129 catch( _com_error e )130 {131 AfxMessageBox(e.ErrorMessage());132 ::CoUninitialize(); 133 } 点击那个Ole,实现在本地打开文件观看的功能 在OLE里实现 还是位图\\\\各位帮帮忙啊 08错误!帮看看。。。。 自己建立的CDIB类,处理有些图象可以,处理一些图象会出错,请教大家(分不够用了,麻烦大家) DLL导出的问题 请问我要在一个view类中显示一个ListCtrl控件应该怎么做? 升星星散分,新年快乐! !!!菜鸟问题,在VC中写个DLL想在ASP。NET下用 大家来看看,一个很简单的问题,一起来讨论讨论!!! 请问怎么用MoveTo,LineTo,画线 郁闷啊郁闷!!!! 如何实现:IE窗口中,当鼠标在网页图片中移动时,就会显示一个菜单,就像QQ的那个发彩信的菜单 vc调用库文件的问题,我老是不能调出函数,郁闷,帮忙啊,在线等。。。
http://www.codeproject.com/richedit/COleRichEditCtrl.asp
对于播放GIF,代码已经很多了。比较有名气的就是那个谁封装的Gif89a,还不错,我喜欢那个CPictureEx.
可以在vchelp找到。
有了这个就完了么?当然不是。你还有写一个OLE/COM对象。实现IOleObject等。
你是用ATL还是MFC呢?
呵呵,我什么也没有用。在这个目录下%program file%\tencent\qq\,你可以看到一个ImageOle.dll,她就是
你日夜思念的人!
好吧,让我们来看看他的真面目。怎么看?X Ray? 当然不是——OLE/COM Viewer.
Click on “All Objects”,View TypeLib... 打开那个文件,你可以看到:
[
uuid(0C1CF2DF-05A3-4FEF-8CD4-F5CFC4355A16),
helpstring("IGifAnimator Interface"),
dual,
nonextensible
]
dispinterface IGifAnimator {
properties:
methods:
[id(0x00000001), helpstring("method LoadFromFile")]
void LoadFromFile([in] BSTR FileName);
[id(0x00000002), helpstring("method TriggerFrameChange")]
VARIANT_BOOL TriggerFrameChange();
[id(0x00000003), helpstring("method GetFilePath")]
BSTR GetFilePath();
[id(0x00000004), helpstring("method ShowText")]
void ShowText([in] BSTR Text);
};这个接口就是我们要的。你可以用ActiveX Control Test Container测试一下。还挺管用的。那么怎么在我们的程序中使用呢?我也没有那么多的时间,先给出代码吧,有时间再说啊,见谅。
1 LPLOCKBYTES lpLockBytes = NULL;
2 SCODE sc;
3 HRESULT hr;
4 //print to RichEdit' s IClientSite
5 LPOLECLIENTSITE m_lpClientSite;
6 //A smart point to IAnimator
7 IGifAnimatorPtr m_lpAnimator;
8 //ptr 2 storage
9 LPSTORAGE m_lpStorage;
10 //the object 2 b insert 2
11 LPOLEOBJECT m_lpObject;
12
13 //Create lockbytes
14 sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
15 if (sc != S_OK)
16 AfxThrowOleException(sc);
17 ASSERT(lpLockBytes != NULL);
18
19 //use lockbytes to create storage
20 sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
21 STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
22 if (sc != S_OK)
23 {
24 VERIFY(lpLockBytes->Release() == 0);
25 lpLockBytes = NULL;
26 AfxThrowOleException(sc);
27 }
28 ASSERT(m_lpStorage != NULL);
29
30 //get the ClientSite of the very RichEditCtrl
31 GetIRichEditOle()->GetClientSite(&m_lpClientSite);
32 ASSERT(m_lpClientSite != NULL);
33
34 try
35 {
36 //Initlize COM interface
37 hr = ::CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
38 if( FAILED(hr) )
39 _com_issue_error(hr);
40
41 //Get GifAnimator object
42 //here, I used a smart point, so I do not need to free it
43 hr = m_lpAnimator.CreateInstance(CLSID_GifAnimator);
44 if( FAILED(hr) )
45 _com_issue_error(hr);
46 //COM operation need BSTR, so get a BSTR
47 BSTR path = strPicPath.AllocSysString();
48
49 //Load the gif
50 hr = m_lpAnimator->LoadFromFile(path);
51 if( FAILED(hr) )
52 _com_issue_error(hr);
53
54 TRACE0( m_lpAnimator->GetFilePath() );
55
56 //get the IOleObject
57 hr = m_lpAnimator.QueryInterface(IID_IOleObject, (void**)&m_lpObject);
58 if( FAILED(hr) )
59 _com_issue_error(hr);
60
61 //Set it 2 b inserted
62 OleSetContainedObject(m_lpObject, TRUE);
63
64 //2 insert in 2 richedit, you need a struct of REOBJECT
65 REOBJECT reobject;
66 ZeroMemory(&reobject, sizeof(REOBJECT));
67
68 reobject.cbStruct = sizeof(REOBJECT);
69 CLSID clsid;
70 sc = m_lpObject->GetUserClassID(&clsid);
71 if (sc != S_OK)
72 AfxThrowOleException(sc);
73 //set clsid
74 reobject.clsid = clsid;
75 //can be selected
76 reobject.cp = REO_CP_SELECTION;
77 //content, but not static
78 reobject.dvaspect = DVASPECT_CONTENT;
79 //goes in the same line of text line
80 reobject.dwFlags = REO_BELOWBASELINE; //REO_RESIZABLE |
81 reobject.dwUser = 0;
82 //the very object
83 reobject.poleobj = m_lpObject;
84 //client site contain the object
85 reobject.polesite = m_lpClientSite;
86 //the storage
87 reobject.pstg = m_lpStorage;
88
89 SIZEL sizel;
90 sizel.cx = sizel.cy = 0;
91 reobject.sizel = sizel;
92 HWND hWndRT = this->m_hWnd;
93 //Sel all text
94// ::SendMessage(hWndRT, EM_SETSEL, 0, -1);
95// DWORD dwStart, dwEnd;
96// ::SendMessage(hWndRT, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
97// ::SendMessage(hWndRT, EM_SETSEL, dwEnd+1, dwEnd+1);
98 //Insert after the line of text
99 GetIRichEditOle()->InsertObject(&reobject);
100 ::SendMessage(hWndRT, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
101 VARIANT_BOOL ret;
102 //do frame changing
103 ret = m_lpAnimator->TriggerFrameChange();
104 //show it
105 m_lpObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, m_lpClientSite, 0, m_hWnd, NULL);
106 m_lpObject->DoVerb(OLEIVERB_SHOW, NULL, m_lpClientSite, 0, m_hWnd, NULL);
107
108 //redraw the window to show animation
109 RedrawWindow();
110
111 if (m_lpClientSite)
112 {
113 m_lpClientSite->Release();
114 m_lpClientSite = NULL;
115 }
116 if (m_lpObject)
117 {
118 m_lpObject->Release();
119 m_lpObject = NULL;
120 }
121 if (m_lpStorage)
122 {
123 m_lpStorage->Release();
124 m_lpStorage = NULL;
125 }
126
127 SysFreeString(path);
128 }
129 catch( _com_error e )
130 {
131 AfxMessageBox(e.ErrorMessage());
132 ::CoUninitialize();
133 }