?? webctl.cpp
字號:
// 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,¶ms,&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 + -