📄 capturedlg.cpp
字号:
LeftLine.Detach();
}
LeftLine.DeleteObject();
memDC.DeleteDC();
DrawCaption();
}
void CCaptureDlg::DrawCaption()
{
if(!m_Caption.IsEmpty())
{
CDC* pDC = GetWindowDC();
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(m_CapitonColor);
pDC->SetTextAlign(TA_CENTER);
CRect rect;
GetClientRect(rect);
pDC->SelectObject(&m_CaptionFont);
pDC->TextOut(rect.Width()/2, m_CaptionHeight/3 ,m_Caption);
ReleaseDC(pDC);
}
}
void CCaptureDlg::OnNcMouseMove(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect tempMin,tempMax,tempClose,ClientRect;
CWindowDC WindowDC (this);
CDC memDC;
memDC.CreateCompatibleDC(&WindowDC);
BITMAPINFO bInfo;
CBitmap LeftLine;
int x,y;
GetWindowRect(ClientRect);
tempMin.CopyRect(CRect(m_MinRect.left+ ClientRect.left,ClientRect.top
+m_MinRect.top,m_MinRect.right+m_MinRect.left+ ClientRect.left,
m_MinRect.bottom+m_MinRect.top+ClientRect.top));
tempMax.CopyRect(CRect(m_MaxRect.left+ ClientRect.left,ClientRect.top
+m_MaxRect.top,m_MaxRect.right+m_MaxRect.left+ ClientRect.left,
m_MaxRect.bottom+m_MaxRect.top+ClientRect.top));
tempClose.CopyRect(CRect(m_CloseRect.left+ ClientRect.left,ClientRect.top
+m_CloseRect.top,m_CloseRect.right+m_CloseRect.left+ ClientRect.left,
m_CloseRect.bottom+m_CloseRect.top+ClientRect.top));
if(tempMin.PtInRect(point)) //鼠标在最小化按钮上移动时,更改按钮显示的位图
{
if(m_ButtonState != bsMin)
{
LeftLine.LoadBitmap(IDB_MINHOTBT);
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
WindowDC.StretchBlt(m_MinRect.left,m_MinRect.top,m_MinRect.right,
m_MinRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
m_ButtonState = bsMin;
LeftLine.Detach();
}
}
else if(tempMax.PtInRect(point))
{
if(m_ButtonState!=bsMax && m_ButtonState!=bsRes)
{
LeftLine.LoadBitmap(IDB_MAXHOTBT);
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
WindowDC.StretchBlt(m_MaxRect.left,m_MaxRect.top,m_MaxRect.right,
m_MaxRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
if (m_IsMax)
{
m_ButtonState = bsMax;
}
else
{
m_ButtonState = bsRes;
}
LeftLine.Detach();
}
}
else if(tempClose.PtInRect(point))
{
if(m_ButtonState != bsClose)
{
LeftLine.LoadBitmap(IDB_CLOSEHOTBT);
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
WindowDC.StretchBlt(m_CloseRect.left,m_CloseRect.top,m_CloseRect.right,
m_CloseRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
m_ButtonState = bsClose;
LeftLine.Detach();
}
}
else
{
if(m_IsDrawForm == FALSE)
{
if(m_ButtonState == bsMin)
DrawDialog( FMINBUTTON);
else if(m_ButtonState == bsClose)
DrawDialog( FCLOSEBUTTON);
else if(m_ButtonState == bsMax || m_ButtonState==bsRes)
DrawDialog( FMAXBUTTON);
}
m_ButtonState = bsNone;
}
LeftLine.DeleteObject();
ReleaseDC(&memDC);
CDialog::OnNcMouseMove(nHitTest, point);
}
void CCaptureDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_ButtonState != bsNone)
{
if(m_ButtonState == bsMin)
DrawDialog(FMINBUTTON);
else if(m_ButtonState == bsClose)
DrawDialog(FCLOSEBUTTON);
else if(m_ButtonState==bsMax || m_ButtonState==bsRes)
DrawDialog(FMAXBUTTON);
m_ButtonState = bsNone;
}
CDialog::OnMouseMove(nFlags, point);
}
void CCaptureDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
switch(m_ButtonState)
{
case bsClose: //关闭窗口
{
OnCancel();
}
break;
case bsMin:
{
ShowWindow(SW_SHOWMINIMIZED);
}
break;
case bsMax:
{
m_ButtonState = bsMax;
ShowWindow(SW_SHOWMAXIMIZED);
m_IsMax = FALSE;
}
break;
case bsRes:
{
ShowWindow(SW_RESTORE);
m_IsMax = TRUE;
}
break;
}
CDialog::OnNcLButtonDown(nHitTest, point);
}
BOOL CCaptureDlg::OnNcActivate(BOOL bActive)
{
// TODO: Add your message handler code here and/or call default
OnPaint() ;
return CDialog::OnNcActivate(bActive);
}
void CCaptureDlg::MoveCapture(UINT num)
{
VARIANT vt;
SAFEARRAY* pSafe;
SAFEARRAYBOUND band;
band.cElements = m_Len;
band.lLbound = 0;
pSafe = SafeArrayCreate(VT_UI1,1,&band);
for(long i=0;i<m_Len;i++)
{
SafeArrayPutElement(pSafe,&i,(void*)&m_pData[num][i]);
}
vt.vt = VT_ARRAY |VT_UI1;
vt.parray = pSafe;
m_Com.SetOutput((COleVariant)vt);
}
//向上移动
void CCaptureDlg::OnUp()
{
MoveCapture(0);
}
//停止移动
void CCaptureDlg::OnReset()
{
MoveCapture(12);
}
//向下移动
void CCaptureDlg::OnDown()
{
MoveCapture(1);
}
//向左移动
void CCaptureDlg::OnLeft()
{
MoveCapture(2);
}
//向右移动
void CCaptureDlg::OnRight()
{
MoveCapture(3);
}
//增加聚焦
void CCaptureDlg::OnInFoci()
{
MoveCapture(5);
}
//减小聚焦
void CCaptureDlg::OnReFoci()
{
MoveCapture(4);
}
//对焦增
void CCaptureDlg::OnInLen()
{
MoveCapture(7);
}
//对焦减
void CCaptureDlg::OnReLen()
{
MoveCapture(6);
}
//光圈减
void CCaptureDlg::OnReAperture()
{
MoveCapture(8);
}
//光圈增
void CCaptureDlg::OnInAperture()
{
MoveCapture(9);
}
//雨刷减
void CCaptureDlg::OnReBrush()
{
MoveCapture(10);
}
//雨刷增
void CCaptureDlg::OnInBrush()
{
MoveCapture(11);
}
void CCaptureDlg::OnControl()
{
// TODO: Add your control notification handler code here
CControlForm dlg;
dlg.m_UserName = m_UserName;
dlg.m_LogPath = m_LogPath;
dlg.DoModal();
Invalidate();
}
DWORD WINAPI ThreadProc(LPVOID lpParameter )
{
CCaptureDlg* pDlg = (CCaptureDlg*)lpParameter;
while (true)
{
switch(pDlg->m_Num)
{
case 0:
//向上
pDlg->MoveCapture(0);
Sleep(2000);
//向左
pDlg->MoveCapture(2);
Sleep(22000);
//向下
pDlg->MoveCapture(1);
Sleep(2000);
//向右
pDlg->MoveCapture(3);
Sleep(22000);
//向下
pDlg->MoveCapture(1);
Sleep(2000);
//向左
pDlg->MoveCapture(2);
Sleep(22000);
//向上
pDlg->MoveCapture(0);
Sleep(2000);
//向右
pDlg->MoveCapture(3);
Sleep(22000);
break;
case 1:
//向左
pDlg->MoveCapture(2);
Sleep(22000);
//向右
pDlg->MoveCapture(3);
Sleep(22000);
break;
case 2:
//向上
pDlg->MoveCapture(0);
Sleep(2000);
//向下
pDlg->MoveCapture(1);
Sleep(2000);
break;
}
}
return 0;
}
void CCaptureDlg::OnAutomatism()
{
// TODO: Add your control notification handler code here
CAutodlg dlg;
dlg.m_UserName = m_UserName;
dlg.m_LogPath = m_LogPath;
if(dlg.DoModal()==IDOK)
{
DWORD threadID;
m_hThread = ::CreateThread(NULL,0,ThreadProc,(LPVOID)this,0,&threadID);
m_Num = dlg.m_Num;
m_Time = dlg.m_Time;
if(m_Time)
{
m_StopTime = dlg.stoptime;
}
}
Invalidate();
}
void CCaptureDlg::OnStop()
{
// TODO: Add your control notification handler code here
//停止运动
MoveCapture(12);
::TerminateThread(m_hThread,0);
//停止监控
VCAStopVideoCapture(0);
}
void CCaptureDlg::OnKinescope()
{
// TODO: Add your control notification handler code here
if(!m_Kinescope)
{
if(CPreView::m_CurIndex != -1)
{
CFileDialog fDlg(FALSE,"avi","avi_001",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"AVI|*.avi",this);
if (fDlg.DoModal()==IDOK)
{
m_Kinescope = TRUE;
CString file = fDlg.GetPathName();
VCASetKeyFrmInterval(CPreView::m_CurIndex,250);
VCASetBitRate(CPreView::m_CurIndex,256);
VCASetVidCapFrameRate(CPreView::m_CurIndex,25);
VCASetVidCapSize(CPreView::m_CurIndex,320,240);
VCASetXVIDQuality(CPreView::m_CurIndex,10,3);
VCASetXVIDCompressMode(CPreView::m_CurIndex,XVID_VBR_MODE);
BOOL ret = VCAStartVideoCapture(CPreView::m_CurIndex,CAP_ORIGIN_MPEG4_STREAM,
MPEG4_AVIFILE_CALLBACK ,file);
GetDlgItem(IDC_KINESCOPE)->SetWindowText("停止录像");
}
}
m_LogTime = CTime::GetCurrentTime();
CString strText;
strText.Format("%s\t%s\t录像\r\n",m_UserName,
m_LogTime.Format("%y-%m-%d %H:%M:%S"));
CFile file;
file.Open(m_LogPath,CFile::modeWrite);
file.SeekToEnd();
file.Write(strText,strText.GetLength());
file.Close();
}
else
{
m_Kinescope = FALSE;
GetDlgItem(IDC_KINESCOPE)->SetWindowText("录像");
VCAStopVideoCapture(CPreView::m_CurIndex);
}
}
void CCaptureDlg::OnPlay()
{
// TODO: Add your control notification handler code here
CPlaydlg dlg;
dlg.m_UserName = m_UserName;
dlg.m_LogPath = m_LogPath;
dlg.DoModal();
Invalidate();
}
void CCaptureDlg::OnManage()
{
// TODO: Add your control notification handler code here
CManagedlg dlg;
dlg.m_UserName = m_UserName;
dlg.m_LogPath = m_LogPath;
dlg.m_PathText = m_PathText;
dlg.DoModal();
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -