www.pudn.com > PercentageCtrl.rar > PercentageCtrlDemoDlg.cpp


// PercentageCtrlDemoDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "PercentageCtrlDemo.h" 
#include "PercentageCtrlDemoDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
extern const UINT PERCENTAGE_CHANGED; 
 
///////////////////////////////////////////////////////////////////////////// 
// CPercentageCtrlDemoDlg dialog 
 
CPercentageCtrlDemoDlg::CPercentageCtrlDemoDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CPercentageCtrlDemoDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CPercentageCtrlDemoDlg) 
	m_1 = 25; 
	m_2 = 25; 
	m_3 = 25; 
	m_4 = 25; 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CPercentageCtrlDemoDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CPercentageCtrlDemoDlg) 
	DDX_Text(pDX, IDC_EDIT1, m_1); 
	DDX_Text(pDX, IDC_EDIT2, m_2); 
	DDX_Text(pDX, IDC_EDIT3, m_3); 
	DDX_Text(pDX, IDC_EDIT4, m_4); 
	//}}AFX_DATA_MAP 
	DDX_Control(pDX, IDC_PERCENTAGE2, m_percentage2); 
} 
 
BEGIN_MESSAGE_MAP(CPercentageCtrlDemoDlg, CDialog) 
	//{{AFX_MSG_MAP(CPercentageCtrlDemoDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	//}}AFX_MSG_MAP 
	ON_REGISTERED_MESSAGE(PERCENTAGE_CHANGED,OnPercentageChanged) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPercentageCtrlDemoDlg message handlers 
 
BOOL CPercentageCtrlDemoDlg::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 
	 
	CRect r (25,25,400,60); 
	m_percentage.Create(NULL,NULL,WS_VISIBLE | WS_BORDER,r,this,IDC_PERCENTAGE); 
 
	m_percentage.SetMultiplier(0.1); 
	m_percentage.SetOptions(PC_HORIZONTAL | PC_ALWAYSSHOWTEXT); 
 
	m_percentage.AddBlock(250,"%0.1f%%",RGB(200,255,255)); 
	m_percentage.AddBlock(250,"%0.1f%%",RGB(255,200,255)); 
	m_percentage.AddBlock(250,"%0.1f%%",RGB(255,255,200)); 
	m_percentage.AddBlock(250,"%0.1f%%",RGB(180,180,180)); 
 
	m_percentage2.SetOptions(PC_VERTICAL | PC_VERTICALTEXT | PC_TEXTELLIPSIS); 
	m_percentage2.AddBlock(1,"",RGB(100,100,100)); 
	m_percentage2.AddBlock(3,"Progress",RGB(0,0,255)); 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
 
void CPercentageCtrlDemoDlg::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 CPercentageCtrlDemoDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
LRESULT CPercentageCtrlDemoDlg::OnPercentageChanged(WPARAM WParam, LPARAM LParam) 
{ 
	if ((HWND)WParam == m_percentage.m_hWnd) 
	{ 
		double multiplier=m_percentage.GetMultiplier(); 
 
		switch ((int)LParam) 
		{ 
		case 0: 
			m_1=m_percentage.GetWeight(0)*multiplier; 
			m_2=m_percentage.GetWeight(1)*multiplier; 
			break; 
		case 1: 
			m_2=m_percentage.GetWeight(1)*multiplier; 
			m_3=m_percentage.GetWeight(2)*multiplier; 
			break; 
		case 2: 
			m_3=m_percentage.GetWeight(2)*multiplier; 
			m_4=m_percentage.GetWeight(3)*multiplier; 
			break; 
		default: 
			ASSERT(0); 
			break; 
		} 
 
		UpdateData(FALSE); 
	} 
	return 0; 
}