📄 test1300dlg.cpp
字号:
// test1300Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "test1300.h"
#include "test1300Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
DWORD WINAPI AcceptThread(LPVOID lpV);
extern "C" {
void yv12_to_rgb24_mmx(unsigned char *dst,
int dst_stride,
unsigned char *y_src,
unsigned char *u_src,
unsigned char *v_src,
int y_stride, int uv_stride,
int width, int height);
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest1300Dlg dialog
CTest1300Dlg::CTest1300Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest1300Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest1300Dlg)
m_Address = _T("");
m_Port = 0;
m_cfgchn = 0;
m_cfgport = 0;
m_cfgquality = 0;
m_cfgip = _T("");
m_cfggateway = _T("");
m_cfgnetmask = _T("");
//}}AFX_DATA_INIT
memset( biOut, 0, sizeof(BITMAPINFO)+256);
memset( biIn, 0, sizeof(BITMAPINFO)+256);
m_lpbiIn = (PBITMAPINFOHEADER)&biIn;
m_lpbiOut = (PBITMAPINFOHEADER)&biOut;
m_hAcceptThread = NULL;
m_hIC = NULL;
lpDD = NULL; // DirectDraw object
lpDDSPrimary = NULL; // DirectDraw primary surface
lpDDSOne = NULL; // Offscreen surface 1
lpClipper = NULL; // clipper for primary
m_bShowUpdated = TRUE;
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest1300Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest1300Dlg)
DDX_Control(pDX, IDC_CONNECT, m_Connect);
DDX_Control(pDX, IDC_SHOW_BOX, m_ShowBox);
DDX_Text(pDX, IDC_ADDRESS, m_Address);
DDX_Text(pDX, IDC_PORT, m_Port);
DDX_Text(pDX, IDC_CFG_CHN, m_cfgchn);
DDX_Text(pDX, IDC_CFG_PORT, m_cfgport);
DDX_Text(pDX, IDC_CFG_QUALITY, m_cfgquality);
DDX_Text(pDX, IDC_CFG_ADDRESS, m_cfgip);
DDX_Text(pDX, IDC_CFG_GATEWAY, m_cfggateway);
DDX_Text(pDX, IDC_CFG_NETMASK, m_cfgnetmask);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest1300Dlg, CDialog)
//{{AFX_MSG_MAP(CTest1300Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_BN_CLICKED(IDC_CONFIG, OnConfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest1300Dlg message handlers
BOOL CTest1300Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_Address = CString("192.168.15.223");
m_Port = 3358;
m_cfgip = CString("192.168.15.221");
m_cfgport = 3357;
m_cfggateway=CString("192.168.15.1");
m_cfgnetmask=CString("255.255.255.0");
m_cfgchn = 0;
m_cfgquality=5;
UpdateData(FALSE);
// (1) initial Decompress
m_lpbiIn->biSize = sizeof(BITMAPINFOHEADER);
m_lpbiIn->biWidth = DEFAULT_WIDTH;
m_lpbiIn->biHeight = DEFAULT_HEIGHT;
m_lpbiIn->biCompression = mmioStringToFOURCC("XFM4", 0);
m_lpbiIn->biBitCount = 16;
m_lpbiIn->biSizeImage = m_lpbiIn->biWidth*m_lpbiIn->biHeight*4+2048;
m_lpbiIn->biPlanes = 1;
m_lpbiIn->biXPelsPerMeter = 0;
m_lpbiIn->biYPelsPerMeter = 0;
m_lpbiIn->biClrImportant = 0;
m_lpbiIn->biClrUsed = 0;
m_hIC = ICOpen(mmioStringToFOURCC("VIDC", 0), m_lpbiIn->biCompression, ICMODE_FASTDECOMPRESS );
if ( m_hIC==NULL ) {
TRACE0("ICOpen return error\n");
return FALSE;
}
//Get Decompress OutPut Format
int nOutSize;
int ret;
nOutSize = ICDecompressGetFormatSize(m_hIC, m_lpbiIn);
m_lpbiOut->biSize = nOutSize;
m_lpbiOut->biWidth = m_lpbiIn->biWidth;
m_lpbiOut->biHeight = m_lpbiIn->biHeight;
m_lpbiOut->biCompression = BI_RGB; // default display format
m_lpbiOut->biBitCount = 24;
m_lpbiOut->biSizeImage = m_lpbiOut->biWidth*m_lpbiOut->biHeight*3+2048;
m_lpbiOut->biPlanes = 1;
m_lpbiOut->biXPelsPerMeter = 0;
m_lpbiOut->biYPelsPerMeter = 0;
m_lpbiOut->biClrImportant = 0;
m_lpbiOut->biClrUsed = 0;
ret = ICDecompressQuery(m_hIC, m_lpbiIn, m_lpbiOut);
if ( ret!=ICERR_OK ) {
ICClose ( m_hIC );
m_hIC = NULL;
TRACE0("Decompress Format Error\n");
return FALSE;
}
if ( ICDecompressBegin(m_hIC , m_lpbiIn, m_lpbiOut) != ICERR_OK) {
ICClose ( m_hIC );
m_hIC = NULL;
TRACE0("DecompressBegin Error\n");
return FALSE;
}
// (2) initial DirectDraw
if ( CreateDirectDraw(m_ShowBox.m_hWnd, m_lpbiOut)==FALSE ) {
ICClose ( m_hIC );
m_hIC = NULL;
TRACE0("CreateDirectDraw Error\n");
return FALSE;
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest1300Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTest1300Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTest1300Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CTest1300Dlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_Socket.Close();
int i=0;
while ( m_hAcceptThread!=NULL && i++<300 ) {
Sleep(10);
}
DestroyDirectDraw();
if ( m_hIC!=NULL ) {
ICDecompressEnd(m_hIC);
ICClose(m_hIC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -