Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / MFC

The Ultimate Grid Home Page

,
Rate me:
Please Sign up or sign in to vote.
5.00/5 (122 votes)
14 Sep 2013CPOL10 min read 4.6M   81.9K   418  
The Ultimate Grid is now Open Source
/////////////////////////////////////////////////////////////////////////////
//	Skeleton Class for a Derived CUGCtrl class

#include "stdafx.h"
#include "resource.h"
#include "DropMonthCug.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(CDropMonthCug,CUGCtrl)
	//{{AFX_MSG_MAP(CDropMonthCug)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Standard CDropMonthCug construction/destruction
CDropMonthCug::CDropMonthCug()
{
	m_nYear = COleDateTime::GetCurrentTime().GetYear();
}

CDropMonthCug::~CDropMonthCug()
{
}

/////////////////////////////////////////////////////////////////////////////
//	OnSetup
//		This function is called just after the grid window 
//		is created or attached to a dialog item.
//		It can be used to initially setup the grid
void CDropMonthCug::OnSetup()
{
	int cols = 2,
		rows = 12;
	CString tempStr;
	CUGCell cell;
	TCHAR *monthInfo[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

	GetHeadingDefault( &cell );
	int hedingFontIndex = AddFont( "Arial", -13, 700 );
	cell.SetFont( GetFont( hedingFontIndex ));
	cell.SetTextColor( RGB(0,0,200));
	SetHeadingDefault( &cell );

	GetGridDefault( &cell );
	int gridFontIndex = AddFont( "Arial", -13, 400 );
	cell.SetFont( GetFont( gridFontIndex ));
	SetGridDefault( &cell );

	SetUserSizingMode( 0 );
	SetNumberRows( rows );
	SetNumberCols( cols );

	// The two scroll buttons in the top heading
	QuickSetCellType( -1, -1, UGCT_ARROW );
	QuickSetCellTypeEx( -1, -1, UGCT_ARROWLEFT );
	QuickSetCellType( 1, -1, UGCT_ARROW );
	QuickSetCellTypeEx( 1, -1, UGCT_ARROWRIGHT );

	// Month information
	for ( int nIndex = 0; nIndex < rows; nIndex ++ )
	{
		JoinCells( 0, nIndex, 1, nIndex );
		tempStr.Format( "%d", nIndex + 1 );
		QuickSetText( -1, nIndex, tempStr );
		QuickSetText( 0, nIndex, monthInfo[nIndex] );
	}
}

/////////////////////////////////////////////////////////////////////////////
//	OnGetCell
//		This message is sent everytime the grid needs to
//		draw a cell in the grid. At this point the cell
//		object has been populated with all of the information
//		that will be used to draw the cell. This information
//		can now be changed before it is used for drawing.
//	Warning:
//		This notification is called for each cell that needs to be painted
//		Placing complicated calculations here will slowdown the refresh speed.
//	Params:
//		col, row	- coordinates of cell currently drawing
//		cell		- pointer to the cell object that is being drawn
//	Return:
//		<none>
void CDropMonthCug::OnGetCell(int col,long row,CUGCell *cell)
{
	if ( col == 0 && row == -1 )
	{
		cell->SetPropertyFlags( cell->GetPropertyFlags()|UGCELL_DONOT_LOCALIZE );
		cell->SetNumber( m_nYear );
	}
}

/////////////////////////////////////////////////////////////////////////////
//	OnTH_LClicked
//		Sent whenever the user clicks the left mouse button within the top heading
//		this message is sent when the button goes down then again when the button goes up
//	Params:
//		col, row	- coordinates of a cell that received mouse click event
//		updn		- is TRUE if mouse button is 'down' and FALSE if button is 'up'
//		processed	- indicates if current event was processed by other control in the grid.
//		rect		- represents the CDC rectangle of cell in question
//		point		- represents the screen point where the mouse event was detected
//	Return:
//		<none>
void CDropMonthCug::OnTH_LClicked(int col,long row,int updn,RECT *rect,POINT *point,BOOL processed)
{
	UNREFERENCED_PARAMETER(row);
	UNREFERENCED_PARAMETER(*rect);
	UNREFERENCED_PARAMETER(*point);
	UNREFERENCED_PARAMETER(processed);

	if ( updn && col == 1 )
	{
		m_nYear ++;
		RedrawCell( 0, -1 );
	}
}

/////////////////////////////////////////////////////////////////////////////
//	OnTH_DClicked
//		Sent whenever the user double clicks the left mouse
//		button within the top heading
//	Params:
//		col, row	- coordinates of a cell that received mouse click event
//		processed	- indicates if current event was processed by other control in the grid.
//		rect		- represents the CDC rectangle of cell in question
//		point		- represents the screen point where the mouse event was detected
//	Return:
//		<none>
void CDropMonthCug::OnTH_DClicked(int col,long row,RECT *rect,POINT *point,BOOL processed)
{
	OnTH_LClicked( col, row, 1, rect, point, processed );
}


/////////////////////////////////////////////////////////////////////////////
//	OnCB_LClicked
//		Sent whenever the user clicks the left mouse button within the top corner button
//		this message is sent when the button goes down then again when the button goes up
//	Params:
//		updn		- is TRUE if mouse button is 'down' and FALSE if button is 'up'
//		processed	- indicates if current event was processed by other control in the grid.
//		rect		- represents the CDC rectangle of cell in question
//		point		- represents the screen point where the mouse event was detected
//	Return:
//		<none>
void CDropMonthCug::OnCB_LClicked(int updn,RECT *rect,POINT *point,BOOL processed)
{
	UNREFERENCED_PARAMETER(*rect);
	UNREFERENCED_PARAMETER(*point);
	UNREFERENCED_PARAMETER(processed);

	if ( updn )
	{
		m_nYear --;
		RedrawCell( 0, -1 );
	}
}

/////////////////////////////////////////////////////////////////////////////
//	OnCB_DClicked
//		Sent whenever the user double clicks the left mouse
//		button within the top corner button
//	Params:
//		processed	- indicates if current event was processed by other control in the grid.
//		rect		- represents the CDC rectangle of cell in question
//		point		- represents the screen point where the mouse event was detected
//	Return:
//		<none>
void CDropMonthCug::OnCB_DClicked(RECT *rect,POINT *point,BOOL processed)
{
	OnCB_LClicked( 1, NULL, NULL, processed );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions