Click here to Skip to main content
15,885,546 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 399.5K   11.5K   141  
C++ class library.
//
// Colorpicker sample.
//
// Shows the usage of the ClsColorPicker class.
// 
#include <classes/all.h> 
#include "resource.h"
 
#ifdef _DEBUG  
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
class ColorPickerDlg : public ClsDialog
{
	_NO_COPY( ColorPickerDlg ); 
public:
	// No-op constructor and destructor.
	ColorPickerDlg() {;}
	virtual ~ColorPickerDlg() {;}

protected:
	virtual LRESULT OnInitDialog( PROPSHEETPAGE *p )
	{
		// Attach (subclass) and setup the colorpickers.
		picker1.Attach( GetDlgItemHandle( IDC_COLOR ));
		picker1.SetHotFrame();
		picker1.ShowToolTip();
		picker1.Color() = RGB( 255, 0, 0 );
		
		picker2.Attach( GetDlgItemHandle( IDC_COLOR2 ));
		picker2.ShowToolTip();
		picker2.DropDownArrow() = TRUE;
		picker2.SetXPStyle( TRUE, TRUE );
		picker2.Color() = RGB( 0, 255, 0 );

		picker3.Attach( GetDlgItemHandle( IDC_COLOR3 ));
		picker3.ShowToolTip();
		picker3.SetHotTrack( FALSE );
		picker3.Color() = RGB( 0, 0, 255 );
		
		// Attach the buttons.
		about.Attach( GetDlgItemHandle( IDC_ABOUT ));
		about.SetHotFrame();
		
		ok.Attach( GetDlgItemHandle( IDOK ));
		ok.SetHotFrame();
		return ClsDialog::OnInitDialog( p );
	}

	virtual LRESULT OnCommand( UINT nNotifyCode, UINT nCtrlID, HWND hWndCtrl )
	{
		if ( nCtrlID == IDC_ABOUT )
		{
			// Show the about box.
			ClsMessageBox::MsgBox( *this,
					_T( "*&OK" ),
					_T( "The code for the \"" ) ISEQ_ITALIC _T( "ColourPopup" ) ISEQ_NORMAL _T( "\" is a version of the\n" )
					_T( "excellent original MFC code by Chris Maunder\n" )
					_T( "(" ) ISEQ_BOLD _T( "www.codeproject.com" ) ISEQ_NORMAL _T( ")\ntweaked to run with this class library ." ),
					_T( "\"ClsColorPicker\" Sample" ), ClsMessageBox::MBF_ICONINFORMATION );
			return 0;
		}
		return ClsDialog::OnCommand( nNotifyCode, nCtrlID, hWndCtrl );
	}
	
	ClsColorPicker picker1, picker2, picker3;
	ClsFlatButton about, ok;
};

// Entry point.
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd )
{
	int		rc = 0;

	// Setup app.
	if ( ClsGetApp()->Setup( hInstance, lpCmdLine, nShowCmd ))
	{
		// Check OS version.
		if ( ClsGetApp()->GetPlatformID() != VER_PLATFORM_WIN32_WINDOWS &&
		     ClsGetApp()->GetPlatformID() != VER_PLATFORM_WIN32_NT )
		{
			MessageBox( NULL, _T( "Windows 95/98/ME/NT/2000 required!" ), _T( "\"ClsColorPicker\" Sample" ), MB_OK );
			return NULL;
		}
		
		// Create and open the dialog.
		ColorPickerDlg	dlg;
		dlg.DoModal( IDD_COLORPICKER );
	}
	return rc;
}

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