📄 showstreamdlg.cpp
字号:
// ShowStreamDlg.cpp : implementation file
//
#include "stdafx.h"
#include "multicard.h"
#include "ShowStreamDlg.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/*typedef struct tagSTREAMNOTIFYPARAME
{
int iDlgCount;
CShowStreamDlg * pDlgArray;
} STREAMNOTIFYPARAME;*/
#define WIDTH (320)//(160)
#define HEIGHT (240)//(120)修改数据流回调显示的大小 02 10 16 23:29
/////////////////////////////////////////////////////////////////////////////
// CShowStreamDlg dialog
CShowStreamDlg::CShowStreamDlg(CWnd* pParent /*=NULL*/)
: CDialog(CShowStreamDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CShowStreamDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bIs4WayCard = false; //是否是四路实时卡
m_iShowWay=0; //如果是四路实时卡,显示第几路图像
Prsed=FALSE;
counts=0;
//pLastFrame=new BYTE[320*240*3];
}
void CShowStreamDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShowStreamDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShowStreamDlg, CDialog)
//{{AFX_MSG_MAP(CShowStreamDlg)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowStreamDlg message handlers
BOOL CShowStreamDlg::OnInitDialog()
{
//将客户区窗口的大小改为 160 x 120
CDialog::OnInitDialog();
RECT rcFrame, rcClient;
int w, h;
int width, height;
GetWindowRect(&rcFrame);
GetClientRect(&rcClient);
w = (rcFrame.right-rcFrame.left) - (rcClient.right-rcClient.left);
h = (rcFrame.bottom-rcFrame.top) - (rcClient.bottom-rcClient.top);
width =WIDTH + w;//rcClient.right-rcClient.left+
height = HEIGHT + h;///客户区的边框风格与图像框相同rcClient.bottom-rcClient.top+
SetWindowPos(NULL, -1, -1, width, height, SWP_NOZORDER|SWP_NOMOVE);//SWP_NOSIZE|SWP_NOZORDER| SWP_NOACTIVATE|SWP_SHOWWINDOW
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CShowStreamDlg::OnOK()
{
}
void CShowStreamDlg::OnCancel()
{
}
void CShowStreamDlg::ShowStream(const BITMAPINFO * pInfo, const BYTE * pBits)
{
if(!pInfo || !pBits)
return;
HDC hdc = ::GetDC(m_hWnd);
int w = pInfo->bmiHeader.biWidth;
int h = pInfo->bmiHeader.biHeight;
RECT rcClient;
GetClientRect(&rcClient);///获得当前的客户区大小,以适应窗口的拖动
int ww = (rcClient.right-rcClient.left);//2002.11.14 12:21 ^_^
int hh = ww*3/4 ;//(rc.bottom-rc.top)
/*float rt=0;float rt1,rt2;
rt1=ww/320;rt2=hh/240;
rt=(rt1>=rt2)?rt2:rt1;
ww=(int)rt*320;
hh=(int)rt*240;*/
SetStretchBltMode(hdc, COLORONCOLOR);
//不是四路实时卡
if(!m_bIs4WayCard)
{
StretchDIBits(hdc,
0, 0,ww,hh, //WIDTH, HEIGHT,
0, 0, w, h,
pBits, pInfo, DIB_RGB_COLORS, SRCCOPY);
}
//是四路实时卡
else
{
POINT ptS[4] = { {0,h/2}, {w/2,h/2}, {0,0}, {w/2,0} };
StretchDIBits(hdc,
0, 0, WIDTH, HEIGHT,
ptS[m_iShowWay].x, ptS[m_iShowWay].y, w/2, h/2,
pBits, pInfo, DIB_RGB_COLORS, SRCCOPY);
}
::ReleaseDC(m_hWnd, hdc);
}
//设置是否是四路实时卡,
//如果是四路实时卡,设置显示第几路图像
void CShowStreamDlg::SetShowWay(int iCardID, bool bIs4WayCard, int iWay/*=0*/)
{
m_bIs4WayCard = bIs4WayCard;
if(m_bIs4WayCard && iWay>=0 && iWay<=3)
m_iShowWay = iWay;
else
m_iShowWay = 0;
char szCaption[100];
if(m_bIs4WayCard)
sprintf(szCaption, "%d号卡 (路数%d)", iCardID, m_iShowWay);
else
sprintf(szCaption, "%d号卡: 数据流回调显示", iCardID);
SetWindowText(szCaption);
}
void CShowStreamDlg::DisplayGrayImage(const BITMAPINFO *pInfo, const BYTE *pBits)
{
if(!pInfo || !pBits)
return ;
HDC hdc = ::GetDC(m_hWnd);
int w = pInfo->bmiHeader.biWidth;
int h = pInfo->bmiHeader.biHeight;
BYTE *GrayImage=(BYTE *)(new BYTE[w*h*3]);///必须预先分配内存大小
SetStretchBltMode(hdc, COLORONCOLOR);
for (int i=0;i<h;i++)
for(int j=0;j<w;j++)
{
GrayImage[i*3*w+j*3+0]=(const BYTE)(pBits[i*3*w+j*3+0]*0.299+pBits[i*3*w+j*3+1]*0.587+pBits[i*3*w+j*3+2]*0.114);
GrayImage[i*3*w+j*3+1]=GrayImage[i*3*w+j*3+0];
GrayImage[i*3*w+j*3+2]=GrayImage[i*3*w+j*3+0];
}
StretchDIBits(hdc,
0, 0, w, h,///目的区域大小(显示面积)
0, 0, w, h, ///源区域的大小(要显示的原图像中的那一部分)
GrayImage/*plastFrame*/, pInfo, DIB_RGB_COLORS, SRCCOPY);
delete [] GrayImage;///释放内存
::ReleaseDC(m_hWnd, hdc);
}
void CShowStreamDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
RECT rcFrame, rcClient;
GetClientRect(&rcClient);///获得当前的客户区大小,以适应窗口的拖动
int ww = (rcClient.right-rcClient.left);//2002.11.14 12:21 ^_^
int hh = ww*3/4 ;//(rc.bottom-rc.top)
int w1, h1;
int width, height;
GetWindowRect(&rcFrame);
w1 = (rcFrame.right-rcFrame.left) - (rcClient.right-rcClient.left);
h1 = (rcFrame.bottom-rcFrame.top) - (rcClient.bottom-rcClient.top);
width =ww + w1;//rcClient.right-rcClient.left+
height = hh + h1;///客户区的边框风格与图像框相同rcClient.bottom-rcClient.top+
SetWindowPos(NULL, -1, -1, width, height, SWP_NOZORDER|SWP_NOMOVE);
//MessageBox("changed");
// TODO: Add your message handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -