effectchang.cpp
来自「一个通过PCI卡向LED屏发送股票实时行情的系统」· C++ 代码 · 共 1,278 行 · 第 1/3 页
CPP
1,278 行
// EffectChang.cpp : implementation file
//
#include "stdafx.h"
#include "sjshq.h"
#include "EffectChang.h"
#include <windowsx.h>//???????????????????????????????/
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEffectChang
CEffectChang::CEffectChang()
{
}
CEffectChang::~CEffectChang()
{
}
BEGIN_MESSAGE_MAP(CEffectChang, CWnd)
//{{AFX_MSG_MAP(CEffectChang)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEffectChang message handlers
//通过HBITMAP句柄装载显示BMP //(x,y,dw,dh)目标屏幕的左上角坐标,位图文件名,动画模式,显示模式
BOOL CEffectChang::Open_DrawBmp(CWnd* pWnd,CDC *pDC,
int dx, int dy, int dw, int dh,
CString fName,int DisplayMode,int DrawMode,
int sx, int sy, int sw, int sh)
{
char p1[80];
BITMAPFILEHEADER fileh; //定义一个文件标题结构
LPBITMAPINFOHEADER fileh1; //定义一个信息标题结构
CFile FileBmp;
CBitmap* pOldMap;
CDC pMenDC; //定义一个设备描述表
int i,dw1,dh1,maxread;
short int bytes_per_line;
unsigned char* BmpChar;
long bmpsize;
maxread=64*512;
BOOL YN=FileBmp.Open(fName,CFile::typeBinary|CFile::modeRead|CFile::shareDenyNone);
if(YN==0) //如果文件打开错误,给出出错信息
{
strcpy(p1,"位图文件");
strcpy(p1,fName);
strcat(p1,"不存在");
// AfxMessageBox(p1);
return 0;
}
//以下读入位图的文件标题
FileBmp.Read((unsigned char *)&fileh,sizeof(fileh));
if(fileh.bfType!=19778) //判断是否是一个位图文件,19778是"BM"的数值
{
//如果不是一个位图文件,加入提示信息,关闭文件退出
FileBmp.Close();
strcpy(p1,"文件");
strcat(p1,fName);
strcat(p1,"不是一个位图文件");
AfxMessageBox(p1);
return 0;
}
bmpsize=fileh.bfSize-sizeof(BITMAPFILEHEADER);
bmpdata=GlobalAllocPtr(GHND,bmpsize);
if(bmpdata==0)
return 0;
BmpChar=new unsigned char[maxread];
if(BmpChar==NULL)
{
GlobalFreePtr(bmpdata);
return 0;
}
unsigned char *data=(unsigned char *)bmpdata;
int chunksize;
while(bmpsize)
{
if(bmpsize>maxread)
chunksize=maxread;
else
chunksize=bmpsize;
FileBmp.Read(BmpChar,chunksize);
for(i=0;i<chunksize;i++)
data[i]=BmpChar[i];
bmpsize-=chunksize;
data+=chunksize;
}
fileh1=(LPBITMAPINFOHEADER)bmpdata;
bytes_per_line=((long)fileh1->biWidth*(long)fileh1->biBitCount+31L)/32*4;
if(fileh1->biSize==12)
return 0;
if(fileh1->biClrUsed!=0)
nPalate=fileh1->biClrUsed;
else
{
switch(fileh1->biBitCount)
{
case 1:
nPalate=2;
break;
case 4:
nPalate=16;
break;
case 8:
nPalate=256;
break;
case 24:
nPalate=0;
break;
default:
nPalate=2;
break;
}
}
bhm_ddb=0;
if(fileh1!=NULL)
{
if(hpal==0&&nPalate>0)//如果调色板颜色数量大于0
{
make_palette();
}
if(bhm_ddb==0)
DIBtoDDB(pDC->GetSafeHdc());
}
if(DrawMode==1) //原样大小显示
{
dw1=fileh1->biWidth;
dh1=fileh1->biHeight;
}
else if(DrawMode==2)//按参数给定的区域显示,纵横伸缩比例一样
{
float bl1=(float)dw/fileh1->biWidth;
float bl2=(float)dh/fileh1->biHeight;
if(bl1>bl2)
{
dh1=dh;
dw1=(int)(bl2*dw);
}
else
{
dw1=dw;
dh1=(int)(bl1*dh);
}
}
else if(DrawMode==3) //严格按参数给定的区域显示
{
dw1=dw;
dh1=dh;
}
if(bhm_ddb!=0)
{
///////////////////////////////////////////////StretchBlt tempMem
/* CDC tempMem;
CBitmap m_bmp;
tempMem.CreateCompatibleDC(pDC);
pOldMap=tempMem.SelectObject(CBitmap::FromHandle(bhm_ddb));
pMenDC.CreateCompatibleDC(pDC);
m_bmp.CreateCompatibleBitmap(pDC,dw,dh);
pMenDC.SelectObject(&m_bmp);
pMenDC.FillSolidRect(CRect(0,0,dw,dh),RGB(0,0,0));
pMenDC.StretchBlt( 0,0,dw,dh,&tempMem,0,0,sw,sh,SRCCOPY);*/
//////////////////////////////////////////////StretchBlt tempMem
pMenDC.CreateCompatibleDC(pDC);
pOldMap=pMenDC.SelectObject(CBitmap::FromHandle(bhm_ddb));
if(DisplayMode==0) //str一屏打出
OnePage_Displaystr(pDC,&pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==1) //一屏打出
OnePage_Display(pDC,&pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else
DynamicShow_Interface(pWnd,DisplayMode,pDC,&pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
/////////////////////////////////////////////StretchBlt tempMem
/* tempMem.SelectObject(pOldMap);
m_bmp.DeleteObject();
tempMem.DeleteDC();*/
////////////////////////////////////////////StretchBlt tempMem
pMenDC.DeleteDC();
}
delete BmpChar; //释放字符串空间
GlobalFreePtr(bmpdata);
if(bhm_ddb!=0)
DeleteBitmap(bhm_ddb);
FileBmp.Close(); //关闭文件
return 1;
}
void CEffectChang::DIBtoDDB(HDC hdc)
{
LPBITMAPINFOHEADER p_bminfo=(LPBITMAPINFOHEADER)(bmpdata);
if(p_bminfo==0)
return;
if(bhm_ddb!=0)
DeleteBitmap(bhm_ddb);
LPSTR p_image=(LPSTR)p_bminfo+sizeof(BITMAPINFOHEADER)+nPalate*sizeof(RGBQUAD);
HPALETTE hpalold=NULL;
if(hpal)
{
hpalold=SelectPalette(hdc,hpal,FALSE);
RealizePalette(hdc);
}
bhm_ddb=CreateDIBitmap(hdc,p_bminfo,CBM_INIT,p_image,(LPBITMAPINFO)p_bminfo,DIB_RGB_COLORS);
if(hpalold)
SelectPalette(hdc,hpalold,FALSE);
}
void CEffectChang::make_palette()
{
LPBITMAPINFOHEADER p_bminfo=(LPBITMAPINFOHEADER)bmpdata;
if(hpal!=0)DeletePalette(hpal);
if(nPalate>0)
{
LPLOGPALETTE cp=(LPLOGPALETTE)GlobalAllocPtr(GHND,sizeof(LOGPALETTE)+nPalate*sizeof(PALETTEENTRY));
if(cp!=NULL)
{
cp->palVersion=0x0300;
cp->palNumEntries=nPalate; //设置调色板入口
LPBITMAPINFO p_bi=(LPBITMAPINFO)p_bminfo;
for(int i=0;i<nPalate;i++) //将调色板信息装入RGBQUAD结构,注意颜色的顺序变化
{
cp->palPalEntry[i].peRed=p_bi->bmiColors[i].rgbRed;
cp->palPalEntry[i].peGreen=p_bi->bmiColors[i].rgbGreen;
cp->palPalEntry[i].peBlue=p_bi->bmiColors[i].rgbBlue;
}
hpal=CreatePalette(cp); //创建逻辑调色板
GlobalFreePtr(cp);
}
}
}
void CEffectChang::DynamicShow_Interface(CWnd* pWnd,int DisplayMode,CDC *pDC, CDC *pMenDC,int dx, int dy, int dw, int dh,int sx,int sy,int sw,int sh)
{
if(DisplayMode==2) MoveEffect2(pWnd,pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==3) MoveEffect3(pWnd,pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==4) MoveEffect4(pWnd,pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==5) MoveEffect5(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==6) MoveEffect6(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==7) MoveEffect7(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==8) MoveEffect8(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==9) ThreadEffect1(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==10) ThreadEffect2(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==11) StretchEffect1(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==12) StretchEffect2(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==13) StretchEffect3(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==14) SpreadEffect1(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==15) SpreadEffect2(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==16) SpreadEffect3(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==17) SpreadEffect4(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==18) SpreadEffect5(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==19) ShowEffect1(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==20) ShowEffect2(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==21) ShowEffect3(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==22) ShowEffect4(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==23) ShowEffect5(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==24) WindowsEffect1(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else if(DisplayMode==25) WindowsEffect2(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
// else if(DisplayMode==xx) TurnEffect(/*pWnd,*/pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
else
OnePage_Display(pDC,pMenDC,dx,dy,dw,dh,sx,sy,sw,sh);
}
//显示TXT文件一屏打出
//(dx,dy,dw,dh)目标屏幕的坐标,位图文件名,动画模式,宋体字号,源屏幕的坐标
BOOL CEffectChang::Open_DrawTxt(CWnd* pWnd,CDC *pDC,
int dx, int dy, int dw, int dh,
CString fName,int DisplayMode,CFont* mTxtFnt)
{
CString Txtstr;
int nLineSpace=0; //行间距
CStdioFile TxtFile;
if (!TxtFile.Open(fName,CFile::modeRead|CFile::typeText|CFile::shareDenyNone))
return 0;
//新的内存
CFont* m_FntOld;
CDC* pMemDC;
CBitmap m_bmp;
CBitmap* pOldbmp;
LOGFONT lp;
pMemDC=new CDC;
pMemDC->CreateCompatibleDC(pDC);
m_bmp.CreateCompatibleBitmap(pDC,dw,dh);
pOldbmp=pMemDC->SelectObject(&m_bmp);
pMemDC->FillSolidRect(CRect(0,0,dw,dh),RGB(0,0,0));
pMemDC->SetBkColor(RGB(0,0,0));
pMemDC->SetTextColor(RGB(255,0,0));
m_FntOld=pMemDC->SelectObject(mTxtFnt);
mTxtFnt->GetLogFont(&lp);
CSize strSize;
TCHAR SingleChar;
int nLineCount=0;
BOOL bchine;
while(TxtFile.ReadString(Txtstr))
{
Txtstr.TrimRight();
if(!Txtstr.IsEmpty())
{
CString WantStr,CurStr=Txtstr;
int Chine_count=0;
int CurLen=Txtstr.GetLength();
//分解一行文本
do
{
for(int count=0;count<CurLen;count++)
{
SingleChar=CurStr.GetAt(count);
if(SingleChar&0x80)
{
Chine_count++; //一行中,中文字符计数
bchine=TRUE;
}
else
bchine=FALSE;
strSize=pMemDC->GetTextExtent(CurStr.Left(count+1));
if(strSize.cx>1024)
{
if(Chine_count%2)//奇数,有中文字符被拆开
count--;
break;
}
}
WantStr=CurStr.Left(count);
//输出一行满宽文本
if(nLineCount*(nLineSpace+lp.lfHeight)<=dh-nLineSpace-lp.lfHeight)
{
pMemDC->TextOut(dx,nLineCount*(nLineSpace+lp.lfHeight),WantStr);//190
pDC->BitBlt(dx,dy,dw,dh,pMemDC,0,0,SRCCOPY);
}
else
{
// DynamicShow_Interface(pWnd,2,pDC,pMemDC,dx,dy,dw,dh,0,0,0,0);
Sleep(theApp.TxtPauseTime*1000);
pMemDC->FillSolidRect(CRect(0,0,dw,dh),RGB(0,0,0));
pMemDC->TextOut(dx,0,WantStr);
nLineCount=0;
pDC->BitBlt(dx,dy,dw,dh,pMemDC,0,0,SRCCOPY);
}
if(bchine)
CurStr=CurStr.Right(CurLen-count+1);
else
CurStr=CurStr.Right(CurLen-count);
if(count==1) CurStr="";
CurLen=CurStr.GetLength();
Chine_count=0;
nLineCount++;
}while(CurStr!="");
}
}
TxtFile.Close();
//收拾设备描述表
pMemDC->SelectObject(m_FntOld);
pMemDC->SelectObject(pOldbmp);
m_bmp.DeleteObject();
pMemDC->DeleteDC();
delete pMemDC;
return 1;
}
BOOL CEffectChang::Open_DrawTxt0812(CWnd* pWnd,CDC *pDC,int dx, int dy, int dw, int dh,
CString fName,CFont* mTxtFnt,CFont* mTitleFnt)
{
CStdioFile TxtFile;
if (!TxtFile.Open(fName,CFile::modeRead|CFile::typeText|CFile::shareDenyNone))
return 0;
pDC->FillSolidRect(CRect(0,0,1024,704),RGB(0,0,0));
CString Txtstr,titlest;
int nLineSpace=4; //行间距
//新的内存
CFont* m_FntOld;
CDC* pMemDC;
CBitmap m_bmp;
CBitmap* pOldbmp;
LOGFONT lp;
int nLineWidth=0;
pMemDC=new CDC;
pMemDC->CreateCompatibleDC(pDC);
m_bmp.CreateCompatibleBitmap(pDC,dw,dh);
pOldbmp=pMemDC->SelectObject(&m_bmp);
pMemDC->FillSolidRect(CRect(0,0,dw,dh),RGB(0,0,0));
pMemDC->SetBkColor(RGB(0,0,0));
pMemDC->SetTextColor(RGB(255,0,0));
//显示标题//////////////////////////////////
TxtFile.ReadString(titlest);
pDC->SelectObject(mTitleFnt);
CSize strSize=pDC->GetTextExtent(titlest);
pDC->TextOut((1024-strSize.cx)/2,50,titlest);
/////////////////////////////////////////////
m_FntOld=pMemDC->SelectObject(mTxtFnt);
mTxtFnt->GetLogFont(&lp);
TCHAR SingleChar;
int nLineCount=0;
BOOL bchine;
while(TxtFile.ReadString(Txtstr))
{
Txtstr.TrimRight();
if(!Txtstr.IsEmpty())
{
CString WantStr,CurStr=Txtstr;
int Chine_count=0;
int CurLen=Txtstr.GetLength();
//分解一行文本
do
{
for(int count=0;count<CurLen;count++)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?