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

XTimer - Timer and Stopwatch Utility with Source Code

Rate me:
Please Sign up or sign in to vote.
4.81/5 (33 votes)
20 Aug 2007CPOL3 min read 165.6K   6.7K   82  
XTimer provides countdown timer and stopwatch features in a compact MFC dialog app.
// XButtonXP.h  Version 1.2
//
// Author:  Hans Dietrich
//          hdietrich@gmail.com
//
// This software is released into the public domain.  You are free to use
// it in any way you like, except that you may not sell this source code.
//
// This software is provided "as is" with no expressed or implied warranty.
// I accept no liability for any damage or loss of business that this
// software may cause.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef  XBUTTONXP_H 
#define  XBUTTONXP_H 

#include "uxtheme.h"
#include "OddButton.h"

/////////////////////////////////////////////////////////////////////////////
// CXButtonXP window

class CXButtonXP : public COddButton
{
// Construction
public:
	CXButtonXP();
	virtual ~CXButtonXP();

// Attributes
public:
	enum ICON_ALIGNMENT
	{
		CENTER = 0,
		LEFT,
		RIGHT
	};

	void SetIconAlignment(ICON_ALIGNMENT ia) 
	{ 
		m_eIconAlignment = ia; 
		RedrawWindow();
	}
	BOOL GetToggle() { return m_bIsToggle; }
	void SetToggle(BOOL bIsToggle) 
	{ 
		m_bIsToggle = bIsToggle;
		m_bToggled  = FALSE;
		RedrawWindow();
	}
	BOOL GetToggleState() { return m_bToggled; }
	void SetToggleState(BOOL bToggled) { m_bToggled = bToggled; RedrawWindow(); }
	void EnableTheming(BOOL bEnable) 
	{ 
		m_bEnableTheming = bEnable; 
		if (m_bEnableTheming)
		{
			TRACE(_T("Theming will be enabled only on XP and only ")
				  _T("if the app is themed with a manifest file.\n"));
		}
		RedrawWindow();
	}
	BOOL IsThemed();


// Operations
public:
	void SetIcon(UINT nIDResource, ICON_ALIGNMENT ia = LEFT);
	void SetIcon(HICON hIcon, ICON_ALIGNMENT ia = LEFT);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CXButtonXP)
public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
	virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

// Implementation
protected:
	void DrawIcon(CDC *pDC, 
				  BOOL bHasText, 
				  RECT& rectItem, 
				  RECT& rectText, 
				  BOOL bIsPressed, 
				  BOOL bIsDisabled);

	void PrepareImageRect(BOOL bHasText, 
						  RECT& rectItem, 
						  RECT& rectText, 
						  BOOL bIsPressed, 
						  DWORD dwWidth, 
						  DWORD dwHeight, 
						  RECT& rectImage);


	BOOL			m_bFirstTime;
	BOOL			m_bMouseOverButton;
	HTHEME			m_hTheme;
	HICON			m_hIcon;
	ICON_ALIGNMENT	m_eIconAlignment;
	BOOL			m_bToggled;
	BOOL			m_bIsToggle;
	BOOL			m_bLButtonDown;
	BOOL			m_bSent;
	BOOL			m_bEnableTheming;

	// Generated message map functions
	//{{AFX_MSG(CXButtonXP)
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

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

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // XBUTTONXP_H 

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
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions