【澳门新葡亰娱乐官网】孙鑫VC视频教程笔记之第十课“绘图”

1,将CreditStatic.h CreditStatic.cpp文件增多到工程目录下,并加到程序中

1.      画图:

//创建24位bmp区域

2,在对应的对话框中加多变量:CCreditStatic m_static;

CClientDC dc(this);

HBITMAP CreateBitmapSection(HDC hdc,int cx,int cy,BYTE** ppbit)

3,在对应的对话框中加上静态文本,并改进其ID为:IDC_DISPLAY_STATIC

CPen
pen(PS_SOLID,1,RGB(255,0,0));

{

4,在对应的对话框的OnInitDialog函数中增多代码如下:

dc.SelceObject(&pen);

BITMAPINFO bmi ;

m_static.SubclassDlgItem(IDC_DISPLAY_STATIC,this);

dc.SetPixel(point,RGB(255,0,0));
//画点

memset(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));

m_static.SetBkImage(IDB_BITMAP1);

dc.MoveTo();dc.LineTo(); //画线

bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER) ;

m_static.SetCredits(pArrCredit,|);

dc.Rectangle(); //画矩形

bmi.bmiHeader.biPlanes = 1;

m_static.SetSpeed(1);

 

bmi.bmiHeader.biBitCount = 24;

m_static.SetColor(BACKGROUND_COLOR, RGB(0,0,0));

2.      透明画刷:

bmi.bmiHeader.biCompression = BI_RGB;

m_static.SetTransparent();

CBrush
*pBrush=CBrush::FromHandle(GetStockObject(NULL_BRUSH));

bmi.bmiHeader.biWidth = cx;

m_static.StartScrolling();

dc.SelctObject(pBrush);

bmi.bmiHeader.biHeight = cy;

其中::pArrCredit为char*品种,里边放要呈现的字幕,在对应对话框的CDlg中宣示并初步化,如::

 

return
CreateDIBSection(hdc,&bmi,DIB_RGB_COLORS,(void**)ppbit,NULL,0);

char *pArrCredit = { ¸谢谢您||购买本书||

3.      颜色对话框:

}

本书会让您获益良多||本书作者||

COLORREF m_selColor; //注解为类的分子变量

//叠合两张bmp图片并出口到拟定DC,Alpha取值范围
0~255(0为全透明,255为不透明卡塔尔国

BITMAP1^|||

      CColorDialog dlg;

void TransParentPicture(CDC *pDC, HBITMAP hOneBitmap, HBITMAP
hTwoBitmap, CRect ClientRect,int Alpha)

};

      dlg.m_cc.rgbResult=m_selColor;
//将上次筛选的颜料重新载入参数回去

{

[plain]view plaincopyprint?

dlg.m_cc.Flags|=CC_RGBINIT; // CC_RGBINIT Causes the dialog box to use the
color specified in the rgbResult member as the initial color
selection. Or the dialog will use the black color as the initial
color.

BITMAP
OneBitmap;

1.CreditStatic.cpp的代码:

      if(IDOK==dlg.DoModal())

BITMAP
TwoBitmap;

//CreditStatic.cpp:implementationfile

      {

GetObject(hOneBitmap, sizeof(BITMAP), &OneBitmap);

//

           m_selColor=dlg.GetColor(卡塔尔; //得到客户筛选的颜色

GetObject(hTwoBitmap, sizeof(BITMAP), &TwoBitmap);

#includestdafx.h

}

int
nOneImageWidth = OneBitmap.bmWidth;

#includeCreditStatic.h

 

int
nOneImageHeight = OneBitmap.bmHeight;

#ifdef_DEBUG

4.      字体对话框:

int
nTwoImageWidth = TwoBitmap.bmWidth;

#definenewDEBUG_NEW

CFontDialog dlg;

int
nTwoImageHeight = TwoBitmap.bmHeight;

#undefTHIS_FILE

CFont m_font;

if
(nOneImageWidth < nTwoImageWidth)

staticcharTHIS_FILE[]=__FILE__;

      if(IDOK==dlg.DoModal())

{

#endif

      {

nOneImageWidth = nTwoImageWidth;

#defineDISPLAY_TIMER_ID150//timerid

           if(!m_font.m_hObjectState of Qatar //字体是或不是和字体能源相关联了

}  

/////////////////////////////////////////////////////////////////////////////

           {

else

//CCreditStatic

m_font.CreateFontIndirect(dlg.m_cf.lpLogFontState of Qatar; //用选定的字体发轫化一种字体

{

CCreditStatic::CCreditStatic()

           }

nTwoImageWidth = nOneImageWidth;

{

           else

}

m_Colors[0]=RGB(0,0,0);//Black

           {

if
(nOneImageHeight < nTwoImageHeight)

m_Colors[1]=RGB(255,0,0);//Red

                 m_font.DeleteObject();

{

m_Colors[2]=RGB(255,255,0);//Yellow

           }

nOneImageHeight = nTwoImageHeight;

m_Colors[3]=RGB(0,255,255);//Turquoise

           m_strFontName=dlg.m_cf.lpLogFont->lfFaceName;
//获取字体的名字

}

m_Colors[4]=RGB(255,255,255);//White

}

else

m_TextHeights[0]=21;

 

{

m_TextHeights[1]=19;

5.      设置对话框和控件的背景观:

nTwoImageHeight = nOneImageHeight;

m_TextHeights[2]=17;

在对话框中增加WM_CTLCOLO奥迪Q7音讯,在音信响应函数OnCtlColor函数中增进:

}

m_TextHeights[3]=15;

OnCtlColor的函数原型为:OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor),

int
nImageWidth = nOneImageWidth;

m_nCurrentFontHeight=m_TextHeights[NORMAL_TEXT_HEIGHT];

该函数在MSDN中的解释是这么的:The framework calls this member function
when a child control is about to be drawn. Most controls send this
message to their parent (usually a dialog boxState of Qatar to prepare the pDC for
drawing the control using the correct colors.

int
nImageHeight = nOneImageHeight;

m_Escapes[0]=t;

  1. 设置对话框和下边装有控件的背景观:

CDC
MemDC1, MemDC2;

m_Escapes[1]=n;

但五个button按键的颜色没有改过

HBITMAP
hOldBitmap1 = NULL, hOldBitmap2 = NULL;

m_Escapes[2]=r;

HBRUSH m_brush;

BYTE
*pOneBits = NULL;

m_Escapes[3]=^;

m_brush.CreateSolidBrush(RGB(255,0,0));

MemDC1.CreateCompatibleDC(pDC);

m_DisplaySpeed[0]=70;

return m_brush;

MemDC2.CreateCompatibleDC(pDC);

m_DisplaySpeed[1]=40;

  1. 静态框,组框(Group Box)的颜色设置:

HBITMAP
hOneBmp = NULL;

m_DisplaySpeed[2]=10;

if(pWnd->GetDlgCtrID()==IDC_STATIC1)

hOneBmp =
CreateBitmapSection(pDC->m_hDC, nImageWidth, nImageHeight,
&pOneBits);

m_CurrentSpeed=1;

{

hOldBitmap1 = (HBITMAP)SelectObject(MemDC1.m_hDC, hOneBmp);

m_ScrollAmount=-1;

pDC->SetTextColor(兰德路虎极光GB(255,0,0卡塔尔国卡塔尔(قطر‎; //设置字体颜色

hOldBitmap2 = (HBITMAP)SelectObject(MemDC2.m_hDC, hOneBitmap);

m_bProcessingBitmap=FALSE;

pDC->SetBkMode(TRANSPARENTState of Qatar;//设置背景观为透明的

//BitBlt(MemDC1.m_hDC, 0, 0, m_nTwoImage_w, m_nTwoImage_h,
MemDC2.m_hDC, 0, 0, SRCCOPY);

m_ArrIndex=NULL;

}

StretchBlt(MemDC1.m_hDC, 0, 0, nImageWidth, nImageHeight,

m_nCounter=1;

  1. 单行文本框的装置:

MemDC2.m_hDC, 0, 0, OneBitmap.bmWidth, OneBitmap.bmHeight,
SRCCOPY);

m_nClip=0;

if(pWnd->GetDlgCtrID()==IDC_EDIT1)

CDC
MemDC3, MemDC4;

m_bFirstTime=TRUE;

{

HBITMAP
hOldBitmap3 = NULL, hOldBitmap4 = NULL;

m_bDrawText=FALSE;

   pDC->SetTextColor(CRUISERGB(255,0,0卡塔尔卡塔尔; //设置字体颜色

BYTE
*pTwoBits = NULL;

m_bFirstTurn=TRUE;

   pDC->SetBkColor(TiguanGB(255,0,0卡塔尔国State of Qatar;//设置文本框的背景象

MemDC3.CreateCompatibleDC(pDC);

m_Gradient=GRADIENT_NONE;

}

MemDC4.CreateCompatibleDC(pDC);

m_bTransparent=FALSE;

  1. 为静态框设置字体(以下代码):

HBITMAP
hTwoBmp = NULL;

n_MaxWidth=0;

CFont m_font; //放在CDialog的构造函数中

hTwoBmp =
CreateBitmapSection(pDC->m_hDC, nImageWidth, nImageHeight,
&pTwoBits);

TimerOn=0;

m_font.CreatePointFont(200,”华文行楷”State of Qatar;

hOldBitmap3 = (HBITMAP)SelectObject(MemDC3.m_hDC, hTwoBmp);

}

if(pWnd->GetDlgCtrID()==IDC_STATIC1State of Qatar //照旧放在OnCtlColor函数中

hOldBitmap4 = (HBITMAP)SelectObject(MemDC4.m_hDC, hTwoBitmap);

CCreditStatic::~CCreditStatic()

pDC->SelectObject(&m_font);

//BitBlt(MemDC3.m_hDC, 0, 0, m_nTwoImage_w, m_nTwoImage_h,
MemDC4.m_hDC, 0, 0, SRCCOPY);

{

  1. 校正窗口上Button的字体颜色:

StretchBlt(MemDC3.m_hDC, 0, 0, nImageWidth, nImageHeight,

}

Button是自绘制的,所以须要协和创立多少个CButton类,然后在这里类中覆盖DrawItem方法,在该方法中设置对Button的字体颜色的转移,然后对对话框上的开关设置变量,类型选为新建的类。

MemDC4.m_hDC, 0, 0, TwoBitmap.bmWidth, TwoBitmap.bmHeight,
SRCCOPY);

BEGIN_MESSAGE_MAP(CCreditStatic,CStatic)

void CTestBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

CDC
MemDC5;

//{{AFX_MSG_MAP(CCreditStatic)

{

HBITMAP
hOldBitmap5 = NULL;

ON_WM_PAINT()

      // TODO: Add your code to draw the specified item

BYTE*
pNewBits=NULL;

ON_WM_ERASEBKGND()

      UINT uStyle = DFCS_BUTTONPUSH;

MemDC5.CreateCompatibleDC(pDC);

ON_WM_TIMER()

 

HBITMAP
hNewBitmap = NULL;

ON_WM_DESTROY()

   // This code only works with buttons.

hNewBitmap = CreateBitmapSection(pDC->m_hDC, nImageWidth,
nImageHeight, &pNewBits);

//}}AFX_MSG_MAP

   ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);

hOldBitmap5 = (HBITMAP)SelectObject(MemDC5.m_hDC, hNewBitmap);

END_MESSAGE_MAP()

 

int
linebytes=0;

/////////////////////////////////////////////////////////////////////////////

   // If drawing selected, add the pushed style to DrawFrameControl.

int
col=0;

//CCreditStaticmessagehandlers

   if (lpDrawItemStruct->itemState & ODS_SELECTED)

int
line=(((nImageWidth*24)+31)>>5)<<2;

BOOLCCreditStatic::StartScrolling()

      uStyle |= DFCS_PUSHED;

linebytes
= line;

{

 

col =
nImageHeight;

//滚动字符为空,再次回到

   // Draw the button frame.

for(int
j=0;j<col;j++)

if(m_ArrCredit.IsEmpty())

   ::DrawFrameControl(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem,

{

returnFALSE;

      DFC_BUTTON, uStyle);

for(int
i=0;i<linebytes;i++)

if(m_BmpMain.m_hObject!=NULL){

 

{

m_BmpMain.DeleteObject();

   // Get the button’s text.

*(pNewBits + j*line + i)=(*(pOneBits + j*line + i)*Alpha +

m_BmpMain.m_hObject=NULL;

   CString strText;

*(pTwoBits+j*line+i)*(255-Alpha))/255;

}

   GetWindowText(strText);

}

//设置依时期隔

 

}

TimerOn=SetTimer(DISPLAY_TIMER_ID,m_DisplaySpeed[m_CurrentSpeed],NULL);

   // Draw the button text using the text color red.

BitBlt(pDC->m_hDC, 0, 0, ClientRect.Width(),
ClientRect.Height(), MemDC5.m_hDC, 0, 0, SRCCOPY);

ASSERT(TimerOn!=0);

   COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC,
RGB(255,0,0));

//StretchBlt(pDC->m_hDC, 0, 0, m_ClientRect.Width(),
m_ClientRect.Height(),

m_ArrIndex=m_ArrCredit.GetHeadPosition();

   ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),

// MemDC5.m_hDC,
0, 0, m_nOneImage_w, m_nOneImage_h, SRCCOPY);

m_nCounter=1;

      &lpDrawItemStruct->rcItem,
DT_SINGLELINE|DT_VCENTER|DT_CENTER);

SelectObject(MemDC5.m_hDC,hOldBitmap5);

m_nClip=0;

   ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);

MemDC5.DeleteDC();

m_bFirstTime=TRUE;

}

SelectObject(MemDC4.m_hDC,hOldBitmap4);

m_bDrawText=FALSE;

最后将Button的styles去掉Default选项,选中owner draw。

MemDC4.DeleteDC();

returnTRUE;

越来越多Button的作用设置,参看源码中的CButtonST这些类(这几个是国外的三个小编写的)。

SelectObject(MemDC3.m_hDC,hOldBitmap3);

}

 

MemDC3.DeleteDC();

//结束滚动

6.      在窗口上显得二个位图:

SelectObject(MemDC2.m_hDC,hOldBitmap2);

voidCCreditStatic::EndScrolling()

1、成立位图

MemDC2.DeleteDC();

{

CBitmap bitmap;

SelectObject(MemDC1.m_hDC,hOldBitmap1);

//结束依期

bitmap.LoadBitmap(IDB_BITMAP1卡塔尔;
//先创造好位图的能源

MemDC1.DeleteDC();

KillTimer(DISPLAY_TIMER_ID);

2、创制宽容DC

}

TimerOn=0;

CDC dcCompatible;

if(m_BmpMain.m_hObject!=NULL){

dcCompatible.CreateCompatibleDC(pDC);

m_BmpMain.DeleteObject();

3、将位图选到相当DC中

m_BmpMain.m_hObject=NULL;

dcCompatible.SelectObject(&bitmap);

}

4、将相称DC中的位图贴到当前DC中。

}

pDC->BitBlt(rect.left,rect.top,rect.Width(),

//取得分开的字符串,用来滚动彰显

rect.Height(),&dcCompatible,0,0,SRCCOPY);

voidCCreditStatic::SetCredits(LPCTSTRcredits,chardelimiter)

 

{

在CView类中加多WM_ERASEBKGND新闻,在该新闻所对应的消息响应函数On伊RusseBkgnd中增加代码:

char*str,*ptr1,*ptr2;

BOOL CGraphicView::OnEraseBkgnd(CDC* pDC)

ASSERT(credits);

{

if((str=strdup(credits))==NULL)

      // TODO: Add your message handler code here and/or call default

return;

      CBitmap bitmap;

m_ArrCredit.RemoveAll();

      bitmap.LoadBitmap(IDB_BITMAP1);

ptr1=str;

 

//得到分开的字符串,当中/表示行与行之间的间隔

      BITMAP bmp;

while((ptr2=strchr(ptr1,delimiter))!=NULL){

      bitmap.GetBitmap(&bmp);

*ptr2=;

 

m_ArrCredit.AddTail(ptr1);

      CDC dcCompatible;

ptr1=ptr2+1;

      dcCompatible.CreateCompatibleDC(pDC);

}

 

m_ArrCredit.AddTail(ptr1);

      dcCompatible.SelectObject(&bitmap);

free(str);

 

m_ArrIndex=m_ArrCredit.GetHeadPosition();

      CRect rect;

m_nCounter=1;

      GetClientRect(&rect);

m_nClip=0;

      //方法1:位图原始大小展现,一比一的显得

m_bFirstTime=TRUE;

      pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);

m_bDrawText=FALSE;

      //方法2:拉伸或减弱位图使得位图可以随窗口的大小退换而修正

}

      pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,           0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);

voidCCreditStatic::SetCredits(UINTnID,chardelimiter)

      return TRUE;

{

//return CView::OnEraseBkgnd(pDC卡塔尔国;
//该行必须注释掉,不然被调用的话,又会擦除掉了

CStringcredits;

}

if(!credits.LoadString(nID))

上述方法On伊RusseBkgnd中的代码也能够放在OnDraw函数中,但有叁个主题素材,正是在改换窗口大小的时候,窗口上的位图会闪烁一下,这是因为OnDraw先将背景擦除后在粘贴上一张位图,而On伊RusseBkgnd是世界将位图粘在上头,未有擦除那样的动作。

return;

SetCredits((LPCTSTR)credits,delimiter);

}

//设置滚动速度

voidCCreditStatic::SetSpeed(UINTindex,intspeed)

{

ASSERT(index=DISPLAY_FAST);

if(speed)

m_DisplaySpeed[index]=speed;

m_CurrentSpeed=index;

}

//设置颜色,富含前途和背景

voidCCreditStatic::SetColor(UINTindex,COLORREFcol)

{

ASSERT(index=NORMAL_TEXT_COLOR);

m_Colors[index]=col;

}

//设置字符中度

voidCCreditStatic::SetTextHeight(UINTindex,intheight)

{

ASSERT(index=NORMAL_TEXT_HEIGHT);

m_TextHeights[index]=height;

}

voidCCreditStatic::SetEscape(UINTindex,charescape)

{

ASSERT(index=DISPLAY_BITMAP);

m_Escapes[index]=escape;

}

voidCCreditStatic::SetGradient(UINTvalue)

{

ASSERT(value=GRADIENT_LEFT_LIGHT);

m_Gradient=value;

}

//设置是或不是透明

voidCCreditStatic::SetTransparent(BOOLbTransparent)

{

m_bTransparent=bTransparent;

}

voidCCreditStatic::OnPaint()

{

CPaintDCdc(this);//devicecontextforpainting

if(TimerOn)return;

CDCmemDC;

memDC.CreateCompatibleDC(dc);

CBitmap*pOldMemDCBitmap=NULL;

CRectm_ScrollRect;

GetClientRect(m_ScrollRect);

if(m_BmpMain.m_hObject==NULL){

CDCmemDC2;

CBitmapbitmap;

memDC2.CreateCompatibleDC(dc);

bitmap.CreateCompatibleBitmap(dc,m_ScrollRect.Width(),m_ScrollRect.Height());

CBitmap*pOldMemDC2Bitmap=(CBitmap*)memDC2.SelectObject(bitmap);

DrawCredit(memDC2,m_ScrollRect);

AddBackGround(memDC2,m_ScrollRect,m_ScrollRect);

pOldMemDCBitmap=(CBitmap*)memDC.SelectObject(m_BmpMain);

memDC.BitBlt(0,0,m_ScrollRect.Width(),m_ScrollRect.Height(),

memDC2,0,0,SRCCOPY);

memDC2.SelectObject(pOldMemDC2Bitmap);

}

else

pOldMemDCBitmap=(CBitmap*)memDC.SelectObject(m_BmpMain);

dc.BitBlt(0,0,m_ScrollRect.Width(),m_ScrollRect.Height(),

memDC,0,0,SRCCOPY);

}

BOOLCCreditStatic::OnEraseBkgnd(CDC*pDC)

{

returnTRUE;

//returnCStatic::OnEraseBkgnd(pDC);

}

//************************************************************************

//OnTimer

//

//Oneachofthedisplaytimers,scrollthewindow1unit.Each20

//units,fetchthenextarrayelementandloadintoworkstring.Call

//InvalidateandUpdateWindowtoinvoketheOnPaintwhichwillpaint

//thecontentsofthenewlyupdatedworkstring.

//************************************************************************

voidCCreditStatic::OnTimer(UINTnIDEvent)

{

//非设置的电磁打点计时器ID,重临

if(nIDEvent!=DISPLAY_TIMER_ID)

{

CStatic::OnTimer(nIDEvent);

return;

}

BOOLbCheck=FALSE;

//要是上次读入的字符串表示的不是位图名字

if(!m_bProcessingBitmap){

//根据m_nCurrentFontHeight中度决定必要多少次time响应才换一行字符显示

if(m_nCounter++%m_nCurrentFontHeight==0)

{

m_nCounter=1;

//读出字符串队列中下一行要显示的字符串

m_szWork=m_ArrCredit.GetNext(m_ArrIndex);

if(m_bFirstTurn)

bCheck=TRUE;

if(m_ArrIndex==NULL){

m_bFirstTurn=FALSE;

m_ArrIndex=m_ArrCredit.GetHeadPosition();

}

m_nClip=0;

m_bDrawText=TRUE;

}

}

CClientDCdc(this);

CRectm_ScrollRect;

GetClientRect(m_ScrollRect卡塔尔;//得到全体CStatic的客商区坐标

CRectm_ClientRect(m_ScrollRect卡塔尔国;//用来代表滚动字符的限量

m_ClientRect.left=(m_ClientRect.Width()-n_MaxWidth)/2;

m_ClientRect.right=m_ClientRect.left+n_MaxWidth;

MoveCredit(dc,m_ScrollRect,m_ClientRect,bCheck卡塔尔(قطر‎;//完结字幕滚动1单元

AddBackGround(dc,m_ScrollRect,m_ClientRectState of Qatar;//增加背景

CStatic::OnTimer(nIDEvent);

}

//设置背景

voidCCreditStatic::AddBackGround(CDC*pDC,CRectm_ScrollRect,CRectm_ClientRect)

{

CDCmemDC;

memDC.CreateCompatibleDC(pDC);

if(m_bitmap.m_hObject==NULL)

{

CBitmap*pOldBitmap=memDC.SelectObject(m_BmpMain);

pDC-BitBlt(0,0,m_ScrollRect.Width(),m_ScrollRect.Height(),

memDC,0,0,SRCCOPY);

memDC.SelectObject(pOldBitmap);

return;

}

//Drawbitmapinthebackgroundifonehasbeenset

//Nowcreateamask

CBitmapbitmap;

bitmap.CreateCompatibleBitmap(pDC,m_ClientRect.Width(),m_ClientRect.Height());

CBitmap*pOldMemDCBitmap=memDC.SelectObject(bitmap);

CDCtempDC;

tempDC.CreateCompatibleDC(pDC);

CBitmap*pOldTempDCBitmap=tempDC.SelectObject(m_BmpMain);

memDC.BitBlt(0,0,m_ClientRect.Width(),m_ClientRect.Height(),tempDC,

m_ClientRect.left,m_ClientRect.top,SRCCOPY);

CDCmaskDC;

maskDC.CreateCompatibleDC(pDC);

CBitmapmaskBitmap;

//Createmonochromebitmapforthemask

maskBitmap.CreateBitmap(m_ClientRect.Width(),m_ClientRect.Height(),1,1,NULL);

CBitmap*pOldMaskDCBitmap=maskDC.SelectObject(maskBitmap);

memDC.SetBkColor(m_bTransparent?RGB(192,192,192):m_Colors[BACKGROUND_COLOR]);

//CreatethemaskfromthememoryDC

maskDC.BitBlt(0,0,m_ClientRect.Width(),m_ClientRect.Height(),memDC,0,0,SRCCOPY);

tempDC.SelectObject(pOldTempDCBitmap);

pOldTempDCBitmap=tempDC.SelectObject(m_bitmap);

CDCimageDC;

CBitmapbmpImage;

imageDC.CreateCompatibleDC(pDC);

bmpImage.CreateCompatibleBitmap(pDC,m_ScrollRect.Width(),m_ScrollRect.Height());

CBitmap*pOldImageDCBitmap=imageDC.SelectObject(bmpImage);

if(pDC-GetDeviceCaps(RASTERCAPS)RC_PALETTEm_pal.m_hObject!=NULL)

{

pDC-SelectPalette(m_pal,FALSE);

pDC-RealizePalette();

imageDC.SelectPalette(m_pal,FALSE);

}

//Getxandyoffset

//DrawbitmapintiledmannertoimageDC

for(inti=0;im_ScrollRect.right;i+=m_cxBitmap)

for(intj=0;jm_ScrollRect.bottom;j+=m_cyBitmap)

imageDC.BitBlt(i,j,m_cxBitmap,m_cyBitmap,tempDC,0,0,SRCCOPY);

//SetthebackgroundinmemDCtoblack.UsingSRCPAINTwithblackandanyother

//colorresultsintheothercolor,thusmakingblackthetransparentcolor

memDC.SetBkColor(RGB(0,0,0));

memDC.SetTextColor(RGB(255,255,255));

memDC.BitBlt(0,0,m_ClientRect.Width(),m_ClientRect.Height(),maskDC,0,0,SRCAND);

//Settheforegroundtoblack.Seecommentabove.

imageDC.SetBkColor(RGB(255,255,255));

imageDC.SetTextColor(RGB(0,0,0));

imageDC.BitBlt(m_ClientRect.left,m_ClientRect.top,m_ClientRect.Width(),m_ClientRect.Height(),

maskDC,0,0,SRCAND);

//Combinetheforegroundwiththebackground

imageDC.BitBlt(m_ClientRect.left,m_ClientRect.top,m_ClientRect.Width(),m_ClientRect.Height(),

memDC,0,0,SRCPAINT);

//Drawthefinalimagetothescreen

pDC-BitBlt(0,0,m_ScrollRect.Width(),m_ScrollRect.Height(),

imageDC,0,0,SRCCOPY);

imageDC.SelectObject(pOldImageDCBitmap);

maskDC.SelectObject(pOldMaskDCBitmap);

tempDC.SelectObject(pOldTempDCBitmap);

memDC.SelectObject(pOldMemDCBitmap);

}

voidCCreditStatic::DrawBitmap(CDC*pDC,CDC*pDC2,CRect*rBitmap)

{

if(!m_bTransparent||m_bitmap.m_hObject!=NULL){

pDC-BitBlt(rBitmap-left,rBitmap-top,rBitmap-Width(),rBitmap-Height(),

pDC2,0,0,SRCCOPY);

return;

}

//成立与pDC宽容的设备

CDCmemDC;

memDC.CreateCompatibleDC(pDC);

//创立宽容位图并且选进设备

CBitmapbitmap;

bitmap.CreateCompatibleBitmap(pDC,rBitmap-Width(),rBitmap-Height());

CBitmap*pOldMemDCBitmap=memDC.SelectObject(bitmap);

//将pDC第22中学的位图拷贝到memDC

memDC.BitBlt(0,0,rBitmap-Width(),rBitmap-Height(),pDC2,0,0,SRCCOPY);

CDCmaskDC;

maskDC.CreateCompatibleDC(pDC);

//创立单色位图并且选入设备

CBitmapmaskBitmap;

maskBitmap.CreateBitmap(rBitmap-Width(),rBitmap-Height(),1,1,NULL);

CBitmap*pOldMaskDCBitmap=maskDC.SelectObject(maskBitmap);

memDC.SetBkColor(TucsonGB(192,192,192State of Qatar卡塔尔;//背景为系统色

//将memDC中的位图拷贝到maskDC,maskDC中的的1意味着位图背景观,0意味着前途,即位图

maskDC.BitBlt(0,0,rBitmap-Width(),rBitmap-Height(),memDC,0,0,SRCCOPY);

CDCimageDC;

CBitmapbmpImage;

imageDC.CreateCompatibleDC(pDC);

bmpImage.CreateCompatibleBitmap(pDC,rBitmap-Width(),rBitmap-Height());

CBitmap*pOldImageDCBitmap=imageDC.SelectObject(bmpImage);

//将pDC中对应位图背景区域拷贝到imageDC

imageDC.BitBlt(0,0,rBitmap-Width(),rBitmap-Height(),pDC,rBitmap-left,rBitmap-top,SRCCOPY);

//下边包车型地铁代码达成透明位图,见msdn的DrawingTransparentBitmaps

//SetthebackgroundinmemDCtoblack.UsingSRCPAINTwithblackandanyother

//colorresultsintheothercolor,thusmakingblackthetransparentcolor

//设置背景为藏赫色

memDC.SetBkColor(RGB(0,0,0));

memDC.SetTextColor(RGB(255,255,255));

memDC.BitBlt(0,0,rBitmap-Width(),rBitmap-Height(),maskDC,0,0,SRCAND);

//设置前程为桔棕

imageDC.SetBkColor(RGB(255,255,255));

imageDC.SetTextColor(RGB(0,0,0));

imageDC.BitBlt(0,0,rBitmap-Width(),rBitmap-Height(),maskDC,0,0,SRCAND);

//获得透明的位图

imageDC.BitBlt(0,0,rBitmap-Width(),rBitmap-Height(),memDC,0,0,SRCPAINT);

//将位图移动到分外岗位

pDC-BitBlt(rBitmap-left,rBitmap-top,rBitmap-Width(),rBitmap-Height(),

imageDC,0,0,SRCCOPY);

imageDC.SelectObject(pOldImageDCBitmap);

maskDC.SelectObject(pOldMaskDCBitmap);

memDC.SelectObject(pOldMemDCBitmap);

}

voidCCreditStatic::FillGradient(CDC*pDC,CRect*m_ScrollRect,CRect*m_FillRect,COLORREFcolor)

{

floatfStep,fRStep,fGStep,fBStep;//Howlargeiseachband?

intiOnBand;//Loopindex

WORDR=GetRValue(color);

WORDG=GetGValue(color);

WORDB=GetBValue(color);

//Determinehowlargeeachbandshouldbeinordertocoverthe

//clientwith256bands(oneforeverycolorintensitylevel)

if(m_Gradient%2){

fRStep=(float)R/255.0f;

fGStep=(float)G/255.0f;

fBStep=(float)B/255.0f;

}else{

fRStep=(float)(255-R)/255.0f;

fGStep=(float)(255-G)/255.0f;

fBStep=(float)(255-B)/255.0f;

}

COLORREFOldCol=pDC-GetBkColor();

//Startfillingbands

fStep=(float)m_ScrollRect-Width()/256.0f;

for(iOnBand=(256*m_FillRect-left)/m_ScrollRect-Width();

(int)(iOnBand*fStep)m_FillRect-rightiOnBand256;iOnBand++){

CRectr((int)(iOnBand*fStep),m_FillRect-top,

(int)((iOnBand+1)*fStep),m_FillRect-bottom+1);

COLORREFcol;

switch(m_Gradient){

caseGRADIENT_RIGHT_DARK:

col=RGB((int)(R-iOnBand*fRStep),(int)(G-iOnBand*fGStep),(int)(B-iOnBand*fBStep));

break;

caseGRADIENT_RIGHT_LIGHT:

col=RGB((int)(R+iOnBand*fRStep),(int)(G+iOnBand*fGStep),(int)(B+iOnBand*fBStep));

break;

caseGRADIENT_LEFT_DARK:

col=RGB((int)(iOnBand*fRStep),(int)(iOnBand*fGStep),(int)(iOnBand*fBStep));

break;

caseGRADIENT_LEFT_LIGHT:

col=RGB(255-(int)(iOnBand*fRStep),255-(int)(iOnBand*fGStep),255-(int)(iOnBand*fBStep));

break;

default:

return;

}

pDC-FillSolidRect(r,col);

}

pDC-SetBkColor(OldCol);

}

#defineSCROLLDC

voidCCreditStatic::MoveCredit(CDC*pDC,CRectm_ScrollRect,CRectm_ClientRect,BOOLbCheck)

{

CDCmemDC,memDC2;

//创制宽容的装置

memDC.CreateCompatibleDC(pDC);

memDC2.CreateCompatibleDC(pDC);

//决定背景颜色,借使初始设置为透明何况有背景位图,就选取系统色,不然选拔安装的背景象

COLORREFBackColor=(m_bTransparentm_bitmap.m_hObject!=NULL)?RGB(192,192,192):m_Colors[BACKGROUND_COLOR];

CBitmap*pOldMemDCBitmap=NULL;

CBitmap*pOldMemDC2Bitmap=NULL;

#ifdefSCROLLDC

CRectr1;

#endif

//发轫句柄为空

if(m_BmpMain.m_hObject==NULL){

//创造与设备优异的位图

m_BmpMain.CreateCompatibleBitmap(pDC,m_ScrollRect.Width(),m_ScrollRect.Height());

//将位图选入设备

pOldMemDCBitmap=(CBitmap*)memDC.SelectObject(m_BmpMain);

//选取是用梯度依旧背景色填充设备memDC的背景

if(m_Gradientm_bitmap.m_hObject==NULL)

FillGradient(memDC,m_ScrollRect,m_ScrollRect,m_Colors[BACKGROUND_COLOR]);

else

memDC.FillSolidRect(m_ScrollRect,BackColor);

}else

pOldMemDCBitmap=(CBitmap*)memDC.SelectObject(m_BmpMain);

if(m_ClientRect.Width()0){

#ifndefSCROLLDC//假诺不扶植设施滚动

CBitmapbitmap;

bitmap.CreateCompatibleBitmap(pDC,m_ClientRect.Width(),m_ClientRect.Height());

pOldMemDC2Bitmap=memDC2.SelectObject(bitmap);

//memDC向上滚动一行,利用设备拷贝

memDC2.BitBlt(0,0,m_ClientRect.Width(),m_ClientRect.Height()-abs(m_ScrollAmount),

memDC,m_ClientRect.left,abs(m_ScrollAmount),SRCCOPY);

memDC.BitBlt(m_ClientRect.left,0,m_ClientRect.Width(),m_ClientRect.Height(),

memDC2,0,0,SRCCOPY);

memDC2.SelectObject(pOldMemDC2Bitmap);

pOldMemDC2Bitmap=NULL;

#else//假设支持设备滚动

CRgnRgnUpdate;

//memDC向上滚动一行,利用设备拷贝

memDC.ScrollDC(0,m_ScrollAmount,(LPCRECT)m_ScrollRect,(LPCRECT)m_ClientRect,RgnUpdate,

(LPRECT)r1);

}

else{

//r1存款和储蓄着要立异的区域地点

r1=m_ScrollRect;

r1.top=r1.bottom-abs(m_ScrollAmount);

#endif

}

m_nClip=m_nClip+abs(m_ScrollAmount);

//*********************************************************************

//FONTSELECTION

CFontm_fntArial;

CFont*pOldFont=NULL;

BOOLbSuccess=FALSE;

BOOLbUnderline;

BOOLbItalic;

intrmcode=0;

//依照字符串性质决定操作

//更新的来得字符串不为空

if(!m_szWork.IsEmpty()){

//依照字符串最终一个人决定项目

charc=m_szWork[m_szWork.GetLength()-1];

if(c==m_Escapes[TOP_LEVEL_GROUP]卡塔尔(قطر‎//类型为最大群组标题

{

rmcode=1;

bItalic=FALSE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[TOP_LEVEL_GROUP_HEIGHT];

//创造字体

bSuccess=m_fntArial.CreateFont(m_TextHeights[TOP_LEVEL_GROUP_HEIGHT],0,0,0,

FW_BOLD,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

//设置字体颜色

memDC.SetTextColor(m_Colors[TOP_LEVEL_GROUP_COLOR]);

//选入设备

if(pOldFont!=NULL)memDC.SelectObject(pOldFont);

pOldFont=memDC.SelectObject(m_fntArial);

}

elseif(c==m_Escapes[GROUP_TITLE]State of Qatar{//类型为组标题

rmcode=1;

bItalic=FALSE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[GROUP_TITLE_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[GROUP_TITLE_HEIGHT],0,0,0,

FW_BOLD,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[GROUP_TITLE_COLOR]);

if(pOldFont!=NULL)memDC.SelectObject(pOldFont);

pOldFont=memDC.SelectObject(m_fntArial);

}

elseif(c==m_Escapes[TOP_LEVEL_TITLE]State of Qatar{//类型为最大标题

rmcode=1;

bItalic=FALSE;

//bUnderline=TRUE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[TOP_LEVEL_TITLE_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[TOP_LEVEL_TITLE_HEIGHT],0,0,0,

FW_BOLD,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[TOP_LEVEL_TITLE_COLOR]);

if(pOldFont!=NULL)memDC.SelectObject(pOldFont);

pOldFont=memDC.SelectObject(m_fntArial);

}

elseif(c==m_Escapes[DISPLAY_BITMAP]卡塔尔{//类型为位图

if(!m_bProcessingBitmap)

{

CStringszBitmap=m_szWork.Left(m_szWork.GetLength(卡塔尔(قطر‎-1State of Qatar;//取得位图名字

if(m_bmpWork.LoadBitmap((constchar*State of QatarszBitmap卡塔尔国卡塔尔{//载入位图

BITMAPm_bmpInfo;

m_bmpWork.GetObject(sizeof(BITMAP),m_bmpInfo);

m_size.cx=m_bmpInfo.bmWidth;//widthofdestrect

m_size.cy=m_bmpInfo.bmHeight;

//得到要出示位图的左上角坐标

m_pt.x=(m_ClientRect.right-

((m_ClientRect.Width())/2)-(m_size.cx/2));

m_pt.y=m_ClientRect.bottom;

m_bProcessingBitmap=TRUE;

if(pOldMemDC2Bitmap!=NULL)memDC2.SelectObject(pOldMemDC2Bitmap);

pOldMemDC2Bitmap=memDC2.SelectObject(m_bmpWork卡塔尔国;//位图选入设备memDC2

}

else

c=;

}

else{

if(pOldMemDC2Bitmap!=NULL)memDC2.SelectObject(pOldMemDC2Bitmap);

pOldMemDC2Bitmap=memDC2.SelectObject(m_bmpWork);

}

}

else{

bItalic=FALSE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[NORMAL_TEXT_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[NORMAL_TEXT_HEIGHT],0,0,0,

FW_THIN,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[NORMAL_TEXT_COLOR]);

if(pOldFont!=NULL)memDC.SelectObject(pOldFont);

pOldFont=memDC.SelectObject(m_fntArial);

}

}

#ifndefSCROLLDC

CRectr1(m_ScrollRect);

r1.top=r1.bottom-abs(m_ScrollAmount);

#endif

//填充背景

if(m_Gradientm_bitmap.m_hObject==NULL)

FillGradient(memDC,m_ScrollRect,r1,m_Colors[BACKGROUND_COLOR]);

else

memDC.FillSolidRect(r1,BackColor);

memDC.SetBkMode(TRANSPARENT);

if(!m_bProcessingBitmap卡塔尔(قطر‎//借使不是位图

{

if(bCheck卡塔尔国{//对于单身一行字符的首先次滚动,必要先明确滚动区域范围

CSizesize=memDC.GetTextExtent((LPCTSTR)m_szWork,m_szWork.GetLength()-rmcode);

if(size.cxn_MaxWidth){

n_MaxWidth=(size.cxm_ScrollRect.Width())?m_ScrollRect.Width():size.cx;

m_ClientRect.left=(m_ScrollRect.Width()-n_MaxWidth)/2;

m_ClientRect.right=m_ClientRect.left+n_MaxWidth;

}

}

CRectr(m_ClientRect);

r.top=r.bottom-m_nClip;

//在要翻新的区域展现字符

intx=memDC.DrawText((constchar*)m_szWork,m_szWork.GetLength()-rmcode,r,DT_TOP|DT_CENTER|

DT_NOPREFIX|DT_SINGLELINE);

m_bDrawText=FALSE;

}

else

{

if(bCheck){

CSizesize=memDC.GetTextExtent((LPCTSTR)m_szWork,m_szWork.GetLength()-rmcode);

if(m_size.cxn_MaxWidth){

n_MaxWidth=(m_size.cxm_ScrollRect.Width())?m_ScrollRect.Width():m_size.cx;

m_ClientRect.left=(m_ScrollRect.Width()-n_MaxWidth)/2;

m_ClientRect.right=m_ClientRect.left+n_MaxWidth;

}

}

CRectr(m_pt.x,m_pt.y-m_nClip,m_pt.x+m_size.cx,m_pt.y);

//假设是位图,依照背景memDC和位图设备memDC2,在改过区域显示部分位图

DrawBitmap(memDC,memDC2,r);

//memDC.BitBlt(m_pt.x,m_pt.y-m_nClip,m_size.cx,m_nClip,

//memDC2,0,0,SRCCOPY);

if(m_nClip=m_size.cy)

{

m_bmpWork.DeleteObject();

m_bProcessingBitmap=FALSE;

m_nClip=0;

m_szWork.Empty();

m_nCounter=1;

}

}

//復苏设备

if(pOldMemDC2Bitmap!=NULL)memDC2.SelectObject(pOldMemDC2Bitmap);

if(pOldFont!=NULL)memDC.SelectObject(pOldFont);

memDC.SelectObject(pOldMemDCBitmap);

}

voidCCreditStatic::DrawCredit(CDC*pDC,CRectm_ScrollRect)

{

if(m_BmpMain.m_hObject!=NULL)return;

CDCmemDC,memDC2;

memDC.CreateCompatibleDC(pDC);

memDC2.CreateCompatibleDC(pDC);

COLORREFBackColor=(m_bTransparentm_bitmap.m_hObject!=NULL)?RGB(192,192,192):m_Colors[BACKGROUND_COLOR];

CBitmap*pOldMemDCBitmap=NULL;

m_BmpMain.CreateCompatibleBitmap(pDC,m_ScrollRect.Width(),m_ScrollRect.Height());

pOldMemDCBitmap=(CBitmap*)memDC.SelectObject(m_BmpMain);

if(m_Gradientm_bitmap.m_hObject==NULL)

FillGradient(memDC,m_ScrollRect,m_ScrollRect,m_Colors[BACKGROUND_COLOR]);

else

memDC.FillSolidRect(m_ScrollRect,BackColor);

POSITIONpos=m_ArrCredit.GetHeadPosition();

intheight=0;

while(pos!=NULLheight=m_ScrollRect.Height()){

CStringm_szWork=m_ArrCredit.GetNext(pos);

CFontm_fntArial;

CFont*pOldFont=NULL;

CBitmap*pOldMemDC2Bitmap=NULL;

CDCmemDC2;

memDC2.CreateCompatibleDC(pDC);

//*********************************************************************

//FONTSELECTION

BOOLbSuccess=FALSE;

BOOLbIsBitmap=FALSE;

BOOLbUnderline;

BOOLbItalic;

intrmcode=0;

CBitmapbitmap;

if(!m_szWork.IsEmpty()){

charc=m_szWork[m_szWork.GetLength()-1];

if(c==m_Escapes[TOP_LEVEL_GROUP]){

rmcode=1;

bItalic=FALSE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[TOP_LEVEL_GROUP_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[TOP_LEVEL_GROUP_HEIGHT],0,0,0,

FW_BOLD,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[TOP_LEVEL_GROUP_COLOR]);

pOldFont=memDC.SelectObject(m_fntArial);

}

elseif(c==m_Escapes[GROUP_TITLE]){

rmcode=1;

bItalic=FALSE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[GROUP_TITLE_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[GROUP_TITLE_HEIGHT],0,0,0,

FW_BOLD,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[GROUP_TITLE_COLOR]);

pOldFont=memDC.SelectObject(m_fntArial);

}

elseif(c==m_Escapes[TOP_LEVEL_TITLE]){

rmcode=1;

bItalic=FALSE;

//bUnderline=TRUE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[TOP_LEVEL_TITLE_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[TOP_LEVEL_TITLE_HEIGHT],0,0,0,

FW_BOLD,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[TOP_LEVEL_TITLE_COLOR]);

pOldFont=memDC.SelectObject(m_fntArial);

}

elseif(c==m_Escapes[DISPLAY_BITMAP]){

CStringszBitmap=m_szWork.Left(m_szWork.GetLength()-1);

if(bitmap.LoadBitmap((constchar*)szBitmap)){

BITMAPm_bmpInfo;

bitmap.GetObject(sizeof(BITMAP),m_bmpInfo);

m_size.cx=m_bmpInfo.bmWidth;//widthofdestrect

m_size.cy=m_bmpInfo.bmHeight;

//upperleftpointofdest

m_pt.x=(m_ScrollRect.right-

((m_ScrollRect.Width())/2)-(m_size.cx/2));

m_pt.y=height;

pOldMemDC2Bitmap=memDC2.SelectObject(bitmap);

bIsBitmap=TRUE;

}

else

c=;

}

else{

bItalic=FALSE;

bUnderline=FALSE;

m_nCurrentFontHeight=m_TextHeights[NORMAL_TEXT_HEIGHT];

bSuccess=m_fntArial.CreateFont(m_TextHeights[NORMAL_TEXT_HEIGHT],0,0,0,

FW_THIN,bItalic,bUnderline,0,

ANSI_CHARSET,

OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS,

PROOF_QUALITY,

VARIABLE_PITCH|0x04|FF_DONTCARE,

(LPSTR)Arial);

memDC.SetTextColor(m_Colors[NORMAL_TEXT_COLOR]);

pOldFont=memDC.SelectObject(m_fntArial);

}

}

memDC.SetBkMode(TRANSPARENT);

if(!bIsBitmap)

{

CRectr(m_ScrollRect);

r.top=height;

CSizesize;

if(m_szWork.GetLength()-rmcode!=0)

{

intx=memDC.DrawText((constchar*)m_szWork,m_szWork.GetLength()-rmcode,r,DT_TOP|DT_CENTER|

DT_NOPREFIX|DT_SINGLELINE);

size=memDC.GetTextExtent((LPCTSTR)m_szWork,m_szWork.GetLength()-rmcode);

}

else

size=memDC.GetTextExtent((LPCTSTR)W,1);

height+=size.cy;

}

else

{

CRectr(m_pt.x,m_pt.y,m_pt.x+m_size.cx,m_pt.y+m_size.cy);

DrawBitmap(memDC,memDC2,r);

//memDC.BitBlt(m_pt.x,m_pt.y,m_size.cx,m_size.cy,memDC2,0,0,SRCCOPY);

height+=m_size.cy;

}

if(pOldMemDC2Bitmap!=NULL)memDC2.SelectObject(pOldMemDC2Bitmap);

if(pOldFont!=NULL)memDC.SelectObject(pOldFont);

}

memDC.SelectObject(pOldMemDCBitmap);

}

voidCCreditStatic::OnDestroy()

{

CStatic::OnDestroy();

m_ArrCredit.RemoveAll();

if(TimerOn)

ASSERT(KillTimer(DISPLAY_TIMER_ID));

}

BOOLCCreditStatic::SetBkImage(UINTnIDResource)

{

returnSetBkImage((LPCTSTR)nIDResource);

}

//设置背景图片

BOOLCCreditStatic::SetBkImage(LPCTSTRlpszResourceName)

{

//删除早先的GDI对象

if(m_bitmap.m_hObject!=NULL)

m_bitmap.DeleteObject();

if(m_pal.m_hObject!=NULL)

m_pal.DeleteObject();

//载入位图

HBITMAPhBmp=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),

lpszResourceName,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);

if(hBmp==NULL)

returnFALSE;

m_bitmap.Attach(hBmp);

BITMAPbm;

m_bitmap.GetBitmap(bm);

m_cxBitmap=bm.bmWidth;

m_cyBitmap=bm.bmHeight;

//为位图成立逻辑调色板

DIBSECTIONds;

BITMAPINFOHEADERbmInfo=ds.dsBmih;

m_bitmap.GetObject(sizeof(ds),ds);

intnColors=bmInfo.biClrUsed?bmInfo.biClrUsed:1bmInfo.biBitCount;

//如若颜色大于256色,创造Halftone调色板

CClientDCdc(NULL);//DesktopDC

if(nColors256)

m_pal.CreateHalftonePalette(dc);

else

{

//不然,创造调色板

RGBQUAD*pRGB=newRGBQUAD[nColors];

CDCmemDC;

memDC.CreateCompatibleDC(dc);

CBitmap*pOldMemDCBitmap=memDC.SelectObject(m_bitmap);

::GetDIBColorTable(memDC,0,nColors,pRGB);

UINTnSize=sizeof(LOGPALETTE)+(sizeof(PALETTEENTRY)*nColors);

LOGPALETTE*pLP=(LOGPALETTE*)newBYTE[nSize];

pLP-palVersion=0x300;

pLP-palNumEntries=nColors;

for(inti=0;inColors;i++)

{

pLP-palPalEntry[i].peRed=pRGB[i].rgbRed;

pLP-palPalEntry[i].peGreen=pRGB[i].rgbGreen;

pLP-palPalEntry[i].peBlue=pRGB[i].rgbBlue;

pLP-palPalEntry[i].peFlags=0;

}

m_pal.CreatePalette(pLP);

memDC.SelectObject(pOldMemDCBitmap);

delete[]pLP;

delete[]pRGB;

}

returnTRUE;

}

2.CreditStatic.h的头文件代码

#if!defined(AFX_CREDITSTATIC_H__4ABD7701_49F5_11D1_9E3C_00A0245800CF__INCLUDED_)

#defineAFX_CREDITSTATIC_H__4ABD7701_49F5_11D1_9E3C_00A0245800CF__INCLUDED_

#if_MSC_VER=1000

#pragmaonce

#endif//_MSC_VER=1000

//CreditStatic.h:headerfile

//

#defineDISPLAY_SLOW0

#defineDISPLAY_MEDIUM1

#defineDISPLAY_FAST2

#defineBACKGROUND_COLOR0

#defineTOP_LEVEL_TITLE_COLOR1

#defineTOP_LEVEL_GROUP_COLOR2

#defineGROUP_TITLE_COLOR3

#defineNORMAL_TEXT_COLOR4

#defineTOP_LEVEL_TITLE_HEIGHT0

#defineTOP_LEVEL_GROUP_HEIGHT1

#defineGROUP_TITLE_HEIGHT2

#defineNORMAL_TEXT_HEIGHT3

#defineTOP_LEVEL_TITLE0//t

#defineTOP_LEVEL_GROUP1//n

#defineGROUP_TITLE2//r

#defineDISPLAY_BITMAP3//^

#defineGRADIENT_NONE0

#defineGRADIENT_RIGHT_DARK1

#defineGRADIENT_RIGHT_LIGHT2

#defineGRADIENT_LEFT_DARK3

#defineGRADIENT_LEFT_LIGHT4

classCCreditStatic:publicCStatic

{

protected:

COLORREFm_Colors[5];

intm_TextHeights[4];

TCHARm_Escapes[4];

intm_DisplaySpeed[3],m_CurrentSpeed;

//CRectm_ScrollRect;//rectofStaticTextframe

CStringListm_ArrCredit;

CStringm_szWork;

intm_nCounter;//workints

POSITIONm_ArrIndex;

BOOLm_bFirstTime;

BOOLm_bDrawText;

intm_nClip,m_ScrollAmount;

intm_nCurrentFontHeight;

CBitmapm_bmpWork;//bitmapholder

CBitmapm_BmpMain;//bitmapholder

CSizem_size;//drawinghelpers

CPointm_pt;

BOOLm_bProcessingBitmap;

CPalettem_pal;

CBitmapm_bitmap;

intm_cxBitmap,m_cyBitmap;

BOOLm_bFirstTurn;

UINTm_Gradient;

BOOLm_bTransparent;

intn_MaxWidth;

UINTTimerOn;

//Construction

public:

CCreditStatic();

//Attributes

public:

//Operations

public:

BOOLStartScrolling();

voidEndScrolling();

voidSetCredits(LPCTSTRcredits,chardelimiter=|);

voidSetCredits(UINTnID,chardelimiter=|);

voidSetSpeed(UINTindex,intspeed=0);

voidSetColor(UINTindex,COLORREFcol);

voidSetTextHeight(UINTindex,intheight);

voidSetEscape(UINTindex,charescape);

voidSetGradient(UINTvalue=GRADIENT_RIGHT_DARK);

BOOLSetBkImage(UINTnIDResource);

BOOLSetBkImage(LPCTSTRlpszResourceName);

voidSetTransparent(BOOLbTransparent=TRUE);

//Overrides

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CCreditStatic)

//}}AFX_VIRTUAL

//Implementation

public:

virtual~CCreditStatic();

//Generatedmessagemapfunctions

protected:

voidMoveCredit(CDC*pDC,CRectr,CRectr2,BOOLbCheck);

voidAddBackGround(CDC*pDC,CRectm_ScrollRect,CRectm_ClientRect);

voidDrawCredit(CDC*pDC,CRectm_ScrollRect);

voidFillGradient(CDC*pDC,CRect*m_ScrollRect,CRect*m_FillRect,COLORREFcolor);

voidDrawBitmap(CDC*pDC,CDC*pDC2,CRect*rBitmap);

//{{AFX_MSG(CCreditStatic)

afx_msgvoidOnPaint();

afx_msgBOOLOnEraseBkgnd(CDC*pDC);

afx_msgvoidOnTimer(UINTnIDEvent);

afx_msgvoidOnDestroy();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}

//MicrosoftDeveloperStudiowillinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!defined(AFX_CREDITSTATIC_H__4ABD7701_49F5_11D1_9E3C_00A0245800CF__INCLUDED_)

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图