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

📄 bcamtopologyviewctl.cpp

📁 BCAM 1394 Driver
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		default:
			{
				if (m_Details) s.Format(_T( "%s %d : PhysicalId: %d"), text, port, (LPCSTR)ptr->PhysicalId() ) ;
				else s = "Node";
				hNewItem = InsertItem(s,0,0, hCurrentItem, TVI_LAST);
			}
		};
	}
	else
	{
		if (m_Details)
		{
			if (m_Details) s.Format(_T( "%s %d : not connected"), text, port ) ;
			else s = "";
			hNewItem = InsertItem(s,2,2, hCurrentItem, TVI_LAST);
		}
	}
	return hNewItem;
}

//------------------------------------------------------------------------------
// void CBcamTopologyViewCtl::ReleaseTree(HTREEITEM hTreeItem)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* recursive helper method to release the nodes associated with a tree 
* of items
*
* \param     hTreeItem root of the tree
*/
//------------------------------------------------------------------------------
void CBcamTopologyViewCtl::ReleaseTree(HTREEITEM hTreeItem)
{
	CNode* pNode = (CNode*)GetItemData(hTreeItem);
	if (pNode != NULL) pNode->Release();
		
	HTREEITEM hNextItem = GetChildItem(hTreeItem);
	while(hNextItem != NULL)
    {
		ReleaseTree(hNextItem);
		hNextItem = GetNextSiblingItem(hNextItem);
    }
}
//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnDeviceChange(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
*
* Message handler for WM_DEVICECHANGE frees all data allocated on creation.
* If a new adapter is added to the system or an existing one is removed, the topology information
* will be retrieved again
*/

LRESULT CBcamTopologyViewCtl::OnDeviceChange(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
  switch (wParam) 
  {
  case DBT_DEVICEARRIVAL: 
  case DBT_DEVICEREMOVECOMPLETE: 

    if( reinterpret_cast<PDEV_BROADCAST_HDR>(lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
    {
      HCURSOR oldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
      // rebuild tree
      ReleaseAdapters();
      ReleaseNodes();
      BuildAdapters();
      BuildTree();
      if (m_FirstItem != NULL) SelectItem(m_FirstItem);
      SetCursor(oldCursor);
    }
    break;
  }

  return 1;
}

//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* message handler for WM_DESTROY frees all data allocated on creation
*
* \param     bHandled set to false, to let the control handle the rest of the WM_DESTROY message
* \return    1
*
*/
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
  ReleaseAdapters();
  ReleaseNodes();

	m_Roots.clear();
	m_ImageList.Destroy();

  if ( m_hNotify )
    UnregisterDeviceNotification(m_hNotify);
	
	// Let the Control handle the rest of the WM_DESTROY message
	bHandled = false;
	return 1;
}

//------------------------------------------------------------------------------
// void CBcamTopologyViewCtl::ReleaseNodes()
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* 	Deletes all adapters and clears the adapter list
*
*/
//------------------------------------------------------------------------------
void CBcamTopologyViewCtl::ReleaseAdapters()
{
	ReleaseNodes();
	for (AdapterList::iterator it1 = m_Adapters.begin(); it1 != m_Adapters.end(); it1++)
		delete(*it1);
	for (ResourceDialogList::iterator it2 = m_ResourceDialogs.begin(); it2 != m_ResourceDialogs.end(); it2++)
	{
		CResourcesDlg * d =(*it2);
		if (d->IsWindow()) 
			d->DestroyWindow();
		delete(*it2);
	}
	m_Adapters.clear();
  m_ResourceDialogs.clear();
}

//------------------------------------------------------------------------------
// void CBcamTopologyViewCtl::ReleaseNodes()
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* 	Releases all nodes
*
*/
//------------------------------------------------------------------------------
void CBcamTopologyViewCtl::ReleaseNodes()
{
	
	// Walk the TreeControl first layer
	HTREEITEM hCurrentRoot = GetRootItem();
	while(hCurrentRoot != NULL)
	{
		// Walk the TreeControl layers
		ReleaseTree(hCurrentRoot);
		
		hCurrentRoot = GetNextSiblingItem(hCurrentRoot);
	}
	DeleteAllItems();
}



//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnDeviceInformation(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
*  shows the properties of the node
*
* \param     bHandled set to false to let the control handle the rest 
* \return    0
*
*/
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnDeviceInformation(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
	SetMsgHandled(TRUE); 
	HTREEITEM hItem = GetSelectedItem();
	CNode* p = (CNode*) GetItemData(hItem);
	// if the selected item has data, it indicates the selected connection
	if (p != NULL)
	{
		CPropertiesDlg *NodeProperties = new CPropertiesDlg(p);
		NodeProperties->DoModal(m_hWnd);
		delete NodeProperties;
	}
	else
	{
		CNoDevicePropertiesDlg dlg;
		dlg.DoModal();
	}
	
	// let the control handle the rest
	SetMsgHandled(false);
	bHandled = false;
	return 0;
}


//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnResources(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
*  shows the available resources
*
* \param     bHandled set to false to let the control handle the rest 
* \return    0
*
*/
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnResources(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
	SetMsgHandled(TRUE); 
	HTREEITEM hItem = GetSelectedItem();
	HTREEITEM hPrevSibling;
	ResourceDialogList::iterator it = m_ResourceDialogs.begin();
	// move the iterator for each sibling preceding the selected root
	do
	{
		hPrevSibling = GetPrevSiblingItem(hItem);
		if (hPrevSibling != NULL)
		{
			hItem = hPrevSibling;
			it++;
		}
	} while (hPrevSibling != NULL);
	CResourcesDlg *AdapterResources = *(it);
	if (!AdapterResources->IsWindow())
		AdapterResources->Create(m_hWnd);
	AdapterResources->OnClickedResources_update(0,0,NULL,bHandled);
	AdapterResources->ShowWindow(SW_SHOW);
	
	// let the control handle the rest
	SetMsgHandled(false);
	bHandled = false;
	return 0;
}


// Set the color of the current connection responding to the connection state
// blue = connectable
// green = connected
// red = unconnectable
//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnCustomDrawTree(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* customized drawing of tree items
* in controls prepaint stage tell windows that we want messages for every item
* in items prepaint stage set the items background color 
*
* \param     pnmh holds information about the draw state
* \return    
*
* desired handling of messages
* 
* CDRF_NOTIFYITEMDRAW in the controls prepaint stage
* CDRF_DODEFAULT	   in all other stages
*
*/
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnCustomDrawTree(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
	
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*> ( pnmh );
	// take the default processing unless we set this to something else below
	LRESULT result = CDRF_DODEFAULT;
	
	// check draw state. If it's the control's prepaint stage, thenn tell Windows we want messages 
	// for every item
	
	if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
	{
		result = CDRF_NOTIFYITEMDRAW;
	}
	else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
	{
		// prepage stage for a item.
		// here is where we set the item's text and background colors. 
		// the return value will tell windows to draw the subitem itself, but it will use the new colors we set here
		COLORREF crBkgnd;
		HTREEITEM nItem = (HTREEITEM)( pLVCD->nmcd.dwItemSpec);
		
		{
			crBkgnd = RGB(255,255,255);
			if ((GetItemData(nItem)) && (nItem == GetSelectedItem()))
			{
				crBkgnd = RGB(0x99,0xcc,0xff);				
			}
			else 
			{
				HTREEITEM child = GetChildItem(GetSelectedItem());
				while (child != NULL)
				{
					if (child == nItem)
						crBkgnd = RGB(0xcc,0xee,0xff);
					child = GetNextSiblingItem(child);
				}
			}
			
			pLVCD->clrTextBk = crBkgnd;
			pLVCD->clrText = RGB(0,0,0);
			
			result =  CDRF_DODEFAULT;
		}
		
	}
	UpdateWindow();
	return result;
}


//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnSelchangedTree(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& bHandled)
// Author: 
// Date: 02.09.2002
//------------------------------------------------------------------------------
/**
 * 	check if there is a new node selected, if so update current selection and fire SelectionChanged
 *
 * \param     bHandled set to false to let the control handle the rest
 * \return    0
 *
 */
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnSelchangedTree(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& bHandled)
{
	HTREEITEM hItem = GetSelectedItem();
	// if the selected item has data, it indicates the selected connection
	if (GetItemData(hItem))
	{
		// check if we have to update the current selection
		if ( hItem != m_CurSelectionItem ) 
		{
			SelectItem(hItem);
			m_CurSelectionItem = hItem;
			Invalidate(FALSE);
			UpdateWindow();
		}
	}

	// let the control handle the rest
	SetMsgHandled(false);
	bHandled = false;
	return 0;
}





//------------------------------------------------------------------------------
// void CBcamTopologyViewCtl::BusResetCallback( CBcamAdapter& adapter, void *pv)
// Author: 
// Date: 05.12.2002
//------------------------------------------------------------------------------
/**
 * Callback to be called from the adapter when a bus reset occured
 *
 * \param     adapter the adapter on which the bus reset occured
 * \param     *pv     pointer to the BcamTopologyViewCtl which has set the BusResetCallback
 * \return    
 *
 * <type Return description here>
 * 
 * \see       <delete line if not used>
 * \todo      
 */
//------------------------------------------------------------------------------



void CBcamTopologyViewCtl::BusResetCallback( CBcamAdapter& adapter, void *pv)
{
	CBcamTopologyViewCtl * ctl = (CBcamTopologyViewCtl*)pv;
	
	::PostMessage(ctl->WindowHandle(), WM_BCAM_BUSRESET, 0,0);
}

//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnBusReset(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
// Author: 
// Date: 05.12.2002
//------------------------------------------------------------------------------
/**
 * message handler for bus reset message, updates the topology tree
 *
 * \param     uMsg
 * \param     wParam
 * \param     lParam
 * \param     bHandled
 * \return    
 *
 * <type Return description here>
 * 
 * \see       <delete line if not used>
 * \todo      
 */
//------------------------------------------------------------------------------

LRESULT CBcamTopologyViewCtl::OnBusReset(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	Beep(1000,500);
    HCURSOR oldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
	Sleep(1000);
	
	Update();
	
	SetCursor(oldCursor);
	SetMsgHandled(TRUE); 
	return TRUE; 
}

//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnContextMenu(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* popup a context menu
*
* \param     wParam holds the flags for hitTest
* \param     lParam holds the location of the mouse
* \param     bHandled set to false, to let the control handle the rest
* \return    0
*
*/
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnContextMenu(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	SetMsgHandled(TRUE); 
	UINT Flags = (UINT) wParam;
	CPoint point = CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
	// if Shift-F10
	if (point.x == -1 && point.y == -1)
		point = (CPoint) GetMessagePos();	
	ScreenToClient(&point);
	HTREEITEM hItem = HitTest( point, &Flags );
	if(hItem && (Flags & TVHT_ONITEM) )
	{
		SelectItem(hItem);
		m_CurSelectionItem = hItem;
		
		Invalidate(FALSE);
		UpdateWindow();
		CMenu menuContext;
		HTREEITEM hParent = GetParentItem(hItem);
		if (hParent != NULL)
		{
			menuContext.LoadMenu(IDR_NODECONTEXTMENU);
		}
		else
		{
			menuContext.LoadMenu(IDR_ROOTCONTEXTMENU);
		}

		ClientToScreen(&point);
		UINT n = menuContext.GetMenuItemCount();
		CMenuHandle menuPopup(menuContext.GetSubMenu(0));
		RECT rect; // ignored by TrackPopupMenu
		::TrackPopupMenu(menuPopup, TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x,  point.y,   0,  m_hWnd, &rect);
		bHandled = false;
	}
	
	return 0;
}

//------------------------------------------------------------------------------
// LRESULT CBcamTopologyViewCtl::OnRClick(int idCtrl, NMHDR* pNMHDR, BOOL& bHandled) 
// Author: 
// Date: 29.08.2002
//------------------------------------------------------------------------------
/**
* the tree control eats the OnContextMenu and sends a RClick notification so we
* send a WM_CONTEXTMENU to self
*
* \param     bHandled set to true
* \return    0 to suppree default handling
*
*/
//------------------------------------------------------------------------------
LRESULT CBcamTopologyViewCtl::OnRClick(int /*idCtrl*/, NMHDR* /*pNMHDR*/, BOOL& bHandled) 
{
	// Send WM_CONTEXTMENU to self
	SendMessage(WM_CONTEXTMENU, (WPARAM) m_hWnd, GetMessagePos());
	// Mark message as handled and suppress default handling
	bHandled = true;
	return 0;
}




⌨️ 快捷键说明

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