电子签章系统源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
电子认证签章系统
源代码
2013年03月
/******************************* stdafx.h ***************************/
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxctl.h> // MFC support for ActiveX Controls
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Comon Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <atlconv.h> // MFC OLE classes
#include "Atlbase.h"
#define UNICODE
#ifndef ULONG_PTR
#define ULONG_PTR /*ULONG*/unsigned long*
#endif
#include "./gdiplus/include/Gdiplus.h"
using namespace Gdiplus;
#pragma comment (lib, "./gdiplus/lib/Gdiplus.lib")
// Delete the two includes below if you do not wish to use the MFC
// database classes
#include <afxdb.h> // MFC database classes
#include <afxdao.h> // MFC DAO database classes
#include <afxwin.h>
#import "msscript.ocx" no_namespace
//{{AFX_INSERT_LOCA TION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif
// !defined(AFX_STDAFX_H__8B528134_029F_4E9C_98FD_E8F297244773__INCLUDED_) /*************************** stdafx.cpp*******************************/
#include "stdafx.h"
/********************************************************************HtmlSignatu reAddInCtl.cpp : Implementation of the CHtmlSignatureAddInCtrl ActiveX Control class.
*******************************************************************/
#include "stdafx.h"
#include "HtmlSignatureAddIn.h"
#include "HtmlSignatureAddInCtl.h"
#include "HtmlSignatureAddInPpg.h"
#include "resource.h"
#include "mshtml.h"
#include <wingdi.h>
#include ".\htmlsignatureaddinctl.h"
//数字证书部分头文件
#include <wincrypt.h>
#include <cryptuiapi.h>
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING) //数字证书部分头文件
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma comment( lib, "Msimg32.lib" )
IMPLEMENT_DYNCREATE(CHtmlSignatureAddInCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CHtmlSignatureAddInCtrl, COleControl)
// ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CHtmlSignatureAddInCtrl)
ON_COMMAND(ID_MENU_BRANDINFO, OnMenuBrandinfo)
ON_COMMAND(ID_MENU_CANCELSIG, OnMenuCancelsig)
ON_COMMAND(ID_MENU_VIEWCERT, OnMenuViewcert)
ON_COMMAND(ID_MENU_NUMSIGNA TURE, OnMenuNumsignature)
ON_COMMAND(ID_MENU_CERTIFY, OnMenuCertify)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CHtmlSignatureAddInCtrl, COleControl)
//{{AFX_DISPA TCH_MAP(CHtmlSignatureAddInCtrl)
DISP_PROPERTY_EX(CHtmlSignatureAddInCtrl, "id", GetId, SetId, VT_BSTR)
DISP_PROPERTY_EX(CHtmlSignatureAddInCtrl, "ocxLeft", GetOcxLeft, SetOcxLeft, VT_BSTR)
DISP_PROPERTY_EX(CHtmlSignatureAddInCtrl, "ocxTop", GetOcxTop, SetOcxTop, VT_BSTR)
DISP_PROPERTY_EX(CHtmlSignatureAddInCtrl, "ocxWidth", GetOcxWidth, SetOcxWidth, VT_BSTR)
DISP_PROPERTY_EX(CHtmlSignatureAddInCtrl, "ocxHeight", GetOcxHeight, SetOcxHeight, VT_BSTR)
DISP_PROPERTY_EX(CHtmlSignatureAddInCtrl, "sigPath", GetSigPath, SetSigPath, VT_BSTR)
//}}AFX_DISPA TCH_MAP
DISP_FUNCTION_ID(CHtmlSignatureAddInCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "EnableMoveSig", dispidEnableMoveSig, m_EnableMoveSig, OnEnableMoveSigChanged, VT_BSTR) DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "DivId", dispidDivId, m_DivId, OnDivIdChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "DocumentId", dispidDocumentId, m_DocumentId, OnDocumentIdChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "FieldList", dispidFieldList, m_FieldList, OnFieldListChanged, VT_V ARIANT)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "IEVersion", dispidIEVersion, m_IEVersion, OnIEVersionChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "UserName", dispidUserName, m_UserName, OnUserNameChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "PassWord", dispidPassWord, m_PassWord, OnPassWordChanged, VT_BSTR)
DISP_PROPERTY_EX_ID(CHtmlSignatureAddInCtrl, "SignatureIP", dispidSignatureIP, GetSignatureIP, SetSignatureIP, VT_BSTR)
DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "SignatureName", dispidSignatureName, m_SignatureName, OnSignatureNameChanged, VT_BSTR) DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "SignatureTime", dispidSignatureTime, m_SignatureTime, OnSignatureTimeChanged, VT_DATE) DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "SignatureSerialId", dispidSignatureSerialId, m_SignatureSerialId, OnSignatureSerialIdChanged, VT_I4) DISP_PROPERTY_NOTIFY_ID(CHtmlSignatureAddInCtrl, "SignatureCode", dispidSignatureCode, m_SignatureCode, OnSignatureCodeChanged, VT_BSTR)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CHtmlSignatureAddInCtrl, COleControl)
//{{AFX_EVENT_MAP(CHtmlSignatureAddInCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CHtmlSignatureAddInCtrl, 1)
PROPPAGEID(CHtmlSignatureAddInPropPage::guid)
END_PROPPAGEIDS(CHtmlSignatureAddInCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CHtmlSignatureAddInCtrl, "HTMLSIGNATUREADDIN.HtmlSignatureAddInCtrl.1",
0x3b659a2f, 0xfacc, 0x4dcb, 0xb1, 0x67, 0x8d, 0x29, 0x49, 0x54, 0xfc, 0xbc)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CHtmlSignatureAddInCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DHtmlSignatureAddIn =
{ 0x7a75abe6, 0x7aa7, 0x4fc9, { 0x82, 0x4f, 0xd0, 0x75, 0x1c, 0, 0xa2, 0x50 } }; const IID BASED_CODE IID_DHtmlSignatureAddInEvents =
{ 0x4dad4e54, 0xbc55, 0x4cef, { 0xac, 0x54, 0xcb, 0xe6, 0x95, 0x47, 0xa9, 0xd3 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwHtmlSignatureAddInOleMisc =
OLEMISC_ACTIV ATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CHtmlSignatureAddInCtrl, IDS_HTMLSIGNATUREADDIN, _dwHtmlSignatureAddInOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::CHtmlSignatureAddInCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CHtmlSignatureAddInCtrl
BOOL CHtmlSignatureAddInCtrl::CHtmlSignatureAddInCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_HTMLSIGNATUREADDIN,
IDB_HTMLSIGNATUREADDIN,
afxRegApartmentThreading,
_dwHtmlSignatureAddInOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::CHtmlSignatureAddInCtrl - Constructor CHtmlSignatureAddInCtrl::CHtmlSignatureAddInCtrl()
{
InitializeIIDs(&IID_DHtmlSignatureAddIn, &IID_DHtmlSignatureAddInEvents);
// TODO: Initialize your control's instance data here.
m_gdip.Initialize();// 初始化gdi+
m_IsRbtnDown=false;//
m_point=0;
m_pSigBitmap=NULL;
//初始化scriptcontrol;
if(SUCCEEDED(m_iScriptControl.CoCreateInstance(__uuidof(ScriptControl))))
{
m_iScriptControl->PutLanguage(L"JScript");
m_iScriptControl->PutAllowUI(VARIANT_TRUE);
}
}
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::~CHtmlSignatureAddInCtrl - Destructor CHtmlSignatureAddInCtrl::~CHtmlSignatureAddInCtrl()
{
// TODO: Cleanup your control's instance data here.
m_gdip.Deinitialize();// 卸载gdi+;
m_iScriptControl=NULL;
m_pSigBitmap=NULL;
}
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::OnDraw - Drawing function
HBITMAP CHtmlSignatureAddInCtrl::CopyScreenToBitmap(LPRECT lpRect,HWND hwnd) {
HDC hscrdc, hmemdc;// 屏幕和内存设备描述
HBITMAP hbitmap, holdbitmap; // 位图句柄
int nx, ny, nx2, ny2; // 选定区域坐标
int nwidth,nheight;// 位图宽度和高度
int xscrn,yscrn;// 屏幕分辨率
if (IsRectEmpty(lpRect)) // 确保选定区域不为空矩形
return NULL;
if (hwnd==NULL)
return NULL;
hscrdc=::GetDC(hwnd);//CreateDC("DISPLAY", NULL, NULL, NULL);//为屏幕创建设备描述表
hmemdc=CreateCompatibleDC(hscrdc);//为屏幕设备描述表创建兼容的内存设备描述表nx=lpRect->left;
ny=lpRect->top;
nx2=lpRect->right;
ny2=lpRect->bottom;
// 获得屏幕分辨率
xscrn = GetDeviceCaps(hscrdc,HORZRES);
yscrn = GetDeviceCaps(hscrdc,VERTRES);
if (nx<0)
nx=0;
if (ny<0)
ny=0;
if (nx2>xscrn)
nx2=xscrn;
if (ny2>yscrn)
ny2=yscrn;
nwidth=nx2-nx;
nheight=ny2-ny;
hbitmap = CreateCompatibleBitmap(hscrdc,nwidth,nheight);// 创建一个与屏幕设备描述表兼容的位图
holdbitmap=(HBITMAP)SelectObject(hmemdc,hbitmap);// 把新位图选到内存设备描述表中
BitBlt(hmemdc,0,0,nwidth,nheight,hscrdc,nx,ny,SRCCOPY);// 把屏幕设备描述表拷贝到内存设备描述表中
hbitmap=(HBITMAP)::SelectObject(hmemdc,holdbitmap); //得到屏幕位图的句柄//清除
//DeleteDC(hscrdc);
::ReleaseDC(hwnd,hscrdc);
DeleteDC(hmemdc);
return hbitmap; // 返回位图句柄
}
void CHtmlSignatureAddInCtrl::PerChannelProcess(
Bitmap *destImg, int destX, int destY, int destWidth, int destHeight,
Bitmap *srcImg,int srcX, int srcY)
{
BitmapData dstBD,srcBD;
Rect dstRect(destX,destY,destWidth,destHeight),srcRect(srcX,srcY,destWidth,destHeight); destImg->LockBits(&dstRect,ImageLockModeRead|ImageLockModeWrite,PixelFormat24bppRG B,&dstBD);
srcImg->LockBits(&srcRect,ImageLockModeRead|ImageLockModeWrite,PixelFormat24bppRG B,&srcBD);
int dstStride = dstBD.Stride;
int srcStride = srcBD.Stride;
byte *pDst = (byte *)dstBD.Scan0;
byte *pSrc = (byte *)srcBD.Scan0;
for(int y = 0; y < destHeight; y++)
{
for(int x = 0; x < destWidth * 3; x++)
{
pDst[x + y * dstStride] = BlendDarken(pSrc[x + y * srcStride],pDst[x + y * dstStride]);
}
}
srcImg->UnlockBits(&srcBD);
destImg->UnlockBits(&dstBD);
}
byte CHtmlSignatureAddInCtrl::BlendDarken(byte & Src,byte & Dst)
{
return ((Src < Dst) ? Src : Dst);
}
void CHtmlSignatureAddInCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
Graphics graphics(pdc->m_hDC);
if (m_pSigBitmap==NULL)
{
return ;
}
int nWidth =m_pSigBitmap->GetWidth();
int nHeight =m_pSigBitmap->GetHeight();
IOleInPlaceSite *pOleInPlaceSite = NULL;
IOleClientSite *pClientSite=NULL;
HWND ieWnd=NULL;
pClientSite= GetClientSite();
if
(NOERROR==pClientSite->QueryInterface(IID_IOleInPlaceSite,(LPVOID*)&pOleInPlaceSite)) {
pOleInPlaceSite->GetWindow((HWND *)&ieWnd);
pOleInPlaceSite->Release();
}
POINT p1,p2;
p1.x=atol(m_ocxLeft);
p1.y=atol(m_ocxTop);
p2.x=atol(m_ocxLeft)+nHeight;
p2.y=atol(m_ocxTop)+nWidth;
m_backRect.SetRect(p1,p2);
CString str;
str.Format("%d",ieWnd);
TRACE(" the %s \n", str);
HBITMAP hbitmap=this->CopyScreenToBitmap(&m_backRect,ieWnd);
Bitmap *pbitmap3=Bitmap::FromHBITMAP(hbitmap,NULL);
if (p1.x<0)
{
nWidth+=p1.x;
}
if (p1.y<0)
{
nHeight+=p1.y;
}
PerChannelProcess(pbitmap3,0,0,nWidth,nHeight,m_pSigBitmap,0,0);
graphics.DrawImage(pbitmap3,rcBounds.left,rcBounds.top,rcBounds.Width(),rcBounds.Height());
graphics.ReleaseHDC(pdc->m_hDC);
pbitmap3=NULL;
}
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::DoPropExchange - Persistence support
void CHtmlSignatureAddInCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
PX_String(pPX,"id",m_SigID);
PX_String(pPX,"ocxLeft",m_ocxLeft);
PX_String(pPX,"ocxTop",m_ocxTop);
PX_String(pPX,"ocxWidth",m_ocxWidth);
PX_String(pPX,"ocxHeight",m_ocxHeight);
PX_String(pPX,"sigPath",m_filePath);
// 初始化变量
USES_CONVERSION;
m_pSigBitmap=Bitmap::FromFile(A2W((LPCTSTR)m_filePath),FALSE); }
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::OnResetState - Reset control to default state
void CHtmlSignatureAddInCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange // TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl::AboutBox - Display an "About" box to the user void CHtmlSignatureAddInCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_HTMLSIGNA TUREADDIN);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInCtrl message handlers
BSTR CHtmlSignatureAddInCtrl::GetId()
{
CString strResult;
// TODO: Add your property handler here
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetId(LPCTSTR lpszNewValue)
{
// TODO: Add your property handler here
SetModifiedFlag();
}
BSTR CHtmlSignatureAddInCtrl::GetOcxLeft()
{
CString strResult;
// TODO: Add your property handler here
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetOcxLeft(LPCTSTR lpszNewValue)
{
// TODO: Add your property handler here
SetModifiedFlag();
}
BSTR CHtmlSignatureAddInCtrl::GetOcxTop()
{
CString strResult;
// TODO: Add your property handler here
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetOcxTop(LPCTSTR lpszNewValue) {
// TODO: Add your property handler here
SetModifiedFlag();
}
BSTR CHtmlSignatureAddInCtrl::GetOcxWidth()
{
CString strResult;
// TODO: Add your property handler here
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetOcxWidth(LPCTSTR lpszNewValue) {
// TODO: Add your property handler here
SetModifiedFlag();
}
BSTR CHtmlSignatureAddInCtrl::GetOcxHeight()
{
CString strResult;
// TODO: Add your property handler here
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetOcxHeight(LPCTSTR lpszNewValue) {
// TODO: Add your property handler here
SetModifiedFlag();
}
BSTR CHtmlSignatureAddInCtrl::GetSigPath()
{
CString strResult;
// TODO: Add your property handler here
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetSigPath(LPCTSTR lpszNewValue) {
// TODO: Add your property handler here
SetModifiedFlag();
}
//版权信息
void CHtmlSignatureAddInCtrl::OnMenuBrandinfo()
{
// TODO: Add your command handler code here
CDialog dlgAbout(IDD_ABOUTBOX_HTMLSIGNA TUREADDIN);
dlgAbout.DoModal();
}
//撤销签章LVFENG180 ********
void CHtmlSignatureAddInCtrl::OnMenuCancelsig()
{
// TODO: Add your command handler code here
// CComPtr<IScriptProcedureCollection> aProcedureSet = m_iScriptControl->GetProcedures();
//long nn = aProcedureSet->GetCount();
// CComPtr<IScriptProcedure> aProcedure = aProcedureSet->GetItem(_variant_t(nn));
// _bstr_t strFunction = aProcedure->GetName();
//***********************************************************
//获取文档对象指针;lvfeng180 2008-3-12
IOleClientSite *pClientSite=NULL;
pClientSite= GetClientSite();
IOleContainer* pContainer = NULL;
IHTMLDocument2 *pDoc=NULL;
IHTMLWindow2 *htmWindow=NULL;
IHTMLEventObj *htmEvnt=NULL;
pClientSite->GetContainer(&pContainer);
if (pContainer != NULL )
pContainer->QueryInterface(IID_IHTMLDocument2, (void **)&pDoc);
pDoc->get_parentWindow(&htmWindow);
// htmWindow->get_event(&htmEvnt);
m_iScriptControl->Reset();//代码清空;
m_iScriptControl->AddObject("document",pDoc,V ARIANT_TRUE);
m_iScriptControl->AddObject("window",htmWindow,VARIANT_TRUE);
LoadScriptFile("D:\\lvfeng\\HtmlSignatureAddin\\WebSignCtrl.js");
// 准备函数参数。
CString argStr[1]={m_SigID};
V ARIANT va = {0};
va.vt = VT_BSTR;
short n = 1;//参数个数;
SAFEARRAYBOUND bounds[1] = {0};
bounds[0].cElements = n;
SAFEARRAY* psa = SafeArrayCreate(VT_V ARIANT, 1, bounds);
long i = 0;
for(i = 0; i < n; i++)
{
va.bstrVal =argStr[i].AllocSysString();
SafeArrayPutElement(psa, &i, &va);
}
// 调用函数;
_variant_t Result =m_iScriptControl->Run("WebSignCtrl_OnDelete",&psa);
//MessageBox((_bstr_t)Result);
// 释放参数;
for(i = 0; i < n; i++)
{
va.bstrVal = argStr[i].AllocSysString();
SafeArrayGetElement(psa, &i, &va);
SysFreeString(va.bstrVal);
}
SafeArrayDestroy(psa);
}
//加载脚本javascript到脚本引擎中;
bool CHtmlSignatureAddInCtrl::LoadScriptFile(LPCTSTR FileName)
{
HANDLE hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INV ALID_HANDLE_V ALUE)
{
DWORD dwSize = GetFileSize(hFile, NULL);
if (0xFFFFFFFF != dwSize)
{
BYTE* pbytes = (BYTE*) GlobalAlloc(GPTR, dwSize+1);
if (pbytes != NULL)
{
DWORD dwRead = 0;
bool bResult = false;
if (ReadFile(hFile, pbytes, dwSize, &dwRead, NULL))
{
try{
if (m_iScriptControl)
{
_bstr_t strCode = (LPCSTR) (pbytes);
m_iScriptControl->AddCode( strCode );
bResult = true;
}
}
catch(...)
{
// Just catch the exception, call GetErrorString()
// to retreive last error
}
GlobalFree( (HGLOBAL) pbytes);
CloseHandle(hFile);
return bResult;
}
GlobalFree( (HGLOBAL) pbytes);
}
}
CloseHandle(hFile);
return false;
}
return false;
}
DWORD CHtmlSignatureAddInCtrl::GetControlFlags()
{
DWORD dwFlags = COleControl::GetControlFlags();
dwFlags |=windowlessActivate;
return dwFlags;
}
void CHtmlSignatureAddInCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
/* IOleInPlaceSite *pOleInPlaceSite = NULL;
if (NOERROR==m_pClientSite->QueryInterface(IID_IOleInPlaceSite, (LPVOID *)&pOleInPlaceSite))
{
pOleInPlaceSite->GetWindow((HWND *)&m_hWndParent);
pOleInPlaceSite->Release();
}
HMODULE hModule = ::GetModuleHandle("D:\\lvfeng\\HtmlSignatureAddIn\\Debug\\HtmlSignatureAddIn.ocx");
HINSTANCE hInst = hModule;
HWND
hwnd=::CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_ABOUTBOX_HTMLSIGNATU READDIN),m_hWndParent,NULL,SW_SHOW);
::ShowWindow(hwnd,SW_SHOW);*/
this->SetCapture();
this->m_IsRbtnDown=true;
CRect rect;
this->GetRectInContainer(rect);
m_width=point.x-rect.left;//鼠标到左顶点x方向距离
m_height=point.y-rect.top;//鼠标到左顶点y方向距离
COleControl::OnLButtonDown(nFlags, point);
}
void CHtmlSignatureAddInCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect rect;
int px,py;
this->GetControlSize(&px,&py);
rect.left=point.x-m_width;
rect.top=point.y-m_height;
rect.right=px+rect.left;
rect.bottom=py+rect.top;
m_ocxLeft.Format("%d",rect.left);
m_ocxTop.Format("%d",rect.top);
m_ocxWidth.Format("%d",px);
m_ocxHeight.Format("%d",py);
this->SetRectInContainer(rect);
InvalidateControl();
m_IsRbtnDown=false;
ReleaseCapture();
m_point=0;
COleControl::OnLButtonUp(nFlags, point);
}
void CHtmlSignatureAddInCtrl::OnEnableMoveSigChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加属性处理程序代码
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnDivIdChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnDocumentIdChanged(void) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnFieldListChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnIEVersionChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnUserNameChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加属性处理程序代码
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnPassWordChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加属性处理程序代码
SetModifiedFlag();
}
BSTR CHtmlSignatureAddInCtrl::GetSignatureIP(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CString strResult;
return strResult.AllocSysString();
}
void CHtmlSignatureAddInCtrl::SetSignatureIP(LPCTSTR newVal) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnSignatureNameChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnSignatureTimeChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnSignatureSerialIdChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
void CHtmlSignatureAddInCtrl::OnSignatureCodeChanged(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SetModifiedFlag();
}
//下午查这个
IDropTarget* CHtmlSignatureAddInCtrl::GetWindowlessDropTarget()
{
return NULL;
}
BOOL CHtmlSignatureAddInCtrl::OnWindowlessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
{
// TODO: 在此添加专用代码和/或调用基类
return COleControl::OnWindowlessMessage(msg, wParam, lParam, plResult);
}
void CHtmlSignatureAddInCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
/* IOleClientSite *pClientSite=NULL;
pClientSite= GetClientSite();
IOleContainer* pContainer = NULL;
IHTMLDocument2 *pDoc=NULL;
IHTMLWindow2 *htmWindow=NULL;
IHTMLEventObj *htmEvnt=NULL;
pClientSite->GetContainer(&pContainer);
if (pContainer != NULL )
pContainer->QueryInterface(IID_IHTMLDocument2, (void **)&pDoc);
pDoc->get_parentWindow(&htmWindow);*/
/*
CMenu *pmenu=NULL;
HMODULE hModule = ::GetModuleHandle("D:\\lvfeng\\HtmlSignatureAddIn\\Debug\\HtmlSignatureAddIn.ocx");
HINSTANCE hInst = hModule;
HMENU
hmenu=::LoadMenu(hInst,MAKEINTRESOURCE(CG_IDR_POPUP_HTML_SIGNA TURE_AD D_IN_CTRL));
pmenu=CMenu::FromHandle(hmenu);
CMenu* pPopup = pmenu->GetSubMenu(0);
ASSERT(pPopup != NULL);
IOleInPlaceSite *pOleInPlaceSite = NULL;
if (NOERROR==m_pClientSite->QueryInterface(IID_IOleInPlaceSite, (LPVOID *)&pOleInPlaceSite))
{
pOleInPlaceSite->GetWindow((HWND *)&m_hWndParent);
pOleInPlaceSite->Release();
}
CWnd* pWndPopupOwner =CWnd::FromHandle(m_hWndParent);
CRect rect;
this->GetRectInContainer(rect);
CString str;
str.Format("px=%d,py=%d",rect.left,rect.top);
::TrackPopupMenu(pPopup->m_hMenu,TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,rect.left+point.x,rect.top+point.y,0,m_hWndParent,NULL);
*/
COleControl::OnRButtonDown(nFlags, point);
}
void CHtmlSignatureAddInCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
// TODO: 在此处添加消息处理程序代码
CMenu menu; //= AfxGetMainWnd()->GetMenu();
ASSERT(menu.LoadMenu(CG_IDR_POPUP_HTML_SIGNATURE_ADD_IN_CTRL));
CMenu* file_menu = menu.GetSubMenu(0);
ASSERT(file_menu);
file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
}
//查看证书
void CHtmlSignatureAddInCtrl::OnMenuViewcert()
{
// TODO: Add your command handler code here
//显示my证书库的所有证书;
//并且选择其中一个作为签章的证书;
HCERTSTORE hCertStore;
PCCERT_CONTEXT pCertContext=NULL;
char pszNameString[256];
unsigned char pszStoreName[256]="MY";
void* pvData;
DWORD cbData;
DWORD dwPropId=0;
if ( !(hCertStore = CertOpenSystemStore(0,L"my")))
{
MessageBox("打开证书库时失败!","错误信息提示",MB_OK);
}
//pCertContext=CertFindCertificateInStore(hCertStore,MY_ENCODING_TYPE,0,CERT_FIND_ CERT_ID,&fcert_id,NULL);
while(pCertContext= CertEnumCertificatesInStore(
hCertStore,
pCertContext))
{
if (pCertContext!=NULL)
{
if
(CertCompareCertificate(MY_ENCODING_TYPE,(m_pCertContext->pCertInfo),(pCertContext->pCertInfo)))
//if (pCertContext)
{
if (!CryptUIDlgViewContext(
CERT_STORE_CERTIFICATE_CONTEXT,
pCertContext,
NULL,
NULL,
0,
NULL))
{
MessageBox("查看证书时失败!","错误信息提示",MB_OK);
}
}
}
}
CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore,0);
}
//数字签名
void CHtmlSignatureAddInCtrl::OnMenuNumsignature()
{
//显示my证书库的所有证书;
//并且选择其中一个作为签章的证书;
HCERTSTORE hCertStore;
PCCERT_CONTEXT pCertContext=NULL;
char pszNameString[256];
unsigned char pszStoreName[256]="MY";
void* pvData;
DWORD cbData;
DWORD dwPropId=0;
if ( !(hCertStore = CertOpenSystemStore(0,L"my")))
{
MessageBox("打开证书库时失败!","错误信息提示",MB_OK);
}
if(!(pCertContext = CryptUIDlgSelectCertificateFromStore(
hCertStore,
this->m_hWnd,
NULL,
NULL,
CRYPTUI_SELECT_LOCATION_COLUMN,
0,
NULL)))
{
MessageBox("选择证书失败!","错误信息提示",MB_OK);
}
else
{
this->m_pCertContext=pCertContext;
fcert_id.dwIdChoice=CERT_ID_ISSUER_SERIAL_NUMBER;
fcert_id.IssuerSerialNumber.Issuer =pCertContext->pCertInfo->Issuer;
fcert_id.IssuerSerialNumber.SerialNumber= pCertContext->pCertInfo->SerialNumber;
}
//--------------------------------------------------------------------
// Clean up.
// CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore,0);
}
//签名认证
void CHtmlSignatureAddInCtrl::OnMenuCertify()
{
// TODO: Add your command handler code here
}
BOOL CHtmlSignatureAddInCtrl::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;//COleControl::OnEraseBkgnd(pDC);
}
/******************************************************************** HtmlSignatureAddIn.cpp : Implementation of CHtmlSignatureAddInApp and DLL registration. ********************************************************************/
#include "stdafx.h"
#include "HtmlSignatureAddIn.h"
#include ".\htmlsignatureaddin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CHtmlSignatureAddInApp NEAR theApp;
const GUID CDECL BASED_CODE _tlid =
{ 0xa74accd3, 0xe192, 0x4708, { 0x9a, 0xe8, 0x85, 0x37, 0x6e, 0x6b, 0x8b, 0x86 } }; const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInApp::InitInstance - DLL initialization
BOOL CHtmlSignatureAddInApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
//this->CreateMsgHandlerWindow();
}
return bInit;
}
////////////////////////////////////////////////////////////////////////////
// CHtmlSignatureAddInApp::ExitInstance - DLL termination
int CHtmlSignatureAddInApp::ExitInstance()
{
// TODO: Add your own module termination code here.
return COleControlModule::ExitInstance();
}。