Click here to Skip to main content
15,896,207 members
Articles / Desktop Programming / MFC

ClassLib, A C++ class library

Rate me:
Please Sign up or sign in to vote.
4.80/5 (32 votes)
25 May 2005CPOL8 min read 402.7K   11.5K   141  
C++ class library.
#ifndef _UPDOWN_H_
#define _UPDOWN_H_
//
// updown.h
//
// (C) Copyright 2000 Jan van den Baard.
//     All Rights Reserved.
//

#include "commoncontrol.h"

// A wrapper for the Up-Down common control.
class ClsUpDown : public ClsCommonControl
{
	_NO_COPY_PARAM( ClsUpDown, ClsCommonControl );
public:
	// Constructor.
	ClsUpDown() : ClsCommonControl( ICC_WIN95_CLASSES )
	{;}

	// Destructor.
	virtual ~ClsUpDown()
	{;}

	// Create an up-down control.
	inline BOOL Create( ClsWindow *parent, ClsRect& rBounds, UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE )
	{
		_ASSERT( m_hWnd == NULL ); // May not be valid.

		// Create the control.
		return ClsCommonControl::Create( 0, UPDOWN_CLASS, NULL, dwStyle, rBounds, parent ? parent->GetSafeHWND() : NULL, ( HMENU )( UINT_PTR )nID );
	}

	// Get accelerator information.
	inline UINT GetAccel( int cAccel, LPUDACCEL pAccelArray ) const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( UINT )::SendMessage( m_hWnd, UDM_GETACCEL, cAccel, ( LPARAM )pAccelArray );
	}

	// Get the current radix base,
	inline UINT GetBase() const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( UINT )::SendMessage( m_hWnd, UDM_GETBASE, 0, 0 );
	}

	// Get the buddy window.
	inline HWND GetBuddy() const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( HWND )::SendMessage( m_hWnd, UDM_GETBUDDY, 0, 0 );
	}

	// Get the position.
	inline DWORD GetPos() const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( DWORD )::SendMessage( m_hWnd, UDM_GETPOS, 0, 0 );
	}

	// Get the range.
	inline DWORD GetRange() const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( DWORD )::SendMessage( m_hWnd, UDM_GETRANGE, 0, 0 );
	}

	// Get the range.
	inline void GetRange32( int& nLow, int& nHight ) const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		::SendMessage( m_hWnd, UDM_GETRANGE32, ( WPARAM )&nLow, ( LPARAM )&nHight );
	}

	// Get the unicode format.
	inline BOOL GetUnicodeFormat() const
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( BOOL )::SendMessage( m_hWnd, UDM_GETUNICODEFORMAT, 0, 0 );
	}

	// Set accelerators.
	inline BOOL SetAccel( int nAccel, LPUDACCEL pAccelArray )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( BOOL )SendMessage( UDM_SETACCEL, nAccel, ( LPARAM )pAccelArray );
	}

	// Set the radix base.
	inline UINT SetBase( UINT nBase )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( UINT )SendMessage( UDM_SETBASE, nBase );
	}

	// Set the buddy.
	inline HWND SetBuddy( HWND hWndBuddy )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( HWND )SendMessage( UDM_SETBUDDY, ( WPARAM )hWndBuddy );
	}

	// Set the position.
	inline int SetPos( int nPos )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( int )SendMessage( UDM_SETPOS, 0, MAKELONG( nPos, 0 ));
	}

	// Set the range.
	inline void SetRange( int nLow, int nHigh )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		SendMessage( UDM_SETRANGE, 0, MAKELONG( nHigh, nLow ));
	}

	// Set the range.
	inline void SetRange32( int nLow, int nHigh )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		SendMessage( UDM_SETRANGE32, nLow, nHigh );
	}

	// Set unicode flag.
	inline BOOL SetUnicodeFormat( BOOL bUnicode )
	{
		_ASSERT_VALID( GetSafeHWND() ); // Must be valid.

		return ( BOOL )SendMessage( UDM_SETUNICODEFORMAT, bUnicode );
	}
protected:
	// Overidables.
	virtual LRESULT OnDeltaPos( LPNMUPDOWN pUpDown, BOOL& bNotifyParent )
	{ return 0; }

	// Reflected notification handler which will call
	// the virtual notification handlers.
	virtual LRESULT OnReflectedNotify( LPNMHDR pNMHDR, BOOL& bNotifyParent )
	{
		// Evaluate notification code.
		if ( pNMHDR->code == UDN_DELTAPOS )
			return OnDeltaPos(( LPNMUPDOWN )pNMHDR, bNotifyParent );

		// Call the base class.
		return ClsCommonControl::OnReflectedNotify( pNMHDR, bNotifyParent );
	}
};

#endif // _UPDOWN_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)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

Comments and Discussions