⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo_vcdlg.cpp

📁 实现和通讯屏的通讯
💻 CPP
字号:
// Demo_VCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Demo_VC.h"
#include "Demo_VCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDemo_VCDlg dialog

CDemo_VCDlg::CDemo_VCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDemo_VCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDemo_VCDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDemo_VCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDemo_VCDlg)
	DDX_Control(pDX, IDC_PICT, m_Pict);
	DDX_Control(pDX, IDC_CL2005OCXCTRL1, m_CL2005);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDemo_VCDlg, CDialog)
	//{{AFX_MSG_MAP(CDemo_VCDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemo_VCDlg message handlers

BOOL CDemo_VCDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CDemo_VCDlg::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 CDemo_VCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void	CDemo_VCDlg::PictToBuff(CDC *dc, LineType *PictBuf,
						WORD PictWidth, WORD PictHeight,
						WORD Width,WORD Height,
						BYTE Color)
{
int		x,y,z,EndX,EndY,vC;
WORD	v,vx;
WORD	_ROLE[]={0x8000,0x4000,0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,
				 0x0080,0x0040,0x0020,0x0010,0x0008,0x0004,0x0002,0x0001};

	// 先清除缓冲区
	for (x=0;x<128;++x)
		for (y=0;y<511;++y) PictBuf[y][x] = 0;

	// 根据图片和屏体的宽高决定截取图片的宽高,保证数据不越界
	if (PictWidth>Width)   EndX=Width;  else EndX=PictWidth;
	if (PictHeight>Height) EndY=Height; else EndY=PictHeight;

	// 遍历高度和宽度
    // 先截取红色
	for (y=0;y<EndY;++y)
		for (x=0;x<(EndX+15)/16;++x)
		{
			v=0;
			for (z=0;z<16;++z)
			{
				vC = dc->GetPixel(x*16+z,y);
				if ((vC & RGB(0xff,0,0))>RGB(0x80,0,0)) v |= _ROLE[z];
			}
			vx = (v>>8) + ((v&0xff)<<8);
			PictBuf[y][x] = vx;
		}
    // 双色屏再截取绿色
	if (Color!=0)
	{
		for (y=0;y<EndY;++y)
			for (x=0;x<(EndX+15)/16;++x)
			{
				v=0;
				for (z=0;z<16;++z)
				{
					vC = dc->GetPixel(x*16+z,y);
					if ((vC & RGB(0,0xff,0))>RGB(0,0x80,0)) v |= _ROLE[z];
				}
				vx = (v>>8) + ((v&0xff)<<8);
				PictBuf[y+Height][x] = vx;
			}
	}
}

#define		LedType         2       // 控制卡类型,1-4
#define		LedNum          0       // 控制卡编号,由控制卡上的跳线设定
#define		LedWidth        384     // 屏体宽度,由CL2005节目管理系统设定
#define		LedHeight       128     // 屏体高度,由CL2005节目管理系统设定
#define		LedColor        1       // 颜色, 0:单色,1:双色, 由CL2005节目管理系统设定

#define		ComPort         1       // 串行口
#define		ComBaudRate     38400   // 通讯速率,由控制卡跳线设定
#define		ComDelay        1000    // 等待应答的延时,由通讯质量及速率和数据包大小决定
									//      一般至少取800以上

void CDemo_VCDlg::OnButton1() 
{
LineType	SendBuf[511];
RECT		rect;
BOOL		bOK;
ProgType	ProgBuff[10];

	m_Pict.GetWindowRect(&rect);
	PictToBuff(m_Pict.GetDC(),SendBuf,rect.right-rect.left,rect.bottom-rect.top,LedWidth,LedHeight,LedColor);
	if (!m_CL2005.ComInitial(ComPort,ComBaudRate,ComDelay))
		MessageBox("初始化串口失败","显示图片",MB_OK);
	else
	{
		bOK = m_CL2005.SetLEDProperty(LedType,LedNum,LedWidth,LedHeight,LedColor,1);
		if (bOK) bOK=m_CL2005.SendPicture(0,(long)SendBuf);
		if (bOK)
		{
            ProgBuff[0].PictIndex   = 0;   // 图片0的播放属性
            ProgBuff[0].Enter       = 3;   // 进入方式2
            ProgBuff[0].Leave       = 0;   // 退出方式
            ProgBuff[0].Speed       = 10;  // 进入速度
            ProgBuff[0].StayTime    = 5;   // 停留时间
            ProgBuff[0].bFollowPlay = 0;   // 非紧随模式
            ProgBuff[0].bShowTimer  = 0;   // 非整页时钟项
            ProgBuff[0].TimerMode   = 0;   // 不显示日期时间
            ProgBuff[0].bTimerPlay  = 0;   // 非定时播放项
			bOK = m_CL2005.SendProgList(1,(long)ProgBuff);
		}
		m_CL2005.CloseCL2005();
		if (bOK) MessageBox("发送成功","发送图片",MB_OK);
        else	 MessageBox("发送失败","发送图片",MB_OK);
	}
}

void CDemo_VCDlg::OnButton2() 
{
char	str[256];
BOOL	bOK;
	strcpy(str,"`01红`02绿`03黄");	
    bOK = m_CL2005.ComInitial(ComPort,ComBaudRate,ComDelay);
    if (!bOK) MessageBox("串口初始化失败","显示文字",MB_OK);
    else
    {
        bOK = m_CL2005.SetLEDProperty(LedType,LedNum,LedWidth,LedHeight,LedColor,1);
		if (bOK) bOK = m_CL2005.SwitchToBank(0);
		if (bOK) bOK = m_CL2005.ShowString(1,LedWidth-3*16,0,0,(long)str);
		if (bOK) bOK = m_CL2005.SwitchToBank(1);
        m_CL2005.CloseCL2005();
        if (bOK) MessageBox("发送成功","显示文字",MB_OK);
        else	 MessageBox("发送失败","显示文字",MB_OK);
	}
}

void CDemo_VCDlg::OnButton3() 
{
BOOL	bOK;
    bOK = m_CL2005.ComInitial(ComPort,ComBaudRate,ComDelay);
    if (!bOK) MessageBox("串口初始化失败","复位控制卡",MB_OK);
    else
    {
        bOK = m_CL2005.SetLEDProperty(LedType,LedNum,LedWidth,LedHeight,LedColor,1);
        if (bOK) bOK=m_CL2005.Reset();
        m_CL2005.CloseCL2005();
        if (bOK) MessageBox("发送成功","复位控制卡",MB_OK);
        else	 MessageBox("发送失败","复位控制卡",MB_OK);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -