class CBoutonCouleur		{
public:
	int posX, posY, selCouleur;
	CHOOSECOLOR cc;
	unsigned char *ptr;
	char str[1000];
	int r,v,b,sel;
	LPDRAWITEMSTRUCT lpdis;
	HBRUSH hbr;
	HPEN hpen;
	HWND hBouton;
	RECT rect;
	POINT pt;
	COLORREF couleurs[16];

	CBoutonCouleur()		{
	}
	~CBoutonCouleur()		{
	}

	LRESULT OnDrawItem(HWND hDlg, LPARAM lParam)			{
		lpdis=(LPDRAWITEMSTRUCT) lParam;
		switch (lpdis->CtlID)	{
			case IDC_BOUTONCOULEUR:
				ptr=(unsigned char*)&cc.rgbResult;
				r=*ptr++;
				v=*ptr++;
				b=*ptr++;
				//Sélectionné, cliqué
				if (lpdis->itemState & ODS_SELECTED)		{
					hbr=CreateSolidBrush(RGB(r/2,v/2,b/2));
					hpen=CreatePen(PS_SOLID,5,RGB(r/4,v/4,b/4));
					SelectObject(lpdis->hDC,hpen);
					SelectObject(lpdis->hDC,hbr);
					Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,lpdis->rcItem.right,lpdis->rcItem.bottom);
					DeleteObject(hbr);
					DeleteObject(hpen);
					selCouleur=0;
				}
				//Sélectionné
				else if (selCouleur)		{
					hbr=CreateSolidBrush(RGB((r+0x1ff)/3,(v+0x1ff)/3,(b+0x1ff)/3));
					hpen=CreatePen(PS_SOLID,5,RGB((r+0x1ff)/4,(v+0x1ff)/4,(b+0x1ff)/4));
					SelectObject(lpdis->hDC,hpen);
					SelectObject(lpdis->hDC,hbr);
					Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,lpdis->rcItem.right,lpdis->rcItem.bottom);
					DeleteObject(hbr);
					DeleteObject(hpen);
				}
				else	{
					hbr=CreateSolidBrush(RGB(r,v,b));
					hpen=CreatePen(PS_SOLID,5,RGB(r/2,v/2,b/2));
					SelectObject(lpdis->hDC,hpen);
					SelectObject(lpdis->hDC,hbr);
					Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,lpdis->rcItem.right,lpdis->rcItem.bottom);
					DeleteObject(hbr);
					DeleteObject(hpen);
/*					if (lpdis->itemState & ODS_FOCUS)			{
//						hbr=CreateSolidBrush(RGB(r,v,b));
						hpen=CreatePen(PS_SOLID,1,RGB(255,255,255));
						SelectObject(lpdis->hDC, GetStockObject(NULL_BRUSH));
						SelectObject(lpdis->hDC, hpen);
						Rectangle(lpdis->hDC,lpdis->rcItem.left+1,lpdis->rcItem.top+1,lpdis->rcItem.right-1,lpdis->rcItem.bottom-1);
					}*/
				}
				return TRUE;
		}
		return FALSE;
	}

	void OnInit(HWND hwndBouton)		{
		CHOOSECOLOR stdCC={
			sizeof(CHOOSECOLOR),
			NULL,
			NULL,
			0,
			couleurs,
			CC_ANYCOLOR|CC_FULLOPEN|CC_RGBINIT,
			NULL,
			NULL,
			NULL
		};
		posX=0, posY=0, selCouleur=0;
		memcpy(&cc, &stdCC, sizeof(stdCC));
		selCouleur=0;
		hBouton=hwndBouton;
	}

	void OnClick(HWND hDlg)			{
		cc.hwndOwner=hDlg;
		ChooseColor(&cc);
		selCouleur=0;
		InvalidateRect(hDlg,NULL,0);
	}

	void OnSetCursor(HWND hDlg, WPARAM wParam)		{
		int oldSelCouleur=selCouleur;
		if ((HWND)wParam==hBouton)
			selCouleur=1;
		else
			selCouleur=0;
		//Changé?
		if (selCouleur!=oldSelCouleur)
			InvalidateRect(hBouton, NULL, 0);
	}

};

