⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webctl.cpp

📁 web应用控件,主要是实现的web开发中文件的加密和解密.该控件b/s架构的应用系统 中有比较好的用途
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WebCtl.cpp : Implementation of the CWebCtrl ActiveX Control class.

#include "stdafx.h"
#include "Web.h"
#include "WebCtl.h"
#include "WebPpg.h"
///////////////IIS头文件///////////
#include <iads.h>
#include <windows.h>
#include <comdef.h>
#include <Adshlp.h>
#include <activeds.h>
#pragma comment(lib,"activeds.lib")
#pragma comment(lib,"adsiid.lib")
//////////////////////////////

///////////////文件下载///////////
#include "direct.h"
#include "string.h"
#include "afxinet.h"
//////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CWebCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CWebCtrl, COleControl)
	//{{AFX_MSG_MAP(CWebCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CWebCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CWebCtrl)
	DISP_FUNCTION(CWebCtrl, "CreateKSDirectory", CreateKSDirectory, VT_BOOL, VTS_BSTR)
	DISP_FUNCTION(CWebCtrl, "CreateVirtualDirection", CreateVirtualDirection, VT_BOOL, VTS_BSTR VTS_BSTR)
	DISP_FUNCTION(CWebCtrl, "DeleteKSDirectory", DeleteKSDirectory, VT_BOOL, VTS_BSTR)
	DISP_FUNCTION(CWebCtrl, "UpFile", UpFile, VT_BOOL, VTS_BSTR VTS_BSTR VTS_BSTR)
	DISP_FUNCTION(CWebCtrl, "DownFile", DownFile, VT_BOOL, VTS_BSTR VTS_BSTR VTS_BSTR)
	DISP_FUNCTION(CWebCtrl, "OpenFrontPage", OpenFrontPage, VT_EMPTY, VTS_BSTR)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CWebCtrl, COleControl)
	//{{AFX_EVENT_MAP(CWebCtrl)
	// 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(CWebCtrl, 1)
	PROPPAGEID(CWebPropPage::guid)
END_PROPPAGEIDS(CWebCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CWebCtrl, "WEB.WebCtrl.1",
	0x383828e0, 0x431e, 0x4562, 0x85, 0x9, 0xff, 0xa7, 0xa4, 0xa, 0xce, 0xa1)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CWebCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DWeb =
		{ 0x4846182e, 0x7c7e, 0x4af7, { 0xbd, 0x54, 0xb0, 0x90, 0x4e, 0xdb, 0x72, 0x7b } };
const IID BASED_CODE IID_DWebEvents =
		{ 0xa32cb279, 0x2f91, 0x4d4d, { 0x90, 0xa3, 0x4e, 0x33, 0x31, 0xc2, 0x67, 0xa } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwWebOleMisc =
	OLEMISC_INVISIBLEATRUNTIME |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CWebCtrl, IDS_WEB, _dwWebOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::CWebCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CWebCtrl

BOOL CWebCtrl::CWebCtrlFactory::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_WEB,
			IDB_WEB,
			afxRegApartmentThreading,
			_dwWebOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::CWebCtrl - Constructor

CWebCtrl::CWebCtrl()
{
	InitializeIIDs(&IID_DWeb, &IID_DWebEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::~CWebCtrl - Destructor

CWebCtrl::~CWebCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::OnDraw - Drawing function

void CWebCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	//pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	//pdc->Ellipse(rcBounds);

	if (!IsOptimizedDraw())
	{
		// The container does not support optimized drawing.

		// TODO: if you selected any GDI objects into the device context *pdc,
		//		restore the previously-selected objects here.
		//		For more information, please see MFC technical note #nnn,
		//		"Optimizing an ActiveX Control".
	}
}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::DoPropExchange - Persistence support

void CWebCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::GetControlFlags -
// Flags to customize MFC's implementation of ActiveX controls.
//
// For information on using these flags, please see MFC technical note
// #nnn, "Optimizing an ActiveX Control".
DWORD CWebCtrl::GetControlFlags()
{
	DWORD dwFlags = COleControl::GetControlFlags();


	// The control can activate without creating a window.
	// TODO: when writing the control's message handlers, avoid using
	//		the m_hWnd member variable without first checking that its
	//		value is non-NULL.
	dwFlags |= windowlessActivate;

	// The control can receive mouse notifications when inactive.
	// TODO: if you write handlers for WM_SETCURSOR and WM_MOUSEMOVE,
	//		avoid using the m_hWnd member variable without first
	//		checking that its value is non-NULL.
	dwFlags |= pointerInactive;

	// The control can optimize its OnDraw method, by not restoring
	// the original GDI objects in the device context.
	dwFlags |= canOptimizeDraw;
	return dwFlags;
}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl::OnResetState - Reset control to default state

void CWebCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CWebCtrl message handlers

////////////创建一个空的考生目录/////////////////
BOOL CWebCtrl::CreateKSDirectory(LPCTSTR ksDir) 
{
	// TODO: Add your dispatch handler code here
if(SetCurrentDirectory(ksDir)==0)////////////判断目录是否存在,不存在则创建目录
{
 SECURITY_ATTRIBUTES attrib;
 attrib.bInheritHandle = FALSE;
 attrib.lpSecurityDescriptor = NULL;
 attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
 
 return ::CreateDirectory(ksDir, &attrib);
}
return true;//////////目录存在,不创建返回true
}

///////////////////将考生目录设为虚拟目录/////////////////////////
BOOL CWebCtrl::CreateVirtualDirection(LPCTSTR lpszVirtualDirName, LPCTSTR lpszDiskPath) 
{
	// TODO: Add your dispatch handler code here
IADsContainer* iContainer;
	IADs* iAds;
	/* 获得WebSever */
	if(ADsGetObject(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&iContainer)==S_OK)
	{
		//等到默认站点
		iContainer->GetObject(_bstr_t("IIsWebServer"), _bstr_t("1"),(IDispatch**)&iAds);
		if(iAds->QueryInterface(IID_IADsContainer,(void**)&iContainer)==S_OK)
		{
			//得到默认站点的根目录
			iContainer->GetObject(_bstr_t("IIsWebVirtualDir"),_bstr_t("Root"),(IDispatch**)&iAds);
			//获得访问虚拟目录
			if(iAds->QueryInterface(IID_IADsContainer,(void**)&iContainer)==S_OK)
			{
				//先删除了虚拟目录
				iContainer->Delete(_bstr_t("IIsWebVirtualDir"), _bstr_t(lpszVirtualDirName));
				//建立虚拟目录
				
				if(iContainer->Create(_bstr_t("IIsWebVirtualDir"), _bstr_t(lpszVirtualDirName),(IDispatch**)&iAds)==S_OK)
				{
					//设置虚拟目录的属性
					iAds->Put(_bstr_t("AccessRead"),_variant_t("True"));//注意跟VB中的设置属性比较
					iAds->Put(_bstr_t("AccessWrite"),_variant_t("True"));
                    iAds->Put(_bstr_t("AccessScript"),_variant_t("True"));
					iAds->Put(_bstr_t("AccessExecute"),_variant_t("True"));
                    iAds->Put(_bstr_t("EnableDirBrowsing"),_variant_t("True"));
                    iAds->Put(_bstr_t("EnableDefaultDoc"),_variant_t("True"));
	 				iAds->Put(_bstr_t("AppAllowDebugging"),_variant_t("True"));
					iAds->Put(_bstr_t("AppFriendlyName"),_variant_t(lpszVirtualDirName));
					
					iAds->Put(_bstr_t("Path"),_variant_t(lpszDiskPath));
					/////////////////////设置为应用程序///////////////////////////////////////////////

                                   OLECHAR * arrFunName[]={L"AppCreate"};   //定义com的函数名称

                                   DISPID dispID;

                                   iContainer->GetIDsOfNames(IID_NULL,arrFunName,1,LOCALE_SYSTEM_DEFAULT,&dispID);      //取得DISPID值,由dispID返回

                                   VARIANTARG v[1];

                                   v[0].vt=VT_BOOL; 
								   v[0].boolVal=TRUE;    //AppCreate的参数负值,

                                   DISPPARAMS params={v,NULL,1,0};                  //定义DISPPARAMS参数

                                   VARIANT vResult;

                                   iAds->Invoke(dispID,IID_NULL,LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD,&params,&vResult,NULL,NULL);    //开始调用方法

////////////////////////////////////////////////////////////////////////////////////////////////////////


					iAds->SetInfo();
					iAds->Release();
					iAds->Release();
					iContainer->Release();
					iContainer->Release();
					return true;
				}
				else
				{
					iAds->Release();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -