📄 mainfrm.cpp
字号:
//-----------------------------------------------------------------------------
// (c) 2002 by Basler Vision Technologies
// Section: Vision Components
// Project: BCAM
// $Header: mainfrm.cpp, 25, 14.10.2003 13:52:00, Happe, A.$
//-----------------------------------------------------------------------------
/**
\file mainfrm.cpp
*
* \brief Implementation of the CMainFrame class.
*
*/
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "mainfrm.h"
#include "ChildFrm.h"
#include "aboutdlg.h"
#include "zoomdlg.h"
#include "utility.h"
#include <htmlhelp.h>
CMainFrame::CMainFrame(bool fRestoreCameraSettings, bool fRestoreWindowLayout)
: m_CameraManager(*this),
m_BusView(m_CameraManager, *this),
m_fPropertyPageVisible(false),
m_fCurrentDeviceSupportsOneShot(false),
m_fCurrentDeviceSupportsShading(false),
m_fBroadCastFps(false),
m_pPropertyDlg(NULL),
m_fRestoreCameraSettings(fRestoreCameraSettings),
m_fRestoreWindowLayout(fRestoreWindowLayout),
m_fMono8(false),
m_fBayerColorFilter(false),
m_fYuv422(false),
m_fWhiteBalanceSupported(false)
{
}
CMainFrame::~CMainFrame()
{
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Message handlers
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// create command bar window
HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
// atach menu
m_CmdBar.AttachMenu(GetMenu());
// load command bar images
m_CmdBar.LoadImages(IDR_MAINFRAME);
// remove old menu
SetMenu(NULL);
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
CreateSimpleStatusBar("");
m_Sbar.SubclassWindow(m_hWndStatusBar);
int arrParts[] =
{
ID_DEFAULT_PANE,
ID_AOI_PANE,
ID_POS_PANE,
ID_VALUE_PANE,
ID_FPS_ACQUIRED_PANE,
ID_FPS_DISPLAYED_PANE
};
m_Sbar.SetPanes(arrParts, sizeof(arrParts) / sizeof(int), false);
CreateMDIClient();
m_CmdBar.SetMDIClient(m_hWndMDIClient);
UIAddToolBar(hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
// Create menu-control
CMessageLoop* pLoop = _Module.GetMessageLoop();
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
m_Dock.m_hwndClient = NULL;
HWND hwndDock = m_Dock.Create(m_hWnd, rcDefault);
m_Dock.SetClient(m_hWndMDIClient);
m_Dock.SetPaneSize(DOCK_LEFT, 120);
m_Dock.SetPaneSize(DOCK_RIGHT, 120);
m_Dock.SetPaneSize(DOCK_TOP, 50);
// Create camera feature windows
AddScalarFeature(FeatureID_Brightness, TRUE);
AddScalarFeature(FeatureID_Shutter);
AddScalarFeature(FeatureID_Gain);
AddBandwidthFeature();
AddWhiteBalanceFeature();
AddScalarFeature(FeatureID_Hue, FALSE, FALSE);
AddScalarFeature(FeatureID_Saturation, FALSE, FALSE);
AddScalarFeature(FeatureID_Gamma, FALSE, FALSE);
// if you add further features don't forget to update the UPDATE_UI_MAP in mainfrm.h
// and be aware of the correspondence between the resource id and the BcamFeatureId (functions.h) :
// ID_VIEW_XXX = ID_VIEW_FIRST_FEATURE + FeatureID_xxx ( resource.h )
// Create bus viewer window
m_BusView.Create(hwndDock, rcDefault);
m_Dock.AddWindow(m_BusView);
m_Dock.DockWindow(m_BusView, DOCK_LEFT);
UISetCheck(ID_VIEW_BUSVIEW, TRUE);
m_hWndClient = hwndDock;
// Restore the image size and position
if ( m_fRestoreWindowLayout )
{
WINDOWPLACEMENT p;
ZeroMemory(&p, sizeof(WINDOWPLACEMENT) );
p.rcNormalPosition.left = 24;
p.rcNormalPosition.right = 1000;
p.rcNormalPosition.top = 30;
p.rcNormalPosition.bottom = 734 ;
p.showCmd = SW_SHOWNORMAL;
int showCmd = SW_MAXIMIZE;
p.length = sizeof(WINDOWPLACEMENT);
try
{
CPropertyBagPtr ptrRegistry = CRegistryPropertyBag::Open(CString(APPLICATION_KEY) + "MainFrame");
p.rcNormalPosition.left = ptrRegistry->ReadLong("left");
p.rcNormalPosition.right = ptrRegistry->ReadLong("right");
p.rcNormalPosition.bottom = ptrRegistry->ReadLong("bottom");
p.rcNormalPosition.top = ptrRegistry->ReadLong("top");
showCmd = ptrRegistry->ReadLong("showCmd");;
}
catch ( BcamException& )
{
}
SetWindowPlacement(&p);
if ( showCmd == SW_MAXIMIZE )
{
PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
// register fps broadcast message
m_uFpsBroadCastMessage = RegisterWindowMessage(BROADCAST_FPS_MSG);
// check if we are asked to broadcast the frame rate
CRegKey regKey;
if ( regKey.Open(HKEY_CURRENT_USER, APPLICATION_KEY) == ERROR_SUCCESS )
{
DWORD val;
if ( regKey.QueryValue(val, ENABLE_BROADCAST_KEY) != ERROR_SUCCESS )
{
regKey.SetValue((DWORD) 0, ENABLE_BROADCAST_KEY); // if value entry doesn't exist, create it for convenience, but disable frame rate broadcast
}
else
{
m_fBroadCastFps = val != 0;
}
}
return 0;
}
LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
PostMessage(WM_CLOSE);
return 0;
}
LRESULT CMainFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
m_CameraManager.AddMDIChild();
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL && m_CameraManager.GetCurrentDevice()->GetBitmap() != NULL )
{
try
{
bool res = m_CameraManager.GetCurrentDevice()->GetBitmap()->CopyToClipboard(m_hWnd);
if ( ! res )
throw BcamException(::GetLastError(), "Copy to clipboard");
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL && ! m_CameraManager.IsGrabActive() )
{
CFileDialog dlg(TRUE, _T("bmp"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0"), m_hWnd);
if(dlg.DoModal() == IDOK)
{
try
{
m_CameraManager.GrabFromFile(dlg.m_szFileName);
}
CATCH_REPORT();
}
}
return 0;
}
LRESULT CMainFrame::OnFileSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL && m_CameraManager.GetCurrentDevice()->GetBitmap() != NULL )
{
try
{
CFileDialog dlg(FALSE, _T("bmp"), _T("Temp.bmp"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0"), m_hWnd);
if(dlg.DoModal() == IDOK)
{
bool res = m_CameraManager.GetCurrentDevice()->GetBitmap()->Save(dlg.m_szFileName);
if ( ! res )
throw BcamException(::GetLastError(), "Save Image");
}
} CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnFileSaveConfiguration(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CCamera* pCamera = m_CameraManager.GetCurrentDevice();
if ( pCamera == NULL )
return 0;
try
{
CFileDialog dlg(FALSE, _T("cfg"), pCamera->Info.ModelName()+".cfg", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Bcam Configuration Files (*.cfg)\0*.cfg\0"), m_hWnd);
if ( dlg.DoModal() == IDOK)
{
pCamera->SaveConfiguration(CString(dlg.m_szFileName));
}
} CATCH_REPORT();
return 0;
}
LRESULT CMainFrame::OnFileRestoreConfiguration(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CCamera* pCamera = m_CameraManager.GetCurrentDevice();
if ( pCamera == NULL )
return 0;
try
{
CFileDialog dlg(TRUE, _T("cfg"), pCamera->Info.ModelName()+".cfg", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Bcam Configuration Files (*.cfg)\0*.cfg\0"), m_hWnd);
if ( dlg.DoModal() == IDOK)
{
pCamera->RestoreConfiguration(CString(dlg.m_szFileName));
}
} CATCH_REPORT();
return 0;
}
LRESULT CMainFrame::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
try
{
m_CameraManager.AppExit();
} CATCH_REPORT();
try
{
CPropertyBagPtr ptrRegistry = CRegistryPropertyBag::Create(CString(APPLICATION_KEY) + "MainFrame");
WINDOWPLACEMENT p;
GetWindowPlacement(&p);
ptrRegistry->WriteLong("left", p.rcNormalPosition.left);
ptrRegistry->WriteLong("right", p.rcNormalPosition.right);
ptrRegistry->WriteLong("bottom", p.rcNormalPosition.bottom);
ptrRegistry->WriteLong("top", p.rcNormalPosition.top);
ptrRegistry->WriteLong("showCmd", p.showCmd);
FeatureMap_t::iterator feature;
for (feature = m_Features.begin(); feature != m_Features.end(); ++ feature)
{
HWND view = feature->second->hWnd();
::DestroyWindow(view);
delete feature->second;
}
}
catch ( BcamException& )
{ /* NOP */ }
bHandled = false;
return 0;
}
LRESULT CMainFrame::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
try
{
if (m_hMenu != NULL)
::DestroyMenu(m_hMenu);
m_hMenu = NULL;
if (m_BusView.IsWindow()) m_BusView.DestroyWindow();
if (m_CmdBar.IsWindow()) m_CmdBar.DestroyWindow();
}
catch ( BcamException& )
{ /* NOP */ }
bHandled = false;
return 0;
}
// An error occured in the thread procedure of an image acquisition thread. The thread sends
// a user defined message to the main frame before it terminates. Inform the according camera object that
// its image acquisition thread got an error. We have chosen this complicated procedure to avoid to run a local message
// pump to allow both, waiting for the terminating thread and dispatching incoming windows messages.
LRESULT CMainFrame::OnError(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
CCamera* pCamera = (CCamera*) lParam;
if ( pCamera != NULL && m_CameraManager.IsDeviceValid(pCamera) )
{
try
{
pCamera->OnContinuousGrabError(wParam);
} CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
static BOOL bNew = TRUE; // initially visible
bNew = !bNew;
::SendMessage(m_hWndToolBar, RB_SHOWBAND, 1, bNew); // toolbar is band #1
UISetCheck(ID_VIEW_TOOLBAR, bNew);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bNew = !::IsWindowVisible(m_hWndStatusBar);
::ShowWindow(m_hWndStatusBar, bNew ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_STATUS_BAR, bNew);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewBusView(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL visible;
if( visible = ::IsWindowVisible(m_BusView) )
m_Dock.HideWindow(m_BusView);
else
m_Dock.DockWindow(m_BusView, DOCK_LASTKNOWN);
UISetCheck(ID_VIEW_BUSVIEW, ! visible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if ( m_CameraManager.GetCurrentDevice() != NULL )
{
try
{
assert( m_pPropertyDlg == NULL);
m_pPropertyDlg = new CPropertyDlg( *m_CameraManager.GetCurrentDevice());
m_fPropertyPageVisible = true;
m_pPropertyDlg->DoModal();
m_fPropertyPageVisible = false;
delete m_pPropertyDlg;
m_pPropertyDlg = NULL;
}
CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnViewZoom(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
try
{
CChildFrame* pChildFrame = m_CameraManager.GetCurrentChild();
if ( pChildFrame != NULL )
{
double zoom = 1.0;
switch ( wID )
{
case ID_VIEW_ZOOM_25:
zoom = 0.25;
break;
case ID_VIEW_ZOOM_50:
zoom = 0.5;
break;
case ID_VIEW_ZOOM_100:
zoom = 1.0;
break;
case ID_VIEW_ZOOM_200:
zoom = 2.0;
break;
case ID_VIEW_ZOOM_400:
zoom = 4.0;
break;
case ID_VIEW_ZOOM_USER:
{
CZoomDlg dlg;
zoom = pChildFrame->m_View.GetZoomLevel();
dlg.SetFactor(zoom);
if ( dlg.DoModal() == IDOK )
{
zoom = dlg.GetFactor();
}
if ( zoom < 1.0 / 32.0 )
{
zoom = 1.0 / 32.0;
MessageBeep(0);
}
else if ( zoom > 32 )
{
MessageBeep(0);
zoom = 32;
}
}
break;
default:
assert(false);
}
pChildFrame->m_View.SetZoomLevel(zoom);
pChildFrame->m_View.ZoomIn(NULL, 0);
}
} CATCH_REPORT();
return 0;
}
LRESULT CMainFrame::OnViewZoomBest(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CChildFrame* pChildFrame = m_CameraManager.GetCurrentChild();
if ( pChildFrame != NULL )
{
try
{
pChildFrame->m_View.ZoomToFit();
} CATCH_REPORT();
}
return 0;
}
LRESULT CMainFrame::OnViewConversion(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CCamera *pCamera = m_CameraManager.GetCurrentDevice();
if ( pCamera != NULL && (pCamera->GetColorCode() == DCSColor_Mono8 || pCamera->GetColorCode() == DCSColor_Raw8) )
{
try
{
pCamera->SetBayerToRGBConversion(wID - ID_VIEW_NO_CONVERSION);
} CATCH_REPORT();
}
return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -