• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    CProgressCtrlEx (프로그래시브 바) (GDI+, Gradient)
    Last Modify : 27 December, 2010(01:56)
    사용법 : 프로그래스 바를 만드신 뒤 ProgressCtrlEx 로 맴버 변수를 추가해주시면됩니다.
    
    m_pgsTest.SetRange(0, 1000);
    m_pgsTest.SetBorderColor(Color(0,0,255));
    m_pgsTest.SetFontColor(Color(255,255,255));
    m_pgsTest.nViewStatus(_PROGRESSCTRL_EX_PERCENTAGE);
    m_pgsTest.SetStartColor(Color(0,0,0));
    m_pgsTest.SetEndColor(Color(255,0,0));
    m_pgsTest.SetPadding(CRect(2,2,2,2));
    m_pgsTest.SetFontColor(Color(0, 0, 255));
    m_pgsTest.SetFontStyle(L"Verdana", 11);
    m_pgsTest.SetBackgroundColor(Color(0,255,0));
    
    // ProgressCtrlEx.cpp : implementation file
    //
    
    // DATE		: February 9, 2007
    // CODER	: Kurome (aucd29@gmail.com)
    //
    // VERSION	: 1.1 (February 12, 2007)
    //			: 1.2 (February 13, 2007)
    //
    // Copyright Asia pasific satellite industries Co., Ltd.
    //
    // ----------------------------------------------------------
    // Require : GDI+
    // installation Guide : http://sarangnamu.net/basic/basic_view.php?no=1369
    // Manual(kor) : http://winapi.co.kr/project/library/gdiplus/gdiplus.htm
    //
    // ----------------------------------------------------------
    // NOTE : February 9, 2007
    // ----------------------------------------------------------
    // * MUM 에 필요해서 하나 만든다. 근데 좀 귀찮다.
    // * 찾아보니 소스가 있더라 -_ - 만들기 귀찮은데 그냥 가져다
    //   써버릴까 생각은 했지만 프로젝트가 끝나서 딱히 할 것도
    //   없고... 
    // * 참조 소스
    //   http://www.codeproject.com/miscctrl/gradientprogressctrl.asp
    //
    // ----------------------------------------------------------
    // NOTE : February 12, 2007
    // ----------------------------------------------------------
    // * 1차 공개
    // * 기타 버그는 aucd29@gmail.com 로 부탁 드립니다.
    // * 퍼센트 혹은 갯수 표시 완료
    //
    // ----------------------------------------------------------
    // FIX : February 12, 2007
    // ----------------------------------------------------------
    // * 그라이데이션이 정상적으로 나오지 않은 문제 해결
    // * 빠르게 갱신되지 않던 문제 해결
    // * 더블 버퍼링에 대한 추가 작업
    //
    // ----------------------------------------------------------
    // FIX : February 13, 2007
    // ----------------------------------------------------------
    // * 속성값이 없을 때 기본값을 적용
    // * 첫 로딩시 깜박임 수정
    //
    // Gradient Mode
    // --------------------------------------------------
    // LinearGradientModeHorizontal,         // 0
    // LinearGradientModeVertical,           // 1
    // LinearGradientModeForwardDiagonal,    // 2
    // LinearGradientModeBackwardDiagonal    // 3
    //
    
    #include "stdafx.h"
    #include "GDIPLUS_TEST.h"
    #include "ProgressCtrlEx.h"
    
    
    // CProgressCtrlEx
    
    IMPLEMENT_DYNAMIC(CProgressCtrlEx, CProgressCtrl)
    
    CProgressCtrlEx::CProgressCtrlEx()
    : m_nLower(0)
    , m_nUpper(100)
    , m_nStep(0)
    , m_nCurrentPosition(50)
    , m_nPenWidth(1)
    , m_bLoad(false)
    , m_nMark(_PROGRESSCTRL_EX_NONE)
    , m_szFont(L"Tahoma")
    , m_nFontSize(11)
    {
    	CString d;
    	d.Format(L"%d", m_nMark);
    
    	m_crBackground	= Color(255, 255, 255);		// White
    	m_crBorder		= Color(103, 99, 114);		// Gray
    	m_crStart		= m_crBackground;			// White
    	m_crEnd			= Color(255, 0, 0);			// Red
    	m_crFontColor	= m_crBackground;			// White
    	
    	m_rtPadding.SetRect(2, 2, 2, 2);
    	SF.SetAlignment(StringAlignmentCenter);
    	SF.SetLineAlignment(StringAlignmentCenter);
    }
    
    CProgressCtrlEx::~CProgressCtrlEx()
    {
    	delete P;
    	delete S;
    	delete m_brFontColor;
    	delete m_memBitmap;
    	delete m_mDC;
    	delete m_Font;
    	delete m_Origin;	
    }
    
    
    BEGIN_MESSAGE_MAP(CProgressCtrlEx, CProgressCtrl)
    	ON_WM_PAINT()
    	ON_WM_ERASEBKGND()
    END_MESSAGE_MAP()
    
    // CProgressCtrlEx message handlers
    
    void CProgressCtrlEx::OnPaint()
    {
    	CPaintDC dc(this); // device context for painting
    	
    	InitObject(true);
    	Graphics G(dc);
    	G.DrawImage(m_memBitmap, 0, 0);
    }
    
    BOOL CProgressCtrlEx::OnEraseBkgnd(CDC* pDC)
    {
    	return true;
    }
    
    void CProgressCtrlEx::SetRange(int nLower, int nUpper)
    {
    	// 프로그래시브에 range를 설정
    	m_nLower			= nLower;
    	m_nUpper			= nUpper;
    	m_nCurrentPosition	= nLower;
    
    	CProgressCtrl::SetRange(nLower, nUpper);
    }
    
    void CProgressCtrlEx::SetRange32(int nLower, int nUpper)
    {
    	m_nLower			= nLower;
    	m_nUpper			= nUpper;
    	m_nCurrentPosition	= nLower;
    
    	CProgressCtrl::SetRange32(nLower, nUpper);
    }
    
    int CProgressCtrlEx::SetPos(int nPos)
    {
    	// 현재 위치를 설정
    	m_nCurrentPosition = nPos;
    	Process();
    
    	return (CProgressCtrl::SetPos(nPos));
    }
    
    int CProgressCtrlEx::SetStep(int nStep)
    {
    	m_nStep = nStep;
    
    	return (CProgressCtrl::SetStep(nStep));
    }
    
    int CProgressCtrlEx::StepIt(void)
    {
    	m_nCurrentPosition += m_nStep;
    
    	return (CProgressCtrl::StepIt());
    }
    
    void CProgressCtrlEx::SetBackgroundColor(Color crBackground)
    {
    	// 배경색을 설정 (기본 흰색)
    	m_crBackground = crBackground;
    }
    
    void CProgressCtrlEx::SetStartColor(Color crStart)
    {
    	// 그라이데이션 시작색 설정 (기본 흰색)
    	m_crStart = crStart;
    }
    
    void CProgressCtrlEx::SetEndColor(Color crEnd)
    {
    	// 그라이데이션 끝색 설정 (기본 빨강)
    	m_crEnd = crEnd;
    }
    
    void CProgressCtrlEx::SetPadding(CRect rtPadding)
    {
    	// 그라이데이션과 볼더 사이에 간격을 설정 (기본 2, 2, 2, 2)
    	m_rtPadding = rtPadding;
    }
    
    void CProgressCtrlEx::Process(void)
    {
    	InitObject();
    
    	int nMaxWidth = 0, nMaxHeight = 0, nCurrentWidth = 0;
    	int nStep			= 255;
    	float fPercentage	= 0.0;
    	float fStep			= 0.0;
    	CString szOutputString;
    
    	// 그래프 길이와 값에 따른 현재 위치에 계산
    	nMaxWidth	= m_rtCtrlSize.Width() - m_rtPadding.right - m_rtPadding.left;
    	nMaxHeight	= m_rtCtrlSize.Height() - m_rtPadding.bottom - m_rtPadding.top;
    	fStep		= static_cast<float>(nMaxWidth) / static_cast<float>(nStep);
    	
    	//TRACE("width :%d, height:%d\n", nMaxWidth, nMaxHeight);
    
    	fPercentage   = static_cast<float>(m_nCurrentPosition) / static_cast<float>(m_nUpper);
    	nCurrentWidth = static_cast<int>(fPercentage * static_cast<float>(nMaxWidth));
    
    	if (m_nMark == _PROGRESSCTRL_EX_PERCENTAGE)
    	{
    		szOutputString.Format(L"%d %%", static_cast<int>(fPercentage * 100));
    	}
    	else if (m_nMark == _PROGRESSCTRL_EX_COUNT)
    	{
    		szOutputString.Format(L"%d / %d", m_nCurrentPosition, m_nUpper);
    	}
    	
    	// 그라이던트 브러쉬 생성
    	LGB = new LinearGradientBrush(Rect(m_rtPadding.left-1, m_rtPadding.top, nCurrentWidth+1, nMaxHeight),
    					m_crStart, m_crEnd, LinearGradientModeHorizontal);
    
    	// 배경 / 테두리 / 그라이데이션 순으로 메모리 DC에 작성
    	m_mDC->FillRectangle(S, Rect(0, 0, m_rtCtrlSize.Width(), m_rtCtrlSize.Height()));
    	m_mDC->DrawRectangle(P, Rect(0, 0, m_rtCtrlSize.Width() - 1, m_rtCtrlSize.Height() - 1));
    	m_mDC->FillRectangle(LGB, Rect(m_rtPadding.left, m_rtPadding.top, nCurrentWidth, nMaxHeight));
    
    	if (m_nMark != _PROGRESSCTRL_EX_NONE)
    	{
    		m_mDC->DrawString(szOutputString, -1, m_Font, *m_Origin, &SF, m_brFontColor);
    	}
    
    	delete LGB;
    
    	static bool bData = false;
    	if (bData)
    	{
    		Invalidate();		
    	}
    	else
    	{
    		bData = true;
    	}
    }
    
    void CProgressCtrlEx::SetFontColor(Color crFontColor)
    {
    	m_crFontColor = crFontColor;
    }
    
    void CProgressCtrlEx::SetBorderColor(Color crOutLineColor)
    {
    	m_crBorder = crOutLineColor;
    }
    
    void CProgressCtrlEx::SetViewStatus(int nType)
    {
    	m_nMark = nType;
    }
    
    void CProgressCtrlEx::SetFontStyle(CString szFont, REAL nFontSize, int nFontStyle)
    {
    	//FontStyleRegular    = 0,
    	//FontStyleBold       = 1,
    	//FontStyleItalic     = 2,
    	//FontStyleBoldItalic = 3,
    	//FontStyleUnderline  = 4,
    	//FontStyleStrikeout  = 8
    
    	m_szFont	= szFont;
    	m_nFontSize = nFontSize;
    }
    
    void CProgressCtrlEx::InitObject(bool bCall)
    {
    	if (!m_bLoad)
    	{
    		GetClientRect(&m_rtCtrlSize);
    
    		P				= new Pen(m_crBorder, m_nPenWidth);
    		S				= new SolidBrush(m_crBackground);
    		m_brFontColor	= new SolidBrush(m_crFontColor);	// Black brush
    
    		m_memBitmap 	= new Bitmap(m_rtCtrlSize.Width(), m_rtCtrlSize.Height());
    		m_mDC			= new Graphics(m_memBitmap);
    		m_Font			= new Font(m_szFont, m_nFontSize, FontStyleRegular, UnitPixel);	
    		m_Origin		= new PointF(static_cast<REAL>(static_cast<float>(m_rtCtrlSize.Width()) / 2.0F),
    									 static_cast<REAL>(static_cast<float>(m_rtCtrlSize.Height()) / 2.0F));
    		m_bLoad			= true;
    		
    		if (bCall)
    			Process();
    	}
    }
    
    Header
    #pragma once
    #include "atltypes.h"
    
    // CProgressCtrlEx
    
    enum
    {
    	_PROGRESSCTRL_EX_NONE = 0,
    	_PROGRESSCTRL_EX_PERCENTAGE,
    	_PROGRESSCTRL_EX_COUNT
    };
    
    class CProgressCtrlEx : public CProgressCtrl
    {
    	DECLARE_DYNAMIC(CProgressCtrlEx)
    
    public:
    	CProgressCtrlEx();
    	virtual ~CProgressCtrlEx();
    	
    protected:
    	int m_nLower, m_nUpper, m_nStep, m_nCurrentPosition, m_nMark;
    	Color m_crBackground, m_crBorder, m_crStart, m_crEnd, m_crFontColor;
    	REAL m_nPenWidth, m_nFontSize;
    	CRect m_rtCtrlSize, m_rtPadding;
    	Pen* P;
    	SolidBrush* S;
    	Bitmap* m_memBitmap;
    	Graphics* m_mDC;
    	bool m_bLoad;
    	LinearGradientBrush* LGB;
    	Font* m_Font;
    	PointF* m_Origin;
    	SolidBrush* m_brFontColor;
    	StringFormat SF;
    	CString m_szFont;
    
    	afx_msg void OnPaint();	
    	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    	
    	DECLARE_MESSAGE_MAP()
    public:	
    	void SetRange(int nLower, int nUpper);
    	void SetRange32(int nLower, int nUpper);
    	int SetPos(int nPos);
    	int SetStep(int nStep);
    	int StepIt(void);
    	void SetBackgroundColor(Color crBackground);
    	void SetStartColor(Color crStart);
    	void SetEndColor(Color crEnd);
    	void SetPadding(CRect rtPadding);
    	void Process(void);
    	void SetFontColor(Color crFontColor);
    	void SetBorderColor(Color crOutLineColor);
    	void SetViewStatus(int nType);
    	void SetFontStyle(CString szFont, REAL nFontSize, int nFontStyle = FontStyleRegular);
    	void InitObject(bool bCall = false);
    };
    
    DOWNLOAD : progressex.jpg
    Filesize : 40.4Kb

    Comment


    입력하3 1502976265



    Locations of visitors to this page