Click here to Skip to main content
15,896,486 members
Articles / Web Development / HTML

CSSSandbox

Rate me:
Please Sign up or sign in to vote.
4.88/5 (13 votes)
12 Feb 2013CPOL6 min read 27K   1.3K   29  
A tool for simultaneous editing and viewing of CSS and HTML.
// DColors.cpp : implementation file
//

#include "stdafx.h"
#include "CSSSandbox.h"
#include "DColors.h"
#include "afxdialogex.h"


// DColors dialog

IMPLEMENT_DYNAMIC(DColors, CDialogEx)

DColors::DColors(CWnd* pParent /*=NULL*/)
	: CDialogEx(DColors::IDD, pParent)
{

}

DColors::~DColors()
{
}

void DColors::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BGCOLOR_BOX, bgColorBox);
	DDX_Control(pDX, IDC_FGCOLOR_BOX, fgColorBox);
}


BEGIN_MESSAGE_MAP(DColors, CDialogEx)
	ON_WM_CTLCOLOR()
	ON_STN_CLICKED(IDC_BGCOLOR_BOX, &DColors::OnStnClickedBgcolorBox)
	ON_STN_CLICKED(IDC_FGCOLOR_BOX, &DColors::OnStnClickedFgcolorBox)
END_MESSAGE_MAP()


// DColors message handlers


BOOL DColors::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  Add extra initialization here
	CreateBrushes();

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void DColors::CreateBrushes()
{
	if ((HBRUSH)bgColorBr != NULL)
		bgColorBr.DeleteObject();
	bgColorBr.CreateSolidBrush(bgColor);

	if ((HBRUSH)fgColorBr != NULL)
		fgColorBr.DeleteObject();
	fgColorBr.CreateSolidBrush(fgColor);
}

HBRUSH DColors::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	int ctrlID = pWnd->GetDlgCtrlID();

	if (ctrlID == IDC_BGCOLOR_BOX)
		return bgColorBr;
	else if (ctrlID == IDC_FGCOLOR_BOX)
		return fgColorBr;

	return hbr;
}


void DColors::OnStnClickedBgcolorBox()
{
	CColorDialog dlg(bgColor,CC_FULLOPEN|CC_RGBINIT|CC_SOLIDCOLOR);
	if (dlg.DoModal() != IDOK)
		return;
	bgColor = dlg.GetColor();
	CreateBrushes();
	Invalidate();
}


void DColors::OnStnClickedFgcolorBox()
{
	CColorDialog dlg(fgColor,CC_FULLOPEN|CC_RGBINIT|CC_SOLIDCOLOR);
	if (dlg.DoModal() != IDOK)
		return;
	fgColor = dlg.GetColor();
	CreateBrushes();
	Invalidate();
}

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)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions