icqreole.cpp
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C++ 代码 · 共 316 行
CPP
316 行
/*__________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: ICQreole.cpp,v 1.6 2002/08/06 20:09:42 dallen Exp $
__________________________________________________________________________*/
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#include <oledlg.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
#include "precomp.h"
#include "OleCtl.h"
#include "ICQreole.h"
BOOL bBMPfiles=FALSE;
void CreateBMPFiles(void)
{
char szPath[MAX_PATH];
char szFile[MAX_PATH];
if(bBMPfiles)
return;
bBMPfiles=TRUE;
GetTempPath(MAX_PATH,szPath);
strcpy(szFile,szPath);
strcat(szFile,"PGPicq1.bmp");
CreateBMFileFromResource(szFile,
FindResource(g_hinst,
MAKEINTRESOURCE(IDB_LOCK),
RT_BITMAP));
/* strcpy(szFile,szPath);
strcat(szFile,"PGPicq2.bmp");
CreateBMFileFromResource(szFile,
FindResource(g_hinst,
MAKEINTRESOURCE(IDB_GOODSIG),
RT_BITMAP));*/
strcpy(szFile,szPath);
strcat(szFile,"PGPicq2.bmp");
CreateBMFileFromResource(szFile,
FindResource(g_hinst,
MAKEINTRESOURCE(IDB_END),
RT_BITMAP));
/*
strcpy(szFile,szPath);
strcat(szFile,"PGPicq4.bmp");
CreateBMFileFromResource(szFile,
FindResource(g_hinst,
MAKEINTRESOURCE(IDB_ENCSIG),
RT_BITMAP));*/
}
/////////////////////////////////////////////////////////////////////////////
//
// Constructors and Destructor
//
CICQreole::CICQreole()
{
m_hwndEdit = NULL;
m_pRichEditOle = NULL;
}
CICQreole::CICQreole(HWND hwndEdit)
: m_hwndEdit(hwndEdit)
{
m_pRichEditOle = NULL;
}
CICQreole::~CICQreole()
{
//
// We need to go through and deactivate and close any objects that are
// currently open or active in the rich edit control. If any objects
// are left running they will remain in memory even after this program
// is long gone.
//
if (m_pRichEditOle)
{
HRESULT hr = 0;
//
// Start by getting the total number of objects in the control.
//
int objectCount = m_pRichEditOle->GetObjectCount();
//
// Loop through each object in the control and if active deactivate
// and if open, close.
//
for (int i = 0; i < objectCount; i++)
{
REOBJECT reObj;
ZeroMemory(&reObj, sizeof(REOBJECT));
reObj.cbStruct = sizeof(REOBJECT);
//
// Get the Nth object
//
hr = m_pRichEditOle->GetObject(i,&reObj,REO_GETOBJ_POLEOBJ);
if(SUCCEEDED(hr))
{
//
// If active, deactivate.
//
if (reObj.dwFlags && REO_INPLACEACTIVE)
m_pRichEditOle->InPlaceDeactivate();
//
// If the object is open, close it.
//
if(reObj.dwFlags&&REO_OPEN)
hr = reObj.poleobj->Close(OLECLOSE_NOSAVE);
reObj.poleobj->Release();
}
}
m_pRichEditOle->Release();
}
}
BOOL CICQreole::Initialize(void)
{
//
// Get the IRichEditOle interface from the edit control.
//
SendMessage(m_hwndEdit, EM_GETOLEINTERFACE, 0,
(LPARAM) (LPVOID*) &m_pRichEditOle);
return (TRUE);
}
HRESULT CICQreole::GetNewStorage(LPSTORAGE* ppStg)
{
if (!ppStg)
return E_INVALIDARG;
*ppStg = NULL;
//
// We need to create a new storage for an object to occupy. We're going
// to do this the easy way and just create a storage on an HGLOBAL and let
// OLE do the management. When it comes to saving things we'll just let
// the RichEdit control do the work. Keep in mind this is not efficient,
// but this program is just for demonstration.
//
LPLOCKBYTES pLockBytes;
HRESULT hr = CreateILockBytesOnHGlobal(NULL, TRUE, &pLockBytes);
if (FAILED(hr))
return hr;
hr = StgCreateDocfileOnILockBytes(pLockBytes,
STGM_SHARE_EXCLUSIVE | STGM_CREATE |
STGM_READWRITE,
0,
ppStg);
pLockBytes->Release();
return (hr);
}
BOOL CICQreole::InsertObject(DWORD dwType,DWORD dwPos)
{
BOOL fSuccess = FALSE;
LPOLEOBJECT pOleObject = NULL;
DWORD ocfferr;
//
// Get a client site from the RichEdit control.
//
LPOLECLIENTSITE pOleSite;
if (FAILED(m_pRichEditOle->GetClientSite(&pOleSite)))
{
goto error;
}
//
// Get a new substorage for the new object.
//
LPSTORAGE pStgItem;
if (FAILED(GetNewStorage(&pStgItem)))
{
goto error;
}
CreateBMPFiles();
char szFile[MAX_PATH];
WCHAR wszFile[MAX_PATH];
GetTempPath(MAX_PATH,szFile);
switch(dwType)
{
case OBL_LOCK:
strcat(szFile,"PGPicq1.bmp");
break;
case OBL_SIG:
strcat(szFile,"PGPicq1.bmp");
break;
case OBL_END:
strcat(szFile,"PGPicq2.bmp");
break;
case OBL_LOCK|OBL_SIG:
strcat(szFile,"PGPicq1.bmp");
break;
}
MultiByteToWideChar(CP_ACP, 0,
szFile, -1, wszFile, sizeof(wszFile));
while(InSendMessage()) // If message came from thread Y
{
ReplyMessage(0L); // let Y know
}
ocfferr=OleCreateFromFile(CLSID_NULL,
wszFile,
IID_IOleObject,
OLERENDER_DRAW,
NULL,
pOleSite,
pStgItem,
(void **)&pOleObject);
if(ocfferr!=S_OK)
{
#ifdef _DEBUG
char szError[256];
sprintf(szError,"File %s\nError %X",szFile,ocfferr);
MessageBox(NULL,szError,
"DEBUG INFO: OleCreateFromFile",
MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION);
#endif
}
else
{
REOBJECT reObj;
ZeroMemory(&reObj, sizeof(REOBJECT));
reObj.cbStruct = sizeof(REOBJECT);
reObj.cp = dwPos;
reObj.poleobj = pOleObject;
reObj.pstg = pStgItem;
reObj.polesite = pOleSite;
reObj.sizel.cx = 0;
reObj.sizel.cy = 0;
reObj.dvaspect = DVASPECT_CONTENT;
reObj.dwFlags = REO_BLANK;
reObj.dwUser = 0;
if (FAILED(m_pRichEditOle->InsertObject(&reObj)))
{
goto error;
}
fSuccess = TRUE;
}
error:
if (pOleSite)
pOleSite->Release();
if (pStgItem)
pStgItem->Release();
if (pOleObject)
pOleObject->Release();
return fSuccess;
}
void SetRichOLE(PPLUGININFO plugin,HWND hwndEdit)
{
plugin->pDoc=new CICQreole(hwndEdit);
((CICQreole *)(plugin->pDoc))->Initialize();
}
void InsertRichOLE(PPLUGININFO plugin,DWORD dwType,DWORD dwPos)
{
((CICQreole *)(plugin->pDoc))->InsertObject(dwType,dwPos);
}
void DeleteRichOLE(PPLUGININFO plugin)
{
delete ((CICQreole *)(plugin->pDoc));
plugin->pDoc=NULL;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?