📄 teleoperationdlg.cpp
字号:
// TeleoperationDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IRExpPlatform.h"
#include "IRExpPlatformDlg.h"
#include "TeleoperationDlg.h"
#include "VideoConfigureDlg.h"
#include "global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTeleoperationDlg dialog
CTeleoperationDlg::CTeleoperationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTeleoperationDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTeleoperationDlg)
m_CarState = _T("");
//}}AFX_DATA_INIT
}
void CTeleoperationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTeleoperationDlg)
DDX_Text(pDX, IDC_EDITCARSTATE, m_CarState);
DDV_MaxChars(pDX, m_CarState, 20);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTeleoperationDlg, CDialog)
//{{AFX_MSG_MAP(CTeleoperationDlg)
ON_BN_CLICKED(IDC_TELECLOSE, OnTeleclose)
//ON_BN_CLICKED(IDC_BACKTOWELOMEDLG, OnBacktowelomedlg)
ON_BN_CLICKED(IDC_TELEFRONT, OnTelefront)
ON_BN_CLICKED(IDC_TELEBACK, OnTeleback)
ON_BN_CLICKED(IDC_TELELEFT, OnTeleleft)
ON_BN_CLICKED(IDC_TELERIGHT, OnTeleright)
ON_BN_CLICKED(IDC_TELESTOP, OnTelestop)
ON_BN_CLICKED(IDC_CONFIGVIDEOINOPERATIONDLG, OnConfigvideoinoperationdlg)
ON_BN_CLICKED(IDC_CLOSECOLVIDEO, OnClosecolvideo)
ON_BN_CLICKED(IDC_OPENCOLVIDEO, OnOpencolvideo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTeleoperationDlg message handlers
void CTeleoperationDlg::OnTeleclose()
{
// TODO: Add your control notification handler code here
capDriverDisconnect(m_hCaptureInTeleDlg);
StopCar();
CDialog::OnCancel();
}
/*
void CTeleoperationDlg::OnBacktowelomedlg()
{
// TODO: Add your control notification handler code here
capDriverDisconnect(m_hCaptureInTeleDlg);
StopCar();
CDialog::OnCancel();
// AfxGetMainWnd()->ShowWindow(SW_SHOW);
}
*/
BOOL CTeleoperationDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_CarState="停止"; //初始化小车状态
UpdateData(false);
//以下八行初始化对应控件的使能状态
GetDlgItem(IDC_OPENCOLVIDEO)->EnableWindow(TRUE);
GetDlgItem(IDC_CLOSECOLVIDEO)->EnableWindow(FALSE);
GetDlgItem(IDC_TELEFRONT)->EnableWindow(FALSE);
GetDlgItem(IDC_TELEBACK)->EnableWindow(FALSE);
GetDlgItem(IDC_TELELEFT)->EnableWindow(FALSE);
GetDlgItem(IDC_TELERIGHT)->EnableWindow(FALSE);
GetDlgItem(IDC_TELESTOP)->EnableWindow(FALSE);
GetDlgItem(IDC_CONFIGVIDEOINOPERATIONDLG) -> EnableWindow(FALSE);
theApp.bColor = TRUE; //显示彩色视频
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CTeleoperationDlg::PreTranslateMessage(MSG* pMsg)
//Nonzero if the message was translated and should not be dispatched;
//zero if the message was not translated and should be dispatched
{
// TODO: Add your specialized code here and/or call the base class
if(WM_KEYFIRST<=pMsg->message&&pMsg->message<=WM_KEYLAST)
{ //为键盘按键
switch(pMsg->wParam)
{
case VK_SPACE:
CTeleoperationDlg::OnTelestop(); //小车启停对应空格键
break;
case VK_LEFT:
CTeleoperationDlg::OnTeleleft(); //小车左转对应左方向键
break;
case VK_RIGHT:
CTeleoperationDlg::OnTeleright(); //小车右转对应右方向键
break;
case VK_UP:
CTeleoperationDlg::OnTelefront(); //小车前进对应上方向键
break;
case VK_DOWN:
CTeleoperationDlg::OnTeleback(); //小车后退对应下方向键
break;
default:
break;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CTeleoperationDlg::OnTelefront()
{
// TODO: Add your control notification handler code here
theApp.nMotiontype=FORWARD;
Motion();
m_CarState="前进"; //小车状态为前进
UpdateData(FALSE);
}
void CTeleoperationDlg::OnTeleback()
{
// TODO: Add your control notification handler code here
theApp.nMotiontype=BACK;
Motion();
m_CarState="后退"; //小车状态为后退
UpdateData(FALSE);
}
void CTeleoperationDlg::OnTeleleft()
{
// TODO: Add your control notification handler code here
theApp.nMotiontype=TURNLEFT;
Motion();
m_CarState="左转"; //小车状态为左转
UpdateData(FALSE);
}
void CTeleoperationDlg::OnTeleright()
{
// TODO: Add your control notification handler code here
theApp.nMotiontype=TURNRIGHT;
Motion();
m_CarState="右转"; //小车状态为右转
UpdateData(false);
}
void CTeleoperationDlg::OnTelestop()
{
// TODO: Add your control notification handler code here
theApp.nMotiontype=STOP;
Motion();
m_CarState="停止"; //小车状态为停止
UpdateData(false);
}
void CTeleoperationDlg::OnConfigvideoinoperationdlg()
{
// TODO: Add your control notification handler code here
CVideoConfigureDlg VideoConfigureDlg;
VideoConfigureDlg.DoModal();
}
void CTeleoperationDlg::OnClosecolvideo()
{
// TODO: Add your control notification handler code here
capDriverDisconnect(m_hCaptureInTeleDlg); //关闭视频
//以下八行初始化对应控件的使能状态
GetDlgItem(IDC_OPENCOLVIDEO)->EnableWindow(TRUE);
GetDlgItem(IDC_CLOSECOLVIDEO)->EnableWindow(FALSE);
GetDlgItem(IDC_TELEFRONT)->EnableWindow(FALSE);
GetDlgItem(IDC_TELEBACK)->EnableWindow(FALSE);
GetDlgItem(IDC_TELELEFT)->EnableWindow(FALSE);
GetDlgItem(IDC_TELERIGHT)->EnableWindow(FALSE);
GetDlgItem(IDC_TELESTOP)->EnableWindow(FALSE);
GetDlgItem(IDC_CONFIGVIDEOINOPERATIONDLG)->EnableWindow(FALSE);
m_CarState="停止"; //小车状态为停止
UpdateData(FALSE);
}
HWND CTeleoperationDlg::IniVideo(HWND m_hwn)
{
HWND m_hTempCapture;
CWnd *pWnd=GetDlgItem(IDC_VIDEOINTELEDLG); //取得原始图像显示对应的Picture控件指针
CRect videoRect;
CRect windowRect;
long xoffset;
long yoffset;
int hTitle;
//让视频窗口正好覆盖原始图像显示对应的Picture控件
//GetWindowRect()求取的坐标是相对于显示器左上角而言的
pWnd->GetWindowRect(&videoRect); //取得原始图像显示对应的Picture控件矩形
GetWindowRect(&windowRect); //取得整个对话框矩形
xoffset=videoRect.TopLeft().x -windowRect.TopLeft().x;
yoffset=videoRect.TopLeft().y -windowRect.TopLeft().y;
hTitle =::GetSystemMetrics(SM_CYSIZE); //求取标题栏高度
m_hTempCapture = capCreateCaptureWindow ("CapWindow", WS_EX_CONTROLPARENT
| WS_CHILD | WS_VISIBLE, xoffset-3, yoffset-hTitle-2, videoRect.Width(),
videoRect.Height(), this->m_hWnd, 0);
//-2,-3是为了微调窗口左上角坐标,因为视频窗口显示时可能存在2-3格象素的误差
ASSERT(m_hTempCapture );
CAPDRIVERCAPS capDrvCaps; // CAPDRIVERCAPS结构体定义了驱动器的性能
//判断采集窗口是否与0号捕获卡驱动程序相连接
//这里采用简化的方法,因只有一块捕获卡,计算机自动登记号码通常是为0
if (capDriverConnect(m_hTempCapture , 0))
{
//作默认值初始化,并得到驱动器的性能,存入CAPDRIVERCAPS结构中
capDriverGetCaps(m_hTempCapture , &capDrvCaps, sizeof(CAPDRIVERCAPS));
//如果初始化成功
if (capDrvCaps.fCaptureInitialized)
{
//设置预视帧频
capPreviewRate(m_hTempCapture , 2 * 1000 / RATE);
//设置成预视模式(preview),该方式是通过内存作
//为缓冲区来存放视频数据,它是获得视频数据的必要条件.
//另一种称为Overlay模式,它是不经过内存而直接将
//数据传入显存中。它不符合我们要求.
//但preview模式很消耗CPU资源,从而减少系统的整体响应时间
capPreview(m_hTempCapture , TRUE);
//设置每帧结束后所调用的回调函数(默认为彩色视频)
capSetCallbackOnFrame(m_hTempCapture , FrameCallbackProc);
}
//如果初始化不成功
else{
//初始化不成功的消息框显示
AfxMessageBox("捕获卡初始化失败");
//发送WM_CLOSE消息,关闭对话框
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
}
//连接不成功
else{
//连接不成功的消息框显示
AfxMessageBox("捕获卡连接失败");
//发送WM_CLOSE消息,关闭对话框
this->PostMessage(WM_CLOSE);
}
return m_hTempCapture;
}
void CTeleoperationDlg::OnOpencolvideo()
{
// TODO: Add your control notification handler code here
m_hCaptureInTeleDlg=IniVideo(this->m_hWnd);//视频初始化
if (capDriverConnect(m_hCaptureInTeleDlg, 0)) //判断视频是否打开
{ //如果视频打开
GetDlgItem(IDC_OPENCOLVIDEO)->EnableWindow(FALSE);
GetDlgItem(IDC_CLOSECOLVIDEO)->EnableWindow(TRUE);
GetDlgItem(IDC_CONFIGVIDEOINOPERATIONDLG) -> EnableWindow(TRUE);
GetDlgItem(IDC_TELEFRONT)->EnableWindow(TRUE);
GetDlgItem(IDC_TELEBACK)->EnableWindow(TRUE);
GetDlgItem(IDC_TELELEFT)->EnableWindow(TRUE);
GetDlgItem(IDC_TELERIGHT)->EnableWindow(TRUE);
GetDlgItem(IDC_TELESTOP)->EnableWindow(TRUE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -