📄 cbperbar.cpp
字号:
/////////////
// CBPerbar.cpp : v0010
// Written by : Li Haijun
// Compiler : Microsoft Visual C++ 4.0 & DirectX
// Library : No .Lib
// Copyright (C) : 1997 WayAhead Corporation
// v0010 : Mar.21.1997
/////////////
// to declear the class to show and update the percent process bar
// eg. building process, general blood...
///////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DDApi.h"
#include "DDCompo.h"
#include "marco.h"
#include "CBPerbar.h"
#include "interfac.h"
////////////////////////////
#include "l_allbmp.h"
extern char bmpfilename[30];
extern char listfilename[30];
/////////////////////////////////////
extern class CPercentBar FACE_Process; // to show the process of a product to be producted
// to init the instance of this class
CPercentBar::CPercentBar()
{
m_nFileNameId = NONE;
m_dwX = 0;
m_dwY = 0;
m_nFrameWidth = 0;
m_rBar.left = 0;
m_rBar.top = 0;
m_rBar.right = 0;
m_rBar.bottom = 0;
m_nCurrentPercent = 0;
m_nColor = 184;
}
// to release the resource that that the instance occupy
CPercentBar::~CPercentBar()
{
Release();
}
// to preload the bitmap background of this percent bar
BOOL CPercentBar::PreLoad(int FilenameId, int x, int y, int FrameWidth, int Color/*=184*/ )
{
char fname[20];
HRESULT ddrval;
DDSURFACEDESC ddsd;
//////////////////////////////////////////////////
_itoa( FilenameId, fname, 10 );
class CPicture_imageall picture;
picture.image_open_compress(bmpfilename);
picture.image_open_index(listfilename);
picture.LoadBitmap( &m_BitmapSurface, FilenameId );
picture.image_close_index();
picture.image_close_compress();
/////////////////////////////////////////////////////////
m_nFileNameId = FilenameId; //set the member veriable m_FileName
//
// get size of surface.
//
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
ddrval = m_BitmapSurface.GetSurface()->GetSurfaceDesc(&ddsd);
if(ddrval != DD_OK)
return FALSE;
m_dwX = x;
m_dwY = y;
m_nFrameWidth = FrameWidth;
m_rBar.left = 0;
m_rBar.top = 0;
m_rBar.right = ddsd.dwWidth;
m_rBar.bottom = ddsd.dwHeight;
BOOL iResult;
// to create a surface for you to blit the process
iResult = m_ProcessBarSurface.Create(
(ddsd.dwWidth - 2*FrameWidth),
(ddsd.dwHeight - 2*FrameWidth) );
if( iResult == FALSE )
return FALSE;
// to set the process bar color and default is 184
m_nColor = Color;
m_ProcessBarSurface.Erase( m_nColor );
return TRUE;
}
// to release this button's pointer
void CPercentBar::Release()
{
// release the surface that this button's bitmap used
m_BitmapSurface.Release();
// to release the surface that the process bar used
m_ProcessBarSurface.Release();
}
// to set the new position of this percent bar
void CPercentBar::SetPosition(int x, int y)
{
m_dwX = x ;
m_dwY = y ;
}
// to blit this percent bar to the just area of back buffer
void CPercentBar::Blit(int NewPercent/* = -10*/)
{
POINT ptDest;
ptDest.x = m_dwX;
ptDest.y = m_dwY;
if( NewPercent != -10 )
{
if( NewPercent < 0 )
m_nCurrentPercent = 0;
else if( NewPercent >100 )
m_nCurrentPercent = 100;
else
m_nCurrentPercent = NewPercent;
}
m_BitmapSurface.BltToBack( ptDest, &m_rBar );
int Length; // the length of the blood bar
POINT ptBDest;
RECT FillRect;
if( this != &FACE_Process )
{
if( m_nCurrentPercent < 33)
m_ProcessBarSurface.Erase( 80 );
else if( m_nCurrentPercent < 66 )
m_ProcessBarSurface.Erase( 93 );
else
m_ProcessBarSurface.Erase( m_nColor );
}
else
m_ProcessBarSurface.Erase( m_nColor );
Length = ( m_nCurrentPercent * ( (m_rBar.right-m_rBar.left) - 2*m_nFrameWidth) ) / 100 ;
ptBDest.x = ptDest.x + m_nFrameWidth;
ptBDest.y = ptDest.y + m_nFrameWidth;
/*
FillRect.left = m_dwX + m_nFrameWidth;
FillRect.top = m_dwY + m_nFrameWidth;
FillRect.right = FillRect.left + Length;
FillRect.bottom = FillRect.top + (m_rBar.bottom - 2*m_nFrameWidth) ;
*/
FillRect.left = 0;
FillRect.top = 0;
FillRect.right = Length;
FillRect.bottom = m_rBar.bottom - 2*m_nFrameWidth ;
m_ProcessBarSurface.BltToBack( ptBDest, &FillRect );
}
// to blit this percent bar to the just area of back buffer
void CPercentBar::Update(void)
{
RECT ShowRect;
ShowRect.left = m_dwX, ShowRect.top = m_dwY;
ShowRect.right = m_dwX + m_rBar.right;
ShowRect.bottom = m_dwY + m_rBar.bottom;
DDC_UpdateScreen( &ShowRect );
}
// to update this percent bar with a new input percent
void CPercentBar::UpdateData( int NewPercent )
{
Blit( NewPercent );
/////////////////////////////////////////////////////////////
// if current is displaying a menu, return with do nothing
// July.24.1997
if( FACE_GetCommandState() == COMMAND_STATE_MENU )
return ;
Update();
}
//blit this percent bar to back buffer and then update it
void CPercentBar::Show(void)
{
Blit();
Update();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -