Click here to Skip to main content
16,006,378 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to get color Pin
huynhnb5-Jul-06 21:58
huynhnb5-Jul-06 21:58 
GeneralRe: How to get color Pin
Hamid_RT5-Jul-06 22:10
Hamid_RT5-Jul-06 22:10 
GeneralRe: How to get color Pin
Sarath C5-Jul-06 22:29
Sarath C5-Jul-06 22:29 
GeneralRe: How to get color Pin
Hamid_RT5-Jul-06 22:37
Hamid_RT5-Jul-06 22:37 
GeneralRe: How to get color Pin
Sarath C5-Jul-06 22:30
Sarath C5-Jul-06 22:30 
GeneralRe: How to get color Pin
Michael Dunn5-Jul-06 22:46
sitebuilderMichael Dunn5-Jul-06 22:46 
GeneralRe: How to get color Pin
huynhnb5-Jul-06 23:05
huynhnb5-Jul-06 23:05 
AnswerRe: How to get color Pin
Justin Tay6-Jul-06 0:22
Justin Tay6-Jul-06 0:22 
I had some time, and it didn't look difficult so...
Tested on Windows XP. Modify to taste.

CColorDialogEx.h
#pragma once
#include "afxwin.h"

// CColorDialogEx
class CColorDialogEx : public CColorDialog
{
	DECLARE_DYNAMIC(CColorDialogEx)

public:
	CColorDialogEx(COLORREF clrInit = 0, DWORD dwFlags = 0, CWnd* pParentWnd = NULL);
	virtual ~CColorDialogEx();

protected:
	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);

	CEdit m_editRed;
	CEdit m_editGreen;
	CEdit m_editBlue;

private:
	void UpdateHexValues();
};


CColorDialogEx.cpp
// ColorDialogEx.cpp : implementation file
//
#include "stdafx.h"
#include "ColorDialogEx.h"
#include ".\colordialogex.h"

// CColorDialogEx

IMPLEMENT_DYNAMIC(CColorDialogEx, CColorDialog)
CColorDialogEx::CColorDialogEx(COLORREF clrInit, DWORD dwFlags, CWnd* pParentWnd) :
	CColorDialog(clrInit, dwFlags, pParentWnd)
{
}

CColorDialogEx::~CColorDialogEx()
{
}

BEGIN_MESSAGE_MAP(CColorDialogEx, CColorDialog)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

// CColorDialogEx message handlers
BOOL CColorDialogEx::OnInitDialog()
{
	CColorDialog::OnInitDialog();

	// TODO:  Add extra initialization here

	CWnd *pRed = GetDlgItem(706);
	CWnd *pGreen = GetDlgItem(707);
	CWnd *pBlue = GetDlgItem(708);

	CRect rcRed;
	CRect rcGreen;
	CRect rcBlue;

	pRed->GetWindowRect(&rcRed);
	ScreenToClient(&rcRed);

	pGreen->GetWindowRect(&rcGreen);
	ScreenToClient(&rcGreen);

	pBlue->GetWindowRect(&rcBlue);
	ScreenToClient(&rcBlue);

	pRed->ShowWindow(SW_HIDE);
	pGreen->ShowWindow(SW_HIDE);
	pBlue->ShowWindow(SW_HIDE);

	m_editRed.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP , rcRed, this, 1000);
	m_editGreen.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ,rcGreen, this, 2000);
	m_editBlue.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL,  ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP , rcBlue, this, 3000);

	m_editRed.SetFont(GetFont());
	m_editGreen.SetFont(GetFont());
	m_editBlue.SetFont(GetFont());

	UpdateHexValues();

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

void CColorDialogEx::UpdateHexValues()
{
	CWnd *pRed = GetDlgItem(706);
	CWnd *pGreen = GetDlgItem(707);
	CWnd *pBlue = GetDlgItem(708);

	CString strTemp;
	int nTemp;
	pRed->GetWindowText(strTemp);
	nTemp = _ttoi(strTemp);
	strTemp.Format(_T("%02X"), nTemp);
	m_editRed.SetWindowText(strTemp);

	pGreen->GetWindowText(strTemp);
	nTemp = _ttoi(strTemp);
	strTemp.Format(_T("%02X"), nTemp);
	m_editGreen.SetWindowText(strTemp);

	pBlue->GetWindowText(strTemp);
	nTemp = _ttoi(strTemp);
	strTemp.Format(_T("%02X"), nTemp);
	m_editBlue.SetWindowText(strTemp);
}

void CColorDialogEx::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CColorDialog::OnLButtonDown(nFlags, point);
	UpdateHexValues();
}

void CColorDialogEx::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CColorDialog::OnMouseMove(nFlags, point);
	if(GetCapture() == this)
	{
		UpdateHexValues();
	}
}

GeneralRe: How to get color Pin
huynhnb6-Jul-06 0:54
huynhnb6-Jul-06 0:54 
Questionhow we can compare the dialog length to screen length Pin
vasusree5-Jul-06 21:15
vasusree5-Jul-06 21:15 
AnswerRe: how we can compare the dialog length to screen length /*modified*/ Pin
Hamid_RT5-Jul-06 21:28
Hamid_RT5-Jul-06 21:28 
GeneralRe: how we can compare the dialog length to screen length Pin
vasusree5-Jul-06 21:32
vasusree5-Jul-06 21:32 
GeneralRe: how we can compare the dialog length to screen length Pin
Hamid_RT5-Jul-06 21:45
Hamid_RT5-Jul-06 21:45 
GeneralRe: how we can compare the dialog length to screen length Pin
vasusree5-Jul-06 23:33
vasusree5-Jul-06 23:33 
GeneralRe: how we can compare the dialog length to screen length Pin
Hamid_RT6-Jul-06 1:01
Hamid_RT6-Jul-06 1:01 
AnswerRe: how we can compare the dialog length to screen length Pin
Weiye Chen5-Jul-06 21:47
Weiye Chen5-Jul-06 21:47 
QuestionLPINT causes Exception Pin
Checker20035-Jul-06 21:12
Checker20035-Jul-06 21:12 
AnswerRe: LPINT causes Exception Pin
Sarath C5-Jul-06 21:25
Sarath C5-Jul-06 21:25 
GeneralRe: LPINT causes Exception Pin
Checker20035-Jul-06 21:30
Checker20035-Jul-06 21:30 
GeneralRe: LPINT causes Exception Pin
Justin Tay5-Jul-06 22:27
Justin Tay5-Jul-06 22:27 
QuestionUpdateWindow is required? Pin
Sarath C5-Jul-06 20:35
Sarath C5-Jul-06 20:35 
AnswerRe: UpdateWindow is required? Pin
Hamid_RT5-Jul-06 20:41
Hamid_RT5-Jul-06 20:41 
GeneralRe: UpdateWindow is required? Pin
Sarath C5-Jul-06 20:50
Sarath C5-Jul-06 20:50 
GeneralRe: UpdateWindow is required? Pin
Sarath C5-Jul-06 20:55
Sarath C5-Jul-06 20:55 
GeneralRe: UpdateWindow is required? Pin
Hamid_RT5-Jul-06 21:25
Hamid_RT5-Jul-06 21:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.