📄 vscapview.cpp
字号:
// RenderSoft CamStudio
//
// Copyright 2001 RenderSoft Software & Web Publishing
// 2002 Iwasaki Teruyuki converted string text
//
//
// vscapView.cpp : implementation of the CVscapView class
//
#include "stdafx.h"
#include "vscap.h"
#include "vscapDoc.h"
#include "vscapView.h"
#include "hook/hook.h"
#include "hookkey/hookkey.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 "AudioFormat.h"
#include "Keyshortcuts.h"
#include "MainFrm.h"
#include <stdio.h>
#include "fister/soundfile.h"
//#include "htmlhelp.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);
void SetTitleBar(CString title); // Ver 1.1
//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;
int recordpaused=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);
static UINT WM_USER_KEYSTART = ::RegisterWindowMessage(WM_USER_KEYSTART_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=240;
//Video Options and Compressions
//int timelapse=40;
//int frames_per_second = 25;
//int keyFramesEvery = 25;
int timelapse=5;
int frames_per_second = 200;
int keyFramesEvery = 200;
int compquality = 7000;
DWORD compfccHandler = 0;
ICINFO * compressor_info = NULL;
int num_compressor =0;
int selected_compressor = -1;
//Ver 1.2
//Video Compress Parameters
LPVOID pVideoCompressParams = NULL;
DWORD CompressorStateIsFor = 0;
DWORD CompressorStateSize = 0;
void FreeVideoCompressParams();
BOOL AllocVideoCompressParams(DWORD paramsSize);
void GetVideoCompressState (HIC hic, DWORD fccHandler);
void SetVideoCompressState (HIC hic , DWORD fccHandler);
LPVOID pParamsUse = NULL;
void FreeParamsUse();
BOOL MakeCompressParamsCopy(DWORD paramsSize, LPVOID pOrg);
// Resources I dont sure if it should be localized
#define L_CAMSTUDIO "CamStudio"
#define L_AVI_MOVIE "AVI Movie"
#define L_MS_VIDEO_1 "MS Video 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(L_MS_VIDEO_1);
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;
// Ver 1.1
// ===========================================================================
// Audio Functions and Variables
// ===========================================================================
// The program records video and sound separately, into 2 files
// ~temp.avi and ~temp.wav, before merging these 2 file into a single avi file
// using the Merge_Video_And_Sound_File function
// ===========================================================================
//Path to temporary wav file
CString tempaudiopath;
int recordaudio=0;
//Audio Recording Variables
UINT AudioDeviceID = WAVE_MAPPER;
HWAVEIN m_hRecord;
WAVEFORMATEX m_Format;
DWORD m_ThreadID;
int m_QueuedBuffers=0;
int m_BufferSize = 1000; // number of samples
CSoundFile *m_pFile = NULL;
//Audio Options Dialog
LPWAVEFORMATEX pwfx = NULL;
DWORD cbwfx;
//Audio Formats Dialog
DWORD waveinselected = WAVE_FORMAT_2S16;
int audio_bits_per_sample = 16;
int audio_num_channels = 2;
int audio_samples_per_seconds = 22050 ;
BOOL bAudioCompression = TRUE;
#define MILLISECONDS 0
#define FRAMES 1
BOOL interleaveFrames = TRUE;
int interleaveFactor = 100;
int interleaveUnit = MILLISECONDS;
CString getString(UINT nID);
void generalErrorMsg(UINT nIDMsg, UINT nIDTitle = ID_TITLE_MSGBOX_NOTE, UINT uType = MB_OK | MB_ICONEXCLAMATION);
BOOL StartAudioRecording(WAVEFORMATEX* format);
void waveInErrorMsg(MMRESULT result, UINT nID);
int AddInputBufferToQueue();
void SetBufferSize(int NumberOfSamples);
void CALLBACK OnMM_WIM_DATA(UINT parm1, LONG parm2);
void DataFromSoundIn(CBuffer* buffer) ;
void StopAudioRecording();
BOOL InitAudioRecording();
void ClearAudioFile();
void GetTempWavePath();
void BuildRecordingFormat();
void SuggestCompressFormat();
void SuggestRecordingFormat();
void AllocCompressFormat();
// Video/Audio Merging Functions and Definitions
#define NUMSTREAMS 2
int Merge_Video_And_Sound_File(CString input_video_path, CString input_audio_path, CString output_avi_path, BOOL recompress_audio, LPWAVEFORMATEX audio_recompress_format, DWORD audio_format_size, BOOL bInterleave, int interleave_factor,int interleave_unit);
BOOL WinYield(void);
BOOL CALLBACK SaveCallback(int iProgress);
// ===========================================================================
//ver 1.2
// ===========================================================================
//Key short-cuts variables
// ===========================================================================
UINT keyRecordStart = VK_F8;
UINT keyRecordEnd = VK_F9;
UINT keyRecordCancel = VK_ESCAPE;
//state vars
BOOL AllowNewRecordStartKey=TRUE;
int doneOnce=0;
int savesettings=1;
extern int viewtype;
//Enhanced video options
int g_autoadjust=1;
//int g_valueadjust=32;
int g_valueadjust=1;
//Functions that select audio options based on settings read
void AttemptRecordingFormat();
void AttemptCompressFormat();
//Link to customized icon info
extern DWORD icon_info[];
//Cursor Path, used for copying cursor file
CString g_cursorFilePath;
//Tray Icon
#define WM_TRAY_ICON_NOTIFY_MESSAGE (WM_USER + 50)
NOTIFYICONDATA IconData;
BOOL bTrayIconVisible = FALSE;
BOOL DefaultMenuItem = 0;
BOOL bMinimizeToTray = TRUE;
UINT nDefaultMenuItem;
CMenu TrayMenu;
void initTrayIconData();
void finishTrayIconData();
void TraySetIcon(HICON hIcon);
void TraySetIcon(UINT nResourceID);
void TraySetIcon(LPCTSTR lpszResourceName);
void TraySetToolTip(LPCTSTR lpszToolTip);
void TraySetMinimizeToTray(BOOL bMinimizeToTray = TRUE);
BOOL TraySetMenu(UINT nResourceID,UINT nDefaultPos=0);
BOOL TraySetMenu(HMENU hMenu,UINT nDefaultPos=0);
BOOL TraySetMenu(LPCTSTR lpszMenuName,UINT nDefaultPos=0);
BOOL TrayUpdate();
BOOL TrayShow();
BOOL TrayHide();
void OnTrayLButtonDown(CPoint pt);
void OnTrayLButtonDblClk(CPoint pt);
void OnTrayRButtonDown(CPoint pt);
void OnTrayRButtonDblClk(CPoint pt);
void OnTrayMouseMove(CPoint pt);
//ver 1.3
int threadPriority = THREAD_PRIORITY_NORMAL;
CString GetCodecDescription(long fccHandler);
void AutoSetRate(int val,int& framerate,int& delayms);
#if !defined(WAVE_FORMAT_MPEGLAYER3)
#define WAVE_FORMAT_MPEGLAYER3 0x0055
#endif
//ver 1.5
int captureleft=100;
int capturetop=100;
int fixedcapture=0;
/////////////////////////////////////////////////////////////////////////////
// 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)
ON_COMMAND(ID_PAUSE, OnPause)
ON_UPDATE_COMMAND_UI(ID_PAUSE, OnUpdatePause)
ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop)
ON_COMMAND(ID_OPTIONS_RECORDAUDIO, OnOptionsRecordaudio)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_RECORDAUDIO, OnUpdateOptionsRecordaudio)
ON_COMMAND(ID_OPTIONS_AUDIOFORMAT, OnOptionsAudioformat)
ON_COMMAND(ID_HELP_FAQ, OnHelpFaq)
ON_COMMAND(ID_OPTIONS_KEYBOARDSHORTCUTS, OnOptionsKeyboardshortcuts)
ON_COMMAND(ID_OPTIONS_PROGRAMOPTIONS_SAVESETTINGSONEXIT, OnOptionsProgramoptionsSavesettingsonexit)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_PROGRAMOPTIONS_SAVESETTINGSONEXIT, OnUpdateOptionsProgramoptionsSavesettingsonexit)
ON_COMMAND(ID_OPTIONS_RECORDINGTHREADPRIORITY_NORMAL, OnOptionsRecordingthreadpriorityNormal)
ON_COMMAND(ID_OPTIONS_RECORDINGTHREADPRIORITY_HIGHEST, OnOptionsRecordingthreadpriorityHighest)
ON_COMMAND(ID_OPTIONS_RECORDINGTHREADPRIORITY_ABOVENORMAL, OnOptionsRecordingthreadpriorityAbovenormal)
ON_COMMAND(ID_OPTIONS_RECORDINGTHREADPRIORITY_TIMECRITICAL, OnOptionsRecordingthreadpriorityTimecritical)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_RECORDINGTHREADPRIORITY_TIMECRITICAL, OnUpdateOptionsRecordingthreadpriorityTimecritical)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_RECORDINGTHREADPRIORITY_NORMAL, OnUpdateOptionsRecordingthreadpriorityNormal)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_RECORDINGTHREADPRIORITY_HIGHEST, OnUpdateOptionsRecordingthreadpriorityHighest)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_RECORDINGTHREADPRIORITY_ABOVENORMAL, OnUpdateOptionsRecordingthreadpriorityAbovenormal)
//}}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)
ON_REGISTERED_MESSAGE (WM_USER_KEYSTART, OnKeyStart)
ON_MESSAGE(MM_WIM_DATA, OnMM_WIM_DATA)
ON_MESSAGE(WM_TRAY_ICON_NOTIFY_MESSAGE,OnTrayNotify)
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()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -