📄 busview.cpp
字号:
//-----------------------------------------------------------------------------
// (c) 2002 by Basler Vision Technologies
// Section: Vision Components
// Project: BCAM
// $Header: BusView.cpp, 14, 07.01.2003 14:38:47, Happe, A.$
//-----------------------------------------------------------------------------
/**
\file BusView.cpp
\brief Implementation of the CBusView class
*/
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "CameraManager.h"
#include "BusView.h"
#include "utility.h"
#include "Camera.h"
#include "mainfrm.h"
//------------------------------------------------------------------------------
// CBusView::CBusView(CCameraManager& CameraManager, CMainFrame& MainFrame)
//------------------------------------------------------------------------------
/**
* Constructs a new bus viewer window
*
* \param CameraManager Reference to the camera manager
* \param MainFrame Reference to the main frame
*/
//------------------------------------------------------------------------------
CBusView::CBusView(CCameraManager& CameraManager, CMainFrame& MainFrame)
: m_CameraManager(CameraManager), m_MainFrame(MainFrame), UNABLE_TO_OPEN("<Cannot open device>")
{
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Message handlers
//------------------------------------------------------------------------------
// LRESULT CBusView::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//------------------------------------------------------------------------------
/**
* WM_INITDIALOG message handler
*
* \param uMsg
* \param wParam
* \param lParam
* \param bHandled
* \return 0
*
*/
//------------------------------------------------------------------------------
LRESULT CBusView::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
m_TreeView.Attach(GetDlgItem(IDC_BUSTREE));
// Register the bus viewer window for device notifications, i.e. the bus viewer
// will be informed about new devices or devices which have been removed from the bus
try
{
CBcam::RegisterClient(m_hWnd);
}
CATCH_REPORT();
// Create Image List
m_ImageList.Create(16, 16, ILC_MASK, 4, 4);
CBitmap img;
CBitmap mask;
// insert image for "This PC"
img.LoadBitmap(IDB_BITMAP1);
mask.LoadBitmap(IDB_BITMAP2);
m_ImageList.Add(img, mask);
// insert image for "BCAM device"
img.Detach();
mask.Detach();
img.LoadBitmap(IDB_BITMAP3);
mask.LoadBitmap(IDB_BITMAP4);
m_ImageList.Add(img, mask);
m_TreeView.SetImageList(m_ImageList, TVSIL_NORMAL);
// Insert root item
m_RootItem = m_TreeView.InsertItem("This PC", 0, 0, TVI_ROOT, TVI_LAST);
std::list<CString> slResult;
try
{
slResult = CBcam::DeviceNames();
std::list<CString>::iterator pString;
for(pString = slResult.begin(); pString != slResult.end(); pString++)
{
AddNode(*pString, GUID_FILE_DEVICE_BCAM_1394);
}
} CATCH_REPORT();
m_TreeView.Expand(m_RootItem);
return 0;
}
//------------------------------------------------------------------------------
// LRESULT CBusView::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//------------------------------------------------------------------------------
/**
* WM_SIZE message handler
*
* \param uMsg
* \param wParam
* \param lParam
* \param bHandled
* \return 0
*
*/
//------------------------------------------------------------------------------
LRESULT CBusView::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
RECT rcClient;
GetWindowRect(&rcClient);
HWND hwnd;
RECT rc;
hwnd = GetDlgItem(IDC_BUSTREE);
::GetWindowRect(hwnd, &rc);
::SetWindowPos(hwnd, HWND_TOP,
0, 0,
rcClient.right-rc.left, rcClient.bottom-rc.top,
SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
return 0;
}
//------------------------------------------------------------------------------
// LRESULT CBusView::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//------------------------------------------------------------------------------
/**
* WM_CONTEXTMENU message handler
*
* \param uMsg
* \param wParam
* \param lParam
* \param bHandled
* \return 0
*
*/
//------------------------------------------------------------------------------
LRESULT CBusView::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
UINT Flags;
CPoint point = CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
m_TreeView.ScreenToClient(&point);
HTREEITEM hItem = m_TreeView.HitTest( point, &Flags );
if(hItem && (Flags & TVHT_ONITEM) )
{
m_TreeView.SelectItem(hItem);
if ( m_NodeMap.find(hItem) != m_NodeMap.end() )
{
CBusNode* pNode = m_NodeMap[hItem];
if ( pNode->Type() == bnBcam )
{
m_MainFrame.UpdateUI(); // to ensure the menu items are not longer disabled
// Display a context menu for Bcam Nodes
CMenu menuContext;
menuContext.LoadMenu(IDR_BUSVIEW_CONTEXT_MENU);
CMenuHandle menuPopup(menuContext.GetSubMenu(0));
m_TreeView.ClientToScreen(&point);
m_MainFrame.m_CmdBar.TrackPopupMenu(menuPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y);
}
}
}
return 0;
}
//------------------------------------------------------------------------------
// LRESULT CBusView::OnDeviceChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//------------------------------------------------------------------------------
/**
* WM_DEVICECHANGE message handler.
*
* WM_DEVICECHANGE messages are device notifications, which inform a window which is registerd for
* device notifications about new or removed devices
*
* \param uMsg
* \param wParam
* \param lParam
* \param bHandled
* \return 0
*
*/
//------------------------------------------------------------------------------
LRESULT CBusView::OnDeviceChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
try
{
switch (wParam)
{
case DBT_DEVICEQUERYREMOVE:
return 0;
case DBT_DEVICEARRIVAL: // a new device is added to the bus
{
ATLTRACE("DBT_DEVICEARRIVAL\n");
PDEV_BROADCAST_HDR devHdr;
devHdr = (PDEV_BROADCAST_HDR)lParam;
switch ( devHdr->dbch_devicetype )
{
case DBT_DEVTYP_DEVICEINTERFACE :
{
PDEV_BROADCAST_DEVICEINTERFACE devInterface;
devInterface = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
AddNode(BcamUtility::FriendlyDeviceName(devInterface->dbcc_name), devInterface->dbcc_classguid);
}
}
break;
}
case DBT_DEVICEREMOVECOMPLETE: // a device is removed from the bus
{
ATLTRACE("DBT_DEVICEREMOVECOMPLETE\n");
PDEV_BROADCAST_HDR devHdr;
devHdr = (PDEV_BROADCAST_HDR)lParam;
switch ( devHdr->dbch_devicetype )
{
case DBT_DEVTYP_DEVICEINTERFACE:
{
// a node is removed which we currently have not opened. Remove it from the BusView
PDEV_BROADCAST_DEVICEINTERFACE devInterface;
devInterface = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
CString deviceName = BcamUtility::FriendlyDeviceName(devInterface->dbcc_name);
RemoveNode(deviceName);
// Because the device has not been opened, the file handle based notification
// mechanism is not active, so tell the camera manager to remove a device
m_CameraManager.RemoveDevice(deviceName);
return TRUE;
}
}
break;
}
}
}
CATCH_REPORT();
return 0;
}
//------------------------------------------------------------------------------
// LRESULT CBusView::OnLButtonDblClk(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
//------------------------------------------------------------------------------
/**
* Called if the user performs a double click on one of the tree view's nodes
*
* \param idCtrl
* \param pnmh
* \param bHandled
* \return 0
*
*/
//------------------------------------------------------------------------------
LRESULT CBusView::OnLButtonDblClk(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
try
{
HTREEITEM hItem = m_TreeView.GetSelectedItem();
if ( m_NodeMap.find(hItem) != m_NodeMap.end() )
{
CBusNode* pNode = m_NodeMap[hItem];
if ( pNode->Type() == bnBcam )
{
// open new MDI child
if ( m_CameraManager.GetCurrentDevice() != NULL && ! m_CameraManager.ExistMDIChild() )
m_CameraManager.AddMDIChild();
}
}
} CATCH_REPORT();
return 0;
}
//------------------------------------------------------------------------------
// LRESULT CBusView::OnSelChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
//------------------------------------------------------------------------------
/**
* Called if the tree view's selection changes
*
* \param idCtrl
* \param pnmh
* \param bHandled
* \return 0
*
*/
//------------------------------------------------------------------------------
LRESULT CBusView::OnSelChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
try
{
LPNMTREEVIEW pnmtv = (LPNMTREEVIEW) pnmh;
HTREEITEM hItem = pnmtv->itemNew.hItem;
if ( m_NodeMap.find(hItem) != m_NodeMap.end() )
{
CBusNode* pNode = m_NodeMap[hItem];
if ( pNode->Type() == bnBcam )
{
DWORD error = m_CameraManager.CurrentDeviceChanged(&pNode->DeviceName());
// Inform the application about the changed selection
if ( error == 0 )
{
CString ItemText;
if ( m_TreeView.GetItemText(hItem, ItemText) && ItemText == UNABLE_TO_OPEN )
{
// Currently we do not know the name of the camera, because it is the first time we could
// open the camera.
// Read the model Name
try
{
CCamera* pDevice = m_CameraManager.GetDevice(pNode->DeviceName());
if ( pDevice != NULL && pDevice->IsOpen() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -