End Google Ads 201810 - BS.net 01 --> Hello,

I'm trying to put a colour control into my dialog - a little box with a spectrum of colours, however I cannot get my dialog box to actually show the colour control.

I've put in a picture box into the dialog (IDC_COLOUR_CTRL), and am trying to place this colour spectrum in there. I dont know how to get it to show when i run it though!

Oh there is a little box (IDC_COLOUR) next to the colour spectrum that will show the colour you've picked. This is my cpp file:

#include "testcolour.h"


Ctestcolour::Ctestcolour():CDialog(Ctestcolour::IDD, pParent)

void Ctestcolour::DoDataExchange(CDataExchange* pDX)
{
DDX_Control(pDX, IDC_COLOUR_CTRL, bmpColourCtrl);
DDX_Control(pDX, IDC_COLOUR, bmpColour);
}
BEGIN_MESSAGE_MAP(Ctestcolour, CDialog)
ON_BN_CLICKED(IDC_COLOUR_CTRL, OnChooseColour)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


BOOL Ctestcolour::OnInitDialog()
{
mSelectedColour = RGB(255,0,0);

return TRUE;
}

void Ctestcolour::OnPaint()
{

CPaintDC dc(this);

CMemDC memDC(&dc, &m_Rect);

CRect ctrlRect;
bmpColourCtrl.GetWindowRect(ctrlRect);
ScreenToClient(ctrlRect);

CRect colRect;
bmpColour.GetWindowRect(colRect);
ScreenToClient(colRect);
}

for (int i=0; i!=ctrlRect.Width();++i)
{
memDC.FillSolidRect(ctrlRect.left+i,ctrlRect.top,1,ctrlRect.Height(),Hue((float)i,ctrlRect.Width())) ;
}
memDC.FillSolidRect(colRect.left,colRect.top,colRect.Width(),colRect.Height(),mSelectedColour);
}

COLOURREF Ctestcolour::Hue(float H, int range)
{
int r,g,b, Hi;
float H6,f;

H6 = 0.6f*H / range;
Hi = (int)floorf(H6);
f = H6 - Hi;
switch (Hi){
case 0:
r = 255;
g = (int)255*f);
b=0;
break;
case 1:
r = (int)(255*(1.0-f));
g=255;
b=0;
break;
case 2:
r=0;
g=255;
b=(int)(255*f);
break;
case 3:
r=0;
g=(int)(255*(1.0-f));
b=255;
break;
case 4:
r=(int)(255*f);
g=0;
b=255;
break;
default:
r=255;
g=0;
b=(int)(255*(1.0-f));
break;
}
return RGB(r,g,b);
}

void Ctestcolour::OnChooseColour()
{
CRect rect;
Cpoint pt;
bmpColourCtrl.GetWindowRect(rect);

m_colPickPos = pt.x - rect.left;

COLOURREF col = Hue((float)m_colPickPos,rect.Width());

mSelectedColour = col;

bmpColour.GetWindowRect(rect);
ScreenToClient(rect);
}
void Ctestcolour::IncrementColour(int amount)
{
CRect rect;
bmpColourCtrl.GetWindowRect(rect);

m_colPickPos = (m_colPickPos + rect.Width() + amount/30)% rect.Width();

COLOURREF col = Hue((float)m_colPickPos,rect.Width());
mSelectedColour = col;

bmpColour.GetWindowRect(rect);
ScreenToClient(rect);
InvalidateRect(rect, FALSE);
}

void Ctestcolour::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}

If anyone could help i would be very grateful. Penfold