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

📄 bcamviewer.cpp

📁 BCAM 1394 Driver
💻 CPP
字号:
//-----------------------------------------------------------------------------
//  (c) 2002 by Basler Vision Technologies
//  Section:  Vision Components
//  Project:  BCAM
//  $Header: BCAMViewer.cpp, 10, 13.12.2002 13:12:50, Happe, A.$
//-----------------------------------------------------------------------------
/**
  \file     BCAMViewer.cpp
 *
 * \brief Main source file for BCAM Viewer.exe
 *
 */
//-----------------------------------------------------------------------------


#include "stdafx.h"
#include "resource.h"

#include "MainFrm.h"
#include "ParseCmd.h"

using namespace Bcam;

CAppModule _Module;

void Usage()
{
  CString msg;
  msg += "Usage:\n";
  msg += "\tBcamViewer\n";
  msg += "\tBcamViewer /restore camera\n";
  msg += "\tBcamViewer /restore layout\n";
  msg += "\tBcamViewer /restore all   (default)\n";
  msg += "\tBcamViewer /restore none\n";
  MessageBox(NULL, msg, "Help", MB_OK );
}


int Run(LPTSTR lpstrCmdLine = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
  bool fRestoreWindowLayout = true;
  bool fRestoreCameraSettings = true;

  if ( lpstrCmdLine != NULL )
  {
    // parse command line 
    CCmdLineParser cp((LPCTSTR) CString(lpstrCmdLine).MakeLower());
    if ( cp.isParameter("/?") || cp.isParameter("-?") )
    {
      Usage();
      return 0;
    }

    if ( cp.isParameter(RESTORE_SWITCH) )
    {
      std::string restoreArg = cp.getArgument(RESTORE_SWITCH);
      if ( restoreArg != RESTORE_ALL_ARG && restoreArg != RESTORE_SETTINGS_ARG 
        && restoreArg != RESTORE_LAYOUT_ARG && restoreArg != RESTORE_NONE_ARG )
      {
        // invalid argument for paramter RESTORE_SWITCH
        Usage();
        return 0;
      }
      fRestoreCameraSettings = restoreArg == RESTORE_SETTINGS_ARG || restoreArg == RESTORE_ALL_ARG;
      fRestoreWindowLayout = restoreArg == RESTORE_LAYOUT_ARG || restoreArg == RESTORE_ALL_ARG;
    }
    else if ( ! cp.isEmpty() ) // no other parameter supported 
    {
      Usage();
      return 0;
    }
  }

  // First check, if another instance of our application is already running
  // To do this check a named kernel object is created 
  // If the creation fails we know that our application is already running
  HANDLE hExclusion = NULL;   // used to detect another running instance
  hExclusion = CreateMutex(NULL, FALSE, "{7D351A30-B95B-11d5-9255-0090278E5E96}");

  if ( GetLastError() == ERROR_ALREADY_EXISTS )
  {
    // The mutex already exists, bring the running instance to top

    HWND hWndPrev, hWndChild;

    // Determine if another window with your class name exists...
    if (hWndPrev = ::FindWindow("BcamViewer",NULL))
    {
      // If so, does it have any popups?
      hWndChild = ::GetLastActivePopup(hWndPrev);

      // If iconic, restore the main window
      if (::IsIconic(hWndPrev))
        ::ShowWindow(hWndPrev, SW_RESTORE);

      // Bring the main window or its popup to
      // the foreground
      ::SetForegroundWindow(hWndChild);

      // now the previous instance is activated 
      return 0;
    }
  } 


    CMessageLoop theLoop;
    _Module.AddMessageLoop(&theLoop);

    CMainFrame wndMain(fRestoreCameraSettings, fRestoreWindowLayout );

    if(wndMain.CreateEx() == NULL )
    {
      ATLTRACE(_T("Main window creation failed!\n"));
      if ( hExclusion != NULL )
        CloseHandle(hExclusion);

      return 0;
    }

    int nRet;

theloop:
    try
    {
      wndMain.ShowWindow(nCmdShow );
      nRet = theLoop.Run();
    }
    catch ( BcamException& e )
    {
      CString description = "Unhandled Bcam exception.\n";
      if ( e.Context() != "" )
        description += e.Context() + CString(" : ") + e.Description();
      else
        description += e.Description();
      CString errorCode;
      errorCode.Format("Error code: 0x%08x \n", e.Error() );
      if ( MessageBox( NULL, errorCode + description + "Continue?", "Error", MB_OKCANCEL | MB_ICONINFORMATION ) == IDOK )
        goto theloop;
    }
    catch ( ... )
    {
      if ( MessageBox(NULL, "Unknown exception occured.\nContinue?", "Error", MB_OKCANCEL | MB_ICONINFORMATION ) == IDOK )
        goto theloop;
    }


    _Module.RemoveMessageLoop();
    if ( hExclusion != NULL )
      CloseHandle(hExclusion);
    return nRet;
  }

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
  HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//  HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

  int nRet = Run(lpstrCmdLine, nCmdShow);

  _Module.Term();
  ::CoUninitialize();

  return nRet;
}

⌨️ 快捷键说明

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