📄 vscapview.cpp
字号:
// RenderSoft CamStudio
//
// Copyright 2001 RenderSoft Software & Web Publishing
//
//
// vscapView.cpp : implementation of the CVscapView class
//
#include "stdafx.h"
#include "vscap.h"
#include "vscapDoc.h"
#include "vscapView.h"
#include "hook/hook.h"
#include <windowsx.h>
#include <memory.h>
#include <mmsystem.h>
#include <vfw.h>
#include <setjmp.h>
#include "VideoOptions.h"
#include "CursorOptionsDlg.h"
#include "AutopanSpeed.h"
#include "FixedRegion.h"
#include "FlashingWnd.h"
//#include <stdio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////
//Function prototypes
//////////////////////////////////////
//Region Display Functions
#define SWAP(x,y) ((x)^=(y)^=(x)^=(y))
void DrawSelect(HDC hdc, BOOL fDraw, LPRECT lprClip);
void DrawFlashingRect(BOOL bDraw , int mode);
BOOL isRectEqual(RECT a, RECT b);
void WINAPI NormalizeRect(LPRECT prc);
void FixRectSizePos(LPRECT prc,int maxxScreen, int maxyScreen);
RECT FrameWindow(HWND hWnd);
void WINAPI NormalizeRect(LPRECT prc);
void DrawClientArea(HWND hwnd, HDC hdc);
long rounddouble(double dbl);
//Region Select Functions
long WINAPI MouseCaptureWndProc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam);
int InitDrawShiftWindow();
int InitSelectRegionWindow();
int CreateShiftWindow();
int DestroyShiftWindow();
//Mouse Capture functions
HCURSOR FetchCursorHandle();
HCURSOR hSavedCursor = NULL;
//AVI functions and #defines
#define AVIIF_KEYFRAME 0x00000010L // this frame is a key frame.
#define BUFSIZE 260
#define LPLPBI LPBITMAPINFOHEADER *
#define N_FRAMES 50
#define TEXT_HEIGHT 20
static HANDLE Bitmap2Dib(HBITMAP, UINT);
int RecordVideo(int top,int left,int width,int height,int numframes,const char *szFileName);
UINT RecordAVIThread(LPVOID pParam);
//Use these 2 functions to create frames and free frames
LPBITMAPINFOHEADER captureScreenFrame(int left,int top,int width, int height,int tempDisableRect);
void FreeFrame(LPBITMAPINFOHEADER) ;
//Misc Functions
CString GetTempPath();
CString GetProgPath();
void InsertHighLight(HDC hdc,int xoffset, int yoffset);
///////////////////
//State variables
///////////////////
//Vars used for selecting fixed /variableregion
RECT rcOffset;
RECT rcClip;
RECT rcUse;
RECT old_rcClip;
BOOL bCapturing=FALSE;
POINT ptOrigin;
int maxxScreen;
int maxyScreen;
RECT rc;
HWND hMouseCaptureWnd;
HWND hWnd_FixedRegion;
HBITMAP savedBitmap = NULL;
HBITMAP hLogoBM = NULL;
CFlashingWnd* pFrame = NULL;
//Misc Vars
int recordstate=0;
UINT interruptkey = 0;
int tdata=0;
DWORD initialtime=0;
int initcapture = 0;
int irsmallcount=0;
// Messaging
HWND hWndGlobal = NULL;
static UINT WM_USER_RECORDINTERRUPTED = ::RegisterWindowMessage(WM_USER_RECORDINTERRUPTED_MSG);
static UINT WM_USER_SAVECURSOR = ::RegisterWindowMessage(WM_USER_SAVECURSOR_MSG);
static UINT WM_USER_GENERIC = ::RegisterWindowMessage(WM_USER_GENERIC_MSG);
static UINT WM_USER_RECORDSTART = ::RegisterWindowMessage(WM_USER_RECORDSTART_MSG);
/////////////////////////////////////////////////////////
//Variables/Options requiring interface
/////////////////////////////////////////////////////////
int bits = 24;
int flashingRect=1;
int launchPlayer=1;
int minimizeOnStart=0;
int MouseCaptureMode = 0;
int DefineMode = 0; //set only in FixedRegion.cpp
int capturewidth=320;
int captureheight=200;
//Video Options and Compressions
int timelapse=50;
int frames_per_second = 20;
int keyFramesEvery = 20;
int compquality = 6500;
DWORD compfccHandler = 0;
ICINFO * compressor_info = NULL;
int num_compressor =0;
int selected_compressor = -1;
//Report variables
int nActualFrame=0;
int nCurrFrame=0;
float fRate=0.0;
float fActualRate=0.0;
float fTimeLength=0.0;
int nColors=24;
CString strCodec("Default Compressor");
int actualwidth=0;
int actualheight=0;
//Cursor variables
HCURSOR g_loadcursor = NULL;
HCURSOR g_customcursor = NULL;
int g_customsel = 0;
int g_recordcursor=1;
int g_cursortype=0;
int g_highlightcursor=0;
int g_highlightsize=64;
int g_highlightshape=0;
COLORREF g_highlightcolor = RGB(255,255,125);
//Path to temporary avi file
CString tempfilepath;
//Files Directory
CString savedir("");
CString cursordir("");
//Autopan
int autopan=0;
int maxpan = 20;
RECT panrect_current;
RECT panrect_dest;
/////////////////////////////////////////////////////////////////////////////
// CVscapView
IMPLEMENT_DYNCREATE(CVscapView, CView)
BEGIN_MESSAGE_MAP(CVscapView, CView)
//{{AFX_MSG_MAP(CVscapView)
ON_COMMAND(ID_REGION_RUBBER, OnRegionRubber)
ON_COMMAND(ID_REGION_PANREGION, OnRegionPanregion)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_DESTROY()
ON_COMMAND(ID_RECORD, OnRecord)
ON_COMMAND(ID_STOP, OnStop)
ON_UPDATE_COMMAND_UI(ID_REGION_PANREGION, OnUpdateRegionPanregion)
ON_UPDATE_COMMAND_UI(ID_REGION_RUBBER, OnUpdateRegionRubber)
ON_COMMAND(ID_FILE_VIDEOOPTIONS, OnFileVideooptions)
ON_COMMAND(ID_OPTIONS_CURSOROPTIONS, OnOptionsCursoroptions)
ON_COMMAND(ID_OPTIONS_AUTOPAN, OnOptionsAutopan)
ON_COMMAND(ID_OPTIONS_ATUOPANSPEED, OnOptionsAtuopanspeed)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_AUTOPAN, OnUpdateOptionsAutopan)
ON_UPDATE_COMMAND_UI(ID_RECORD, OnUpdateRecord)
ON_COMMAND(ID_REGION_FULLSCREEN, OnRegionFullscreen)
ON_UPDATE_COMMAND_UI(ID_REGION_FULLSCREEN, OnUpdateRegionFullscreen)
ON_COMMAND(ID_OPTIONS_MINIMIZEONSTART, OnOptionsMinimizeonstart)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_MINIMIZEONSTART, OnUpdateOptionsMinimizeonstart)
ON_COMMAND(ID_OPTIONS_HIDEFLASHING, OnOptionsHideflashing)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_HIDEFLASHING, OnUpdateOptionsHideflashing)
ON_COMMAND(ID_OPTIONS_PROGRAMOPTIONS_PLAYAVI, OnOptionsProgramoptionsPlayavi)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_PROGRAMOPTIONS_PLAYAVI, OnUpdateOptionsProgramoptionsPlayavi)
ON_COMMAND(ID_HELP_WEBSITE, OnHelpWebsite)
ON_COMMAND(ID_HELP_HELP, OnHelpHelp)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_REGISTERED_MESSAGE (WM_USER_RECORDSTART, OnRecordStart)
ON_REGISTERED_MESSAGE (WM_USER_RECORDINTERRUPTED, OnRecordInterrupted)
ON_REGISTERED_MESSAGE (WM_USER_SAVECURSOR, OnSaveCursor)
ON_REGISTERED_MESSAGE (WM_USER_GENERIC, OnUserGeneric)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVscapView construction/destruction
CVscapView::CVscapView()
{
// TODO: add construction code here
}
CVscapView::~CVscapView()
{
}
BOOL CVscapView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CVscapView drawing
void CVscapView::OnDraw(CDC* pDC)
{
CVscapDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CVscapView printing
BOOL CVscapView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CVscapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CVscapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CVscapView diagnostics
#ifdef _DEBUG
void CVscapView::AssertValid() const
{
CView::AssertValid();
}
void CVscapView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CVscapDoc* CVscapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVscapDoc)));
return (CVscapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVscapView message handlers
void CVscapView::OnRegionRubber()
{
MouseCaptureMode=1;
}
void CVscapView::OnRegionPanregion()
{
DefineMode = 0;
CFixedRegion cfrdlg;
cfrdlg.DoModal();
MouseCaptureMode=0;
DefineMode = 0;
}
void CVscapView::OnRegionFullscreen()
{
// TODO: Add your command handler code here
MouseCaptureMode=2;
}
void CVscapView::OnPaint()
{
CPaintDC dc(this); // device context for painting
DrawClientArea(m_hWnd, dc.m_hDC);
// Do not call CView::OnPaint() for painting messages
}
int CVscapView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CreateShiftWindow();
HDC hScreenDC = ::GetDC(NULL);
bits = ::GetDeviceCaps(hScreenDC, BITSPIXEL );
nColors = bits;
::ReleaseDC(NULL,hScreenDC);
compfccHandler = mmioFOURCC('M', 'S', 'V', 'C');
hLogoBM = LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3));
pFrame = new CFlashingWnd;
CRect rect(0, 0, maxxScreen-1, maxyScreen-1);
pFrame->CreateFlashing("Flashing", rect);
return 0;
}
void CVscapView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
DestroyShiftWindow();
if (compressor_info != NULL) {
free(compressor_info);
num_compressor = 0;
}
if (savedBitmap) {
DeleteObject(savedBitmap);
savedBitmap = NULL;
}
if (hLogoBM) {
DeleteObject(hLogoBM);
hLogoBM = NULL;
}
if (pFrame) {
pFrame->DestroyWindow();
delete pFrame;
}
}
LRESULT CVscapView::OnRecordStart (UINT wParam, LONG lParam) {
CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
pStatus->SetPaneText(0,"Press F9 or the Stop Button to stop recording");
if (minimizeOnStart == 1)
AfxGetMainWnd()->ShowWindow(SW_MINIMIZE);
//Check validity of rc and fix it
HDC hScreenDC = ::GetDC(NULL);
maxxScreen = GetDeviceCaps(hScreenDC,HORZRES);
maxyScreen = GetDeviceCaps(hScreenDC,VERTRES);
FixRectSizePos(&rc,maxxScreen, maxyScreen);
::ReleaseDC(NULL,hScreenDC);
InstallMyHook(hWndGlobal,WM_USER_SAVECURSOR);
recordstate=1;
interruptkey = 0;
CWinThread * pThread = AfxBeginThread(RecordAVIThread, &tdata);
return 0;
}
LRESULT CVscapView::OnRecordInterrupted (UINT wParam, LONG lParam) {
//if (recordstate==0) return;
UninstallMyHook(hWndGlobal);
recordstate=0;
//Store the interrupt key in case this function is triggered by a keypress
interruptkey = wParam;
CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
pStatus->SetPaneText(0,"Press the Record Button to start recording");
Invalidate();
//SetFocus();
//BringWindowToTop( );
//BOOL ret = SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
AfxGetMainWnd()->ShowWindow(SW_RESTORE);
return 0;
}
LRESULT CVscapView::OnSaveCursor (UINT wParam, LONG lParam) {
hSavedCursor = (HCURSOR) wParam;
return 0;
}
//This function is called when the avi saving is completed
LRESULT CVscapView::OnUserGeneric (UINT wParam, LONG lParam) {
AfxGetMainWnd()->ShowWindow(SW_RESTORE);
if (interruptkey==VK_ESCAPE) {
//Perform processing for cancel operation
DeleteFile(tempfilepath);
return 0;
}
//Normal thread exit
//Prompt the user for the filename
static char BASED_CODE szFilter[] = "AVI Movie Files (*.avi)|*.avi||";
static char szTitle[]="Open Texture File";
CFileDialog fdlg(FALSE,"*.avi","*.avi",OFN_LONGNAMES,szFilter,this);
fdlg.m_ofn.lpstrTitle=szTitle;
if (savedir=="")
savedir=GetProgPath();
fdlg.m_ofn.lpstrInitialDir = savedir;
CString m_newfile;
CString m_newfileTitle;
if(fdlg.DoModal() == IDOK)
{
m_newfile = fdlg.GetPathName();
m_newfileTitle = fdlg.GetPathName();
m_newfileTitle=m_newfileTitle.Left(m_newfileTitle.ReverseFind('\\'));
savedir = m_newfileTitle;
}
else {
DeleteFile(tempfilepath);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -