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

📄 vscapview.cpp

📁 一个摄像机的程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	
	::SelectObject(hdcBits,oldbrush);



	//OffScreen Buffer
	BitBlt(hdc, 0, 0, rect.right-rect.left+1, rect.bottom-rect.top+1, hdcBits, 0, 0, SRCCOPY);              
	SelectObject(hdcBits, old_bitmap);        
	DeleteObject(hbm);
    DeleteDC(hdcBits);


}

BOOL CVscapView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class	
	BOOL result = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
	
	//Can we put the following line here to get the m_hWnd of this CWnd ? 
	hWndGlobal = m_hWnd;

	return result;

}

void CVscapView::OnRecord() 
{
	// TODO: Add your command handler code here
	CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
	pStatus->SetPaneText(0,"Press F9 or the Stop Button to stop recording");

	nActualFrame=0;
	nCurrFrame=0;
	fRate=0.0;
	fActualRate=0.0;
	fTimeLength=0.0;

	if (MouseCaptureMode==0) {

		rc.top=0;
		rc.left=0;
		rc.right=capturewidth-1;
		rc.bottom=captureheight-1;	

		::ShowWindow(hMouseCaptureWnd,SW_MAXIMIZE);
		::UpdateWindow(hMouseCaptureWnd);

		InitDrawShiftWindow(); //will affect rc implicity

	}
	else if (MouseCaptureMode==1) {

		::ShowWindow(hMouseCaptureWnd,SW_MAXIMIZE);
		::UpdateWindow(hMouseCaptureWnd);

		InitSelectRegionWindow(); //will affect rc implicity

	}
	else if (MouseCaptureMode==2) {

		rcUse.left=0;
		rcUse.top=0;
		rcUse.right= maxxScreen-1;
		rcUse.bottom= maxyScreen-1;
		::PostMessage (hWndGlobal,WM_USER_RECORDSTART,0,(LPARAM) 0); 

	}	
	
}

void CVscapView::OnStop() 
{
	// TODO: Add your command handler code here
	OnRecordInterrupted (0, 0);
	
}



void CVscapView::OnUpdateRegionPanregion(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (MouseCaptureMode==0) pCmdUI->SetCheck(TRUE);
	else pCmdUI->SetCheck(FALSE);
	
}

void CVscapView::OnUpdateRegionRubber(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (MouseCaptureMode==1) pCmdUI->SetCheck(TRUE);
	else pCmdUI->SetCheck(FALSE);
	
}



void CVscapView::OnFileVideooptions() 
{
	//Capture a frame and use it to determine compatitble compressors for user to select
	
	LPBITMAPINFOHEADER first_alpbi = NULL;

	COMPVARS compVars;
	compVars.cbSize = sizeof(COMPVARS);     // validate it
    compVars.dwFlags = 0;	

	int top=0;
	int left=0;
	int width=320;
	int height=200;

    first_alpbi=captureScreenFrame(left,top,width, height,1);		

	num_compressor =0;
	if  (compressor_info == NULL) {
		compressor_info = (ICINFO *) calloc(30,sizeof(ICINFO));
	}
	else {

		free(compressor_info);
		compressor_info = (ICINFO *) calloc(30,sizeof(ICINFO));

	}	

	for(int i=0; ICInfo(ICTYPE_VIDEO, i, &compressor_info[num_compressor]); i++) {


		if (num_compressor>=30) break; //maximum allows 30 compressors		
		
		HIC hic;	

		hic = ICOpen(compressor_info[num_compressor].fccType, compressor_info[num_compressor].fccHandler, ICMODE_QUERY);
		if (hic) {
			
			if   (ICERR_OK==ICCompressQuery(hic, first_alpbi, NULL)) {
						
				ICGetInfo(hic, &compressor_info[num_compressor], sizeof(ICINFO));				
				num_compressor ++ ;				
				
			}
			ICClose(hic);
		}
	}
	
	
	FreeFrame(first_alpbi);

	

	CVideoOptions vod;
	vod.DoModal();
	
	
}

void CVscapView::OnOptionsCursoroptions() 
{
	// TODO: Add your command handler code here
	CCursorOptionsDlg cod;
	cod.DoModal();

	
}


void InsertHighLight(HDC hdc,int xoffset, int yoffset)
{

	CSize fullsize;
	fullsize.cx=128;
	fullsize.cy=128;

	int highlightsize = g_highlightsize;
	COLORREF highlightcolor = g_highlightcolor;
	int highlightshape = g_highlightshape;
		
	double x1,x2,y1,y2;

	//OffScreen Buffer	
	HBITMAP hbm = NULL;
	HBITMAP old_bitmap;
	HDC hdcBits = ::CreateCompatibleDC(hdc);
    hbm = (HBITMAP) ::CreateCompatibleBitmap(hdc,fullsize.cx,fullsize.cy);    	
	old_bitmap = (HBITMAP) ::SelectObject(hdcBits,hbm);		
		
	if ((highlightshape == 0) || (highlightshape == 2)) { //circle and square

		x1 = (fullsize.cx - highlightsize)/2.0;
		x2 = (fullsize.cx + highlightsize)/2.0;
		y1 = (fullsize.cy - highlightsize)/2.0;
		y2 = (fullsize.cy + highlightsize)/2.0;
	}
	else if ((highlightshape == 1) || (highlightshape == 3)) { //ellipse and rectangle

		x1 = (fullsize.cx - highlightsize)/2.0;
		x2 = (fullsize.cx + highlightsize)/2.0;
		y1 = (fullsize.cy - highlightsize/2.0)/2.0;
		y2 = (fullsize.cy + highlightsize/2.0)/2.0;

	}

	HBRUSH ptbrush = (HBRUSH) ::GetStockObject(WHITE_BRUSH);
	HPEN nullpen = CreatePen(PS_NULL,0,0); 
	HBRUSH hlbrush = CreateSolidBrush( highlightcolor);
	
	
	HBRUSH oldbrush = (HBRUSH)  ::SelectObject(hdcBits,ptbrush);	
	HPEN oldpen = (HPEN) ::SelectObject(hdcBits,nullpen);			
	::Rectangle(hdcBits, 0,0,fullsize.cx+1,fullsize.cy+1);		
	


		//Draw the highlight
		::SelectObject(hdcBits,hlbrush);				
		
		if ((highlightshape == 0)  || (highlightshape == 1)) { //circle and ellipse
			::Ellipse(hdcBits,(int) x1,(int) y1,(int) x2,(int) y2);
		}
		else if ((highlightshape == 2) || (highlightshape == 3)) { //square and rectangle
			::Rectangle(hdcBits,(int) x1,(int) y1,(int) x2,(int) y2);
		}
		
		::SelectObject(hdcBits,oldbrush);		

	

	::SelectObject(hdcBits,oldpen);	
	DeleteObject(hlbrush);  	
	DeleteObject(nullpen);		

	//OffScreen Buffer
	BitBlt(hdc, xoffset, yoffset, fullsize.cx, fullsize.cy, hdcBits, 0, 0, SRCAND);  
	SelectObject(hdcBits, old_bitmap);        
	DeleteObject(hbm);
    DeleteDC(hdcBits);

	
}

void CVscapView::OnOptionsAutopan() 
{
	// TODO: Add your command handler code here
	if (autopan==0)
		autopan=1;
	else
		autopan=0;

	
}

void CVscapView::OnOptionsAtuopanspeed() 
{
	// TODO: Add your command handler code here
	CAutopanSpeed aps_dlg;
	aps_dlg.DoModal();
	
}

void CVscapView::OnUpdateOptionsAutopan(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(autopan);
	
}

void CVscapView::OnUpdateRecord(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!recordstate);
	
}

CString GetProgPath()
{
	// locals
	TCHAR    szTemp[300];
	CFile converter;
	CString result;
  
	// get root
	GetModuleFileName( NULL, szTemp, 300 );

	CString path=(CString)szTemp;
	path=path.Left(path.ReverseFind('\\'));
	return path;	

}



void CVscapView::OnUpdateRegionFullscreen(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (MouseCaptureMode==2) pCmdUI->SetCheck(TRUE);
	else pCmdUI->SetCheck(FALSE);
	
	
}

void CVscapView::OnOptionsMinimizeonstart() 
{
	// TODO: Add your command handler code here
	if (minimizeOnStart==0) 
		minimizeOnStart = 1;
	else
		minimizeOnStart = 0;
	
}

void CVscapView::OnUpdateOptionsMinimizeonstart(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(minimizeOnStart);
	
}

void CVscapView::OnOptionsHideflashing() 
{
	// TODO: Add your command handler code here
	if (flashingRect==0)
		flashingRect = 1;
	else
		flashingRect = 0;
	
}

void CVscapView::OnUpdateOptionsHideflashing(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(flashingRect);
	
}

void CVscapView::OnOptionsProgramoptionsPlayavi() 
{
	// TODO: Add your command handler code here
	if (launchPlayer==0)
		launchPlayer = 1;
	else
		launchPlayer = 0;
	
}

void CVscapView::OnUpdateOptionsProgramoptionsPlayavi(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(launchPlayer);
	
}


BOOL CVscapView::Openlink (CString link)
{

  BOOL bSuccess = FALSE;

  //As a last resort try ShellExecuting the URL, may
  //even work on Navigator!
  if (!bSuccess)
    bSuccess = OpenUsingShellExecute (link);

  if (!bSuccess)
    bSuccess = OpenUsingRegisteredClass (link);
  return bSuccess;
}


BOOL CVscapView::OpenUsingShellExecute (CString link)
{
  LPCTSTR mode;
  mode = _T ("open");

  //HINSTANCE hRun = ShellExecute (GetParent ()->GetSafeHwnd (), mode, m_sActualLink, NULL, NULL, SW_SHOW);
  HINSTANCE hRun = ShellExecute (GetSafeHwnd (), mode, link, NULL, NULL, SW_SHOW);
  if ((int) hRun <= HINSTANCE_ERROR)
    {
      TRACE ("Failed to invoke URL using ShellExecute\n");
      return FALSE;
    }
  return TRUE;
}


BOOL CVscapView::
OpenUsingRegisteredClass (CString link)
{
  TCHAR key[MAX_PATH + MAX_PATH];
  HINSTANCE result;

  if (GetRegKey (HKEY_CLASSES_ROOT, _T (".htm"), key) == ERROR_SUCCESS)
    {
      LPCTSTR mode;
      mode = _T ("\\shell\\open\\command");
      _tcscat (key, mode);
      if (GetRegKey (HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS)
        {
          LPTSTR pos;
          pos = _tcsstr (key, _T ("\"%1\""));
          if (pos == NULL)
            {              // No quotes found

              pos = strstr (key, _T ("%1"));   // Check for %1, without quotes

              if (pos == NULL)     // No parameter at all...

                pos = key + _tcslen (key) - 1;
              else
                *pos = _T ('\0');  // Remove the parameter

            }
          else
            *pos = _T ('\0');  // Remove the parameter

          _tcscat (pos, _T (" "));
          _tcscat (pos, link);
          result = (HINSTANCE) WinExec (key, SW_SHOW);
          if ((int) result <= HINSTANCE_ERROR)
            {
              CString str;
              switch ((int) result)
                {
                case 0:
                  str = _T ("The operating system is out\nof memory or resources.");
                  break;
                case SE_ERR_PNF:
                  str = _T ("The specified path was not found.");
                  break;
                case SE_ERR_FNF:
                  str = _T ("The specified file was not found.");
                  break;
                case ERROR_BAD_FORMAT:
                  str = _T ("The .EXE file is invalid\n(non-Win32 .EXE or error in .EXE image).");
                  break;
                case SE_ERR_ACCESSDENIED:
                  str = _T ("The operating system denied\naccess to the specified file.");
                  break;
                case SE_ERR_ASSOCINCOMPLETE:
                  str = _T ("The filename association is\nincomplete or invalid.");
                  break;
                case SE_ERR_DDEBUSY:
                  str = _T ("The DDE transaction could not\nbe completed because other DDE transactions\nwere being processed.");
                  break;
                case SE_ERR_DDEFAIL:
                  str = _T ("The DDE transaction failed.");
                  break;
                case SE_ERR_DDETIMEOUT:
                  str = _T ("The DDE transaction could not\nbe completed because the request timed out.");
                  break;
                case SE_ERR_DLLNOTFOUND:
                  str = _T ("The specified dynamic-link library was not found.");
                  break;
                case SE_ERR_NOASSOC:
                  str = _T ("There is no application associated\nwith the given filename extension.");
                  break;
                case SE_ERR_OOM:
                  str = _T ("There was not enough memory to complete the operation.");
                  break;
                case SE_ERR_SHARE:
                  str = _T ("A sharing violation occurred.");
                  break;
                default:
                  str.Format (_T ("Unknown Error (%d) occurred."), (int) result);
                }
              str = _T ("Unable to open hyperlink:\n\n") + str;
              AfxMessageBox (str, MB_ICONEXCLAMATION | MB_OK);
            }
          else
            return TRUE;
        }
    }
  return FALSE;
}

  

LONG CVscapView::GetRegKey (HKEY key, LPCTSTR subkey, LPTSTR retdata)
{
  HKEY hkey;
  LONG retval = RegOpenKeyEx (key, subkey, 0, KEY_QUERY_VALUE, &hkey);

  if (retval == ERROR_SUCCESS)
    {
      long datasize = MAX_PATH;
      TCHAR data[MAX_PATH];
      RegQueryValue (hkey, NULL, data, &datasize);
      _tcscpy (retdata, data);
      RegCloseKey (hkey);
    }

  return retval;
}

void CVscapView::OnHelpWebsite() 
{
	// TODO: Add your command handler code here
	Openlink("http://www.atomixbuttons.com/vsc");
}

void CVscapView::OnHelpHelp() 
{
	// TODO: Add your command handler code here
	

	CString progdir,helppath;
	progdir=GetProgPath();
	//helppath= progdir + "\\..\\docs\\docs\\help.htm";
	helppath= progdir + "\\help.htm";
	
	Openlink(helppath);
	
}


⌨️ 快捷键说明

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