📄 authoritymgr.h
字号:
#ifndef __AUTHORITYMGR_H_
#define __AUTHORITYMGR_H_
#include "resource.h"
//#include <atlsnap.h>
#include "CZMisMMC.h"
#include "basenode.h"
#include "AllUserNode.h"
#include "AllGroupNode.h"
class CAuthorityMgrPage : public CSnapInPropertyPageImpl<CAuthorityMgrPage>
{
public :
CAuthorityMgrPage(long lNotifyHandle, bool bDeleteHandle = false, TCHAR* pTitle = NULL) :
CSnapInPropertyPageImpl<CAuthorityMgrPage> (pTitle),
m_lNotifyHandle(lNotifyHandle),
m_bDeleteHandle(bDeleteHandle) // Should be true for only page.
{
}
~CAuthorityMgrPage()
{
if (m_bDeleteHandle)
MMCFreeNotifyHandle(m_lNotifyHandle);
}
enum { IDD = IDD_AUTHORITYMGR };
BEGIN_MSG_MAP(CAuthorityMgrPage)
CHAIN_MSG_MAP(CSnapInPropertyPageImpl<CAuthorityMgrPage>)
END_MSG_MAP()
// Handler prototypes:
// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
HRESULT PropertyChangeNotify(long param)
{
return MMCPropertyChangeNotify(m_lNotifyHandle, param);
}
public:
long m_lNotifyHandle;
bool m_bDeleteHandle;
};
class CAuthorityMgrData :public CBaseNodeItem<CAuthorityMgrData>
{
public:
//所有用户节点对象指针
CAllUserNode* m_pAllUserNode;
//所有组节点对象指针
CAllGroupNode* m_pAllGroupNode;
//构造函数
CAuthorityMgrData()
{
//创建所有用户对象
m_pAllUserNode = new CAllUserNode();
//创建所有组对象
m_pAllGroupNode = new CAllGroupNode();
// Image indexes may need to be modified depending on the images specific to
// the snapin.
//初始化该节点在树控件及结构视图中的数据
memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
m_scopeDataItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM;
m_scopeDataItem.displayname = MMC_CALLBACK;
m_scopeDataItem.nImage = 0; // May need modification
m_scopeDataItem.nOpenImage = 0; // May need modification
m_scopeDataItem.lParam = (LPARAM) this;
memset(&m_resultDataItem, 0, sizeof(RESULTDATAITEM));
m_resultDataItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
m_resultDataItem.str = MMC_CALLBACK;
m_resultDataItem.nImage = 0; // May need modification
m_resultDataItem.lParam = (LPARAM) this;
}
//析构函数
~CAuthorityMgrData()
{
//销毁在构造函数中创建的对象
delete m_pAllUserNode;
delete m_pAllGroupNode;
}
STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
long handle,
IUnknown* pUnk,
DATA_OBJECT_TYPES type);
STDMETHOD(QueryPagesFor)(DATA_OBJECT_TYPES type)
{
if (type == CCT_SCOPE || type == CCT_RESULT)
return S_OK;
return S_FALSE;
}
//当用户点击该节点查看该节点的详细信息时MMC
//结果视图的数据类型
//这里返回为"消息类型",用于说明该管理单元的说明信息
STDMETHOD(GetResultViewType)(LPOLESTR *ppViewType,long *pViewOptions)
{
LPOLESTR lpOleStr = NULL;
HRESULT hr = StringFromCLSID(CLSID_MessageView, &lpOleStr);
if(SUCCEEDED(hr))
*ppViewType = lpOleStr;
else
*ppViewType = NULL;
*pViewOptions = MMC_VIEW_OPTIONS_NONE;
return S_FALSE;
}
//当用户点击该节点查看该节点的详细信息时MMC
//通过OnShow函数类来提供与GetResultViewType相应的数据
HRESULT OnShow(IConsole *spConsole, BOOL bShow)
{
//CComQIPtr<IResultData, &IID_IResultData> spResultData(spConsole);
HRESULT hr;
IUnknown *pUnk = NULL;
IMessageView *pMessageView = NULL;
hr = spConsole->QueryResultView(&pUnk);
if (SUCCEEDED(hr))
{
hr = pUnk->QueryInterface(IID_IMessageView, (void **)&pMessageView);
if (SUCCEEDED(hr))
{
pMessageView->SetIcon(Icon_Information);
pMessageView->SetTitleText(L"欢迎使用财政管理系统\n--------权限管理");
pMessageView->SetBodyText(L"您可以使用该模块完成以下功能:\n 1.管理本地用户对系统各模块的权限.\n 2.管理本地组对系统各模块的权限.\n注意,用户的最终权限受其所属的组的权限的影响!\n另外:程序列出系统用户和组的时候可能需要一些时间,请稍候。");
pMessageView->Release();
}
pUnk->Release();
}
return S_FALSE;
}
//当用户展开该树节点时,可通过该函数添加子节点的内容
HRESULT OnExpand(BOOL bExpand, IConsole *pConsole, HSCOPEITEM parent);
};
class CAuthorityMgr;
class CAuthorityMgrComponent : public CComObjectRootEx<CComSingleThreadModel>,
public CSnapInObjectRoot<2, CAuthorityMgr >,
public IExtendPropertySheetImpl<CAuthorityMgrComponent>,
public IExtendContextMenuImpl<CAuthorityMgrComponent>,
public IExtendControlbarImpl<CAuthorityMgrComponent>,
public IComponentImpl<CAuthorityMgrComponent>
{
public:
BEGIN_COM_MAP(CAuthorityMgrComponent)
COM_INTERFACE_ENTRY(IComponent)
COM_INTERFACE_ENTRY(IExtendPropertySheet)
COM_INTERFACE_ENTRY(IExtendContextMenu)
COM_INTERFACE_ENTRY(IExtendControlbar)
END_COM_MAP()
public:
CAuthorityMgrComponent():m_ipDisplayHelp(NULL)
{
}
STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param)
{
if (lpDataObject != NULL)
return IComponentImpl<CAuthorityMgrComponent>::Notify(lpDataObject, event, arg, param);
// TODO : Add code to handle notifications that set lpDataObject == NULL.
return E_NOTIMPL;
}
STDMETHOD(Initialize)(LPCONSOLE lpConsole)
{
HRESULT hr=IComponentImpl<CAuthorityMgrComponent>::Initialize(lpConsole);
_ASSERT( S_OK == hr );
hr = m_spConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
_ASSERT( S_OK == hr );
return hr;
}
STDMETHOD(Destroy)(long cookie)
{
if (m_ipDisplayHelp)
{
m_ipDisplayHelp->Release();
m_ipDisplayHelp = NULL;
}
HRESULT hr=IComponentImpl<CAuthorityMgrComponent>::Destroy(cookie);
return hr;
}
IDisplayHelp* m_ipDisplayHelp;
}
class CAuthorityMgr : public CComObjectRootEx<CComSingleThreadModel>,
public CSnapInObjectRoot<1, CAuthorityMgr>,
public IComponentDataImpl<CAuthorityMgr, CAuthorityMgrComponent>,
public IExtendPropertySheetImpl<CAuthorityMgr>,
public IExtendContextMenuImpl<CAuthorityMgr>,
public CComCoClass<CAuthorityMgr, &CLSID_AuthorityMgr>
{
public:
CAuthorityMgr()
{
m_pNode = new CAuthorityMgrData;
_ASSERTE(m_pNode != NULL);
m_pComponentData = this;
}
~CAuthorityMgr()
{
delete m_pNode;
m_pNode = NULL;
}
BEGIN_COM_MAP(CAuthorityMgr)
COM_INTERFACE_ENTRY(IComponentData)
COM_INTERFACE_ENTRY(IExtendPropertySheet)
COM_INTERFACE_ENTRY(IExtendContextMenu)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(IDR_AUTHORITYMGR)
DECLARE_NOT_AGGREGATABLE(CAuthorityMgr)
STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
static HRESULT LoadImages(IImageList*);
static void WINAPI ObjectMain(bool bStarting)
{
if (bStarting)
CSnapInItem::Init();
}
}
class ATL_NO_VTABLE CAuthorityMgrAbout : public ISnapinAbout,
public CComObjectRoot,
public CComCoClass< CAuthorityMgrAbout, &CLSID_AuthorityMgrAbout>
{
HBITMAP m_hSmallImage;
HBITMAP m_hLargeImage;
HBITMAP m_hSmallImageOpen;
HICON m_hAppIcon;
public:
CAuthorityMgrAbout()
{
m_hSmallImage = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_AUTHORITYMGR_32), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT);
m_hLargeImage = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_AUTHORITYMGR_32), IMAGE_BITMAP, 32, 32, LR_LOADTRANSPARENT);
m_hSmallImageOpen = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_SMOPEN), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT);
m_hAppIcon = LoadIcon(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDI_APPICON));
}
~CAuthorityMgrAbout()
{
::DeleteObject(m_hSmallImage);
::DeleteObject(m_hLargeImage);
::DeleteObject(m_hSmallImageOpen);
::DestroyIcon(m_hAppIcon);
}
DECLARE_REGISTRY(CAuthorityMgrAbout, _T("AuthorityMgrAbout.1"), _T("AuthorityMgrAbout.1"), IDS_AUTHORITYMGR_DESC, THREADFLAGS_BOTH);
BEGIN_COM_MAP(CAuthorityMgrAbout)
COM_INTERFACE_ENTRY(ISnapinAbout)
END_COM_MAP()
STDMETHOD(GetSnapinDescription)(LPOLESTR *lpDescription)
{
USES_CONVERSION;
TCHAR szBuf[256];
if (::LoadString(_Module.GetResourceInstance(), IDS_AUTHORITYMGR_DESC, szBuf, 256) == 0)
return E_FAIL;
*lpDescription = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
if (*lpDescription == NULL)
return E_OUTOFMEMORY;
ocscpy(*lpDescription, T2OLE(szBuf));
return S_OK;
}
STDMETHOD(GetProvider)(LPOLESTR *lpName)
{
USES_CONVERSION;
TCHAR szBuf[256];
if (::LoadString(_Module.GetResourceInstance(), IDS_AUTHORITYMGR_PROVIDER, szBuf, 256) == 0)
return E_FAIL;
*lpName = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
if (*lpName == NULL)
return E_OUTOFMEMORY;
ocscpy(*lpName, T2OLE(szBuf));
return S_OK;
}
STDMETHOD(GetSnapinVersion)(LPOLESTR *lpVersion)
{
USES_CONVERSION;
TCHAR szBuf[256];
if (::LoadString(_Module.GetResourceInstance(), IDS_AUTHORITYMGR_VERSION, szBuf, 256) == 0)
return E_FAIL;
*lpVersion = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
if (*lpVersion == NULL)
return E_OUTOFMEMORY;
ocscpy(*lpVersion, T2OLE(szBuf));
return S_OK;
}
STDMETHOD(GetSnapinImage)(HICON *hAppIcon)
{
*hAppIcon = m_hAppIcon;
return S_OK;
}
STDMETHOD(GetStaticFolderImage)(HBITMAP *hSmallImage,
HBITMAP *hSmallImageOpen,
HBITMAP *hLargeImage,
COLORREF *cMask)
{
*hSmallImage = m_hSmallImage;
*hSmallImageOpen = m_hSmallImageOpen;
*hLargeImage = m_hLargeImage;
*cMask = RGB(0, 128, 128);
if (*hSmallImage == NULL || *hLargeImage == NULL ||
*hSmallImageOpen == NULL)
return E_FAIL;
else
return S_OK;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -