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

📄 bcamtopologyviewctl.h

📁 BCAM 1394 Driver
💻 H
字号:
//-----------------------------------------------------------------------------
//  (c) 2002 by Basler Vision Technologies
//  Section:  Vision Components
//  Project:  BCAM
// Author: Margret Albrecht
// Date: 29.08.2002
//  $Header: BcamTopologyViewCtl.h, 10, 21.01.2003 15:34:00, Happe, A.$
//-----------------------------------------------------------------------------
/**
  \file     BcamTopologyViewCtl.h
 *
  \brief   Declaration of the CBcamTopologyViewCtl
 *
 * Declaration of a control showing the available IEEE1394 devices 
 * in a tree structure, the control distinguishes BCAM devices,
 * DCAM compliant devices and other devices
 */
//-----------------------------------------------------------------------------


#ifndef __BCAMTOPOLOGYVIEWCTL_H_
#define __BCAMTOPOLOGYVIEWCTL_H_

#include "resource.h"       // main symbols
#include <Bcam.h>
#include <BcamAdapter.h>
using namespace std;
using namespace Bcam;
#include "propertiesdlg.h"
#include "resourcesdlg.h"
#define WM_BCAM_BUSRESET WM_USER+100

// atlwin.h defines a NOTIFY_ID_HANDLER for WM_NOTIFY, but no handler for OCM_NOTIFY 
#if (WINVER >= 0x0400)
#define NOTIFY_REFLECT_CODE_HANDLER(cd, func) \
	if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
{ \
	bHandled = TRUE; \
	lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
	if(bHandled) \
	return TRUE; \
}
#endif

// WinTraits of the BcamTopologyViewCtl
typedef CWinTraits<WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE > CBcamTopologyControlWinTraits;

typedef std::list< CBcamAdapter* > AdapterList;
typedef std::list< CAdapt<CNodePtr> > RootList;
typedef std::list< CResourcesDlg* > ResourceDialogList;



// The base window class of the BcamTopologyViewCtl is CTreeViewCtrl
// A full control generated by the ATL wizard inherits from CComControl<T>
// the BcamTopologyViewCtl will inherit from CComTreeControl<CBcamTopologyControl>
// The class definition is copied frfom the class definition of CComControl<T>
// WinBase is set to CWindowImpl<T, CTreeViewCtrl, CBcamTopologyControlWinTraits>  instead of CWindowImpl< T >
// and the system tree control is registered in the constructor
template <class T, class WinBase =  CWindowImpl<T, CTreeViewCtrl, CBcamTopologyControlWinTraits> >
class ATL_NO_VTABLE CComTreeControl :  public CComControlBase, public WinBase
{
public:
	DECLARE_WND_SUPERCLASS(NULL, CTreeViewCtrl::GetWndClassName());
	CComTreeControl() : CComControlBase(m_hWnd) 
	{	
		// Make sure that the system tree control is registered
		INITCOMMONCONTROLSEX InitCtr;
		InitCtr.dwSize = sizeof(InitCtr);
		InitCtr.dwICC = ICC_TREEVIEW_CLASSES ;
		InitCommonControlsEx(&InitCtr);
	}
	HRESULT FireOnRequestEdit(DISPID dispID)
	{
		T* pT = static_cast<T*>(this);
		return T::__ATL_PROP_NOTIFY_EVENT_CLASS::FireOnRequestEdit(pT->GetUnknown(), dispID);
	}
	HRESULT FireOnChanged(DISPID dispID)
	{
		T* pT = static_cast<T*>(this);
		return T::__ATL_PROP_NOTIFY_EVENT_CLASS::FireOnChanged(pT->GetUnknown(), dispID);
	}
	virtual HRESULT ControlQueryInterface(const IID& iid, void** ppv)
	{
		T* pT = static_cast<T*>(this);
		return pT->_InternalQueryInterface(iid, ppv);
	}
	virtual HWND CreateControlWindow(HWND hWndParent, RECT& rcPos)
	{
		T* pT = static_cast<T*>(this);
		return pT->Create(hWndParent, rcPos);
	}
	
	typedef CComTreeControl< T, WinBase >	thisClass;
	BEGIN_MSG_MAP(thisClass)
		MESSAGE_HANDLER(WM_SETFOCUS, CComControlBase::OnSetFocus)
		MESSAGE_HANDLER(WM_KILLFOCUS, CComControlBase::OnKillFocus)
		MESSAGE_HANDLER(WM_MOUSEACTIVATE, CComControlBase::OnMouseActivate)
		END_MSG_MAP()
};

//------------------------------------------------------------------------------
// class ATL_NO_VTABLE CBcamTopologyViewCtl
// Author: M.Albrecht
// Date: 28.08.02
//------------------------------------------------------------------------------
/**
* \brief   TreeViewCtrl based ActiveX control showing the topology of IEEE1394 devices
*
*  The CBcamTopologyViewCtl is a TreeViewCtl showing the available IEEE1394 ports
*  Each node of the control corresponds to an IEEE1994 device 
*  The interface IBcamTopologyViewCtl allows you to force a rescan of the devices or to
*  generate a bus reset, and to toggle between short and detailed view
*  The selected node will be shown with with blue background, and it's ports with light blue background
*  The control uses the bacc driver to scan all IEEE1394 devices.
* 
* 
* 
*/
//------------------------------------------------------------------------------
class ATL_NO_VTABLE CBcamTopologyViewCtl : 
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IBcamTopologyViewCtl, &IID_IBcamTopologyViewCtl, &LIBID_BcamTopologyViewLib>,
public CComTreeControl<CBcamTopologyViewCtl>,
public IPersistStreamInitImpl<CBcamTopologyViewCtl>,
public IOleControlImpl<CBcamTopologyViewCtl>,
public IOleObjectImpl<CBcamTopologyViewCtl>,
public IOleInPlaceActiveObjectImpl<CBcamTopologyViewCtl>,
public IViewObjectExImpl<CBcamTopologyViewCtl>,
public IOleInPlaceObjectWindowlessImpl<CBcamTopologyViewCtl>,
public IConnectionPointContainerImpl<CBcamTopologyViewCtl>,
public IPersistStorageImpl<CBcamTopologyViewCtl>,
public ISpecifyPropertyPagesImpl<CBcamTopologyViewCtl>,
public IQuickActivateImpl<CBcamTopologyViewCtl>,
public IDataObjectImpl<CBcamTopologyViewCtl>,
public CComCoClass<CBcamTopologyViewCtl, &CLSID_BcamTopologyViewCtl>
{
public:
	CBcamTopologyViewCtl() 
	{
		m_bWindowOnly = TRUE;
		m_CurSelectionItem = 0;		
		m_FirstItem = NULL;
		m_Details = FALSE;
    m_hNotify = NULL;
	}
	
	DECLARE_REGISTRY_RESOURCEID(IDR_BCAMTOPOLOGYVIEWCTL)
		
		DECLARE_PROTECT_FINAL_CONSTRUCT()
		
		BEGIN_COM_MAP(CBcamTopologyViewCtl)
		COM_INTERFACE_ENTRY(IBcamTopologyViewCtl)
		COM_INTERFACE_ENTRY(IDispatch)
		COM_INTERFACE_ENTRY(IViewObjectEx)
		COM_INTERFACE_ENTRY(IViewObject2)
		COM_INTERFACE_ENTRY(IViewObject)
		COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
		COM_INTERFACE_ENTRY(IOleInPlaceObject)
		COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
		COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
		COM_INTERFACE_ENTRY(IOleControl)
		COM_INTERFACE_ENTRY(IOleObject)
		COM_INTERFACE_ENTRY(IPersistStreamInit)
		COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
		COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
		COM_INTERFACE_ENTRY(IQuickActivate)
		COM_INTERFACE_ENTRY(IPersistStorage)
		COM_INTERFACE_ENTRY(IDataObject)
		COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
		END_COM_MAP()
		
		BEGIN_CONNECTION_POINT_MAP(CBcamTopologyViewCtl)
		END_CONNECTION_POINT_MAP()
		
		// Interfaces which support the ErrorInfo object
		 // BEGIN_ERROR_INFO_MAP(CBcamTopologyViewCtl)
		//    SUPPORT_ERROR_INFO(IBcamTopologyViewCtl)
		//  END_ERROR_INFO_MAP()
		
		BEGIN_PROP_MAP(CBcamTopologyViewCtl)
		PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
		PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
		// Example entries
		// PROP_ENTRY("Property Description", dispid, clsid)
		// PROP_PAGE(CLSID_StockColorPage)
		END_PROP_MAP()
		
		BEGIN_MSG_MAP_EX(CBcamTopologyViewCtl)
#if (WINVER >= 0x0400)
		NOTIFY_REFLECT_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDrawTree)
		NOTIFY_REFLECT_CODE_HANDLER(NM_RCLICK, OnRClick)
		NOTIFY_REFLECT_CODE_HANDLER(TVN_SELCHANGED, OnSelchangedTree)
#endif
		CHAIN_MSG_MAP(CComTreeControl<CBcamTopologyViewCtl>)
		DEFAULT_REFLECTION_HANDLER()
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
		MESSAGE_HANDLER(WM_BCAM_BUSRESET, OnBusReset)
    MESSAGE_HANDLER(WM_DEVICECHANGE, OnDeviceChange)
		COMMAND_ID_HANDLER(ID_DEVICEINFORMATION, OnDeviceInformation)
		COMMAND_ID_HANDLER(ID_RESOURCES, OnResources)
		END_MSG_MAP()
		
		// IViewObjectEx
		DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
		
		// IBcamTopologyViewCtl
public:
	STDMETHOD(get_Details)(/*[out, retval]*/ VARIANT_BOOL *pVal);
	STDMETHOD(put_Details)(/*[in]*/ VARIANT_BOOL newVal);
	STDMETHOD(Update)();
	STDMETHOD(ResetBus)();
	
	
	HRESULT OnDraw(ATL_DRAWINFO& di);
	// generate imagelist and the tree of connected devices
	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	// Release nodes and destroy image list
	LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  // Handling of device notifications
  LRESULT OnDeviceChange(UINT uMst, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	// Set the color of the items
	// blue = selected
	LRESULT OnCustomDrawTree(int wParam, LPNMHDR pnmh, BOOL& bHandled);
	// check if there is a new leaf node selected, if so update current selection
	LRESULT OnSelchangedTree(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
	// callback function to get a driver notification on Bus Resets 
	static void BusResetCallback( CBcamAdapter& adapter, void *pv);
	// handle the WM_BUS_RESET message posted by BusResetCallback
	LRESULT OnBusReset(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	// the tree control eats the WM_CONTEXT_MENU message and sends a RClick notification
	// OnRClick generates a WM_CONTEXT_MENU message, so that we can handle it
	LRESULT OnRClick(int idCtrl, NMHDR* pNMHDR, BOOL& bHandled); 
	// messages generated from the context menu
	LRESULT OnDeviceInformation(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnResources(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	HWND WindowHandle() {return m_hWnd;}
protected:
	void Visit( CNodePtr p, HTREEITEM hCurrentItem);
	LRESULT BuildTree();
	void ReleaseTree(HTREEITEM hTreeItem);
	LRESULT BuildItemTree();
  void BuildAdapters();
  void ReleaseAdapters();
	void ReleaseNodes();
	HTREEITEM InsertNode(CNodePtr ptrNode, HTREEITEM hCurrentItem, char *text, int port);
	// Create tree with the bus topology
	CNode* GetTree(HANDLE hDevice) const;

	// members
	HTREEITEM	m_CurSelectionItem;			 // most recently selected leaf item
	AdapterList m_Adapters;   // list with all adapters found
	RootList m_Roots;   // list with all adapters found
	HTREEITEM m_FirstItem; // the node representing the first device
	ResourceDialogList m_ResourceDialogs;   // list with dialogs for all adapters found
  HDEVNOTIFY m_hNotify;   // device notification handle
	
	CImageList m_ImageList;
	VARIANT_BOOL m_Details;
	
};

#endif //__BCAMTOPOLOGYVIEWCTL_H_

⌨️ 快捷键说明

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