?? demo_vcdlg.cpp
字號(hào):
// 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};
// 先清除緩沖區(qū)
for (x=0;x<128;++x)
for (y=0;y<511;++y) PictBuf[y][x] = 0;
// 根據(jù)圖片和屏體的寬高決定截取圖片的寬高,保證數(shù)據(jù)不越界
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 // 控制卡編號(hào),由控制卡上的跳線設(shè)定
#define LedWidth 384 // 屏體寬度,由CL2005節(jié)目管理系統(tǒng)設(shè)定
#define LedHeight 128 // 屏體高度,由CL2005節(jié)目管理系統(tǒng)設(shè)定
#define LedColor 1 // 顏色, 0:單色,1:雙色, 由CL2005節(jié)目管理系統(tǒng)設(shè)定
#define ComPort 1 // 串行口
#define ComBaudRate 38400 // 通訊速率,由控制卡跳線設(shè)定
#define ComDelay 1000 // 等待應(yīng)答的延時(shí),由通訊質(zhì)量及速率和數(shù)據(jù)包大小決定
// 一般至少取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; // 進(jìn)入方式2
ProgBuff[0].Leave = 0; // 退出方式
ProgBuff[0].Speed = 10; // 進(jìn)入速度
ProgBuff[0].StayTime = 5; // 停留時(shí)間
ProgBuff[0].bFollowPlay = 0; // 非緊隨模式
ProgBuff[0].bShowTimer = 0; // 非整頁(yè)時(shí)鐘項(xiàng)
ProgBuff[0].TimerMode = 0; // 不顯示日期時(shí)間
ProgBuff[0].bTimerPlay = 0; // 非定時(shí)播放項(xiàng)
bOK = m_CL2005.SendProgList(1,(long)ProgBuff);
}
m_CL2005.CloseCL2005();
if (bOK) MessageBox("發(fā)送成功","發(fā)送圖片",MB_OK);
else MessageBox("發(fā)送失敗","發(fā)送圖片",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("發(fā)送成功","顯示文字",MB_OK);
else MessageBox("發(fā)送失敗","顯示文字",MB_OK);
}
}
void CDemo_VCDlg::OnButton3()
{
BOOL bOK;
bOK = m_CL2005.ComInitial(ComPort,ComBaudRate,ComDelay);
if (!bOK) MessageBox("串口初始化失敗","復(fù)位控制卡",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("發(fā)送成功","復(fù)位控制卡",MB_OK);
else MessageBox("發(fā)送失敗","復(fù)位控制卡",MB_OK);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -