⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setcolordlg.cpp

📁 提供一个图形工具界面
💻 CPP
字号:
// SetColorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mdrowpen.h"
#include "SetColorDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// SetColorDlg dialog


SetColorDlg::SetColorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(SetColorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(SetColorDlg)
	//}}AFX_DATA_INIT
}


void SetColorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SetColorDlg)
	DDX_Control(pDX, IDC_RED, m_Red);
	DDX_Control(pDX, IDC_GREEN, m_Green);
	DDX_Control(pDX, IDC_BLUE, m_Blue);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(SetColorDlg, CDialog)
	//{{AFX_MSG_MAP(SetColorDlg)
	ON_WM_PAINT()
	ON_NOTIFY(NM_OUTOFMEMORY, IDC_BLUE, OnOutofmemoryBlue)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_BLUE, OnCustomdrawBlue)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_RED, OnCustomdrawRed)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_GREEN, OnCustomdrawGreen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SetColorDlg message handlers

void SetColorDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CWnd *pWnd = GetDlgItem(IDC_COLOR);
	pWnd->UpdateWindow();
	Draw();
	// TODO: Add your message handler code here
	
	// Do not call CDialog::OnPaint() for painting messages
}

BOOL SetColorDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_nBlueValue  = 0;
	m_nGreenValue = 0;
	m_nRedValue   = 0;
	// TODO: Add extra initialization here
	m_Blue.SetRange(0,255);
	m_Blue.SetPos(m_nBlueValue);

	m_Green.SetRange(0,255);
	m_Green.SetPos(m_nGreenValue);

	m_Red.SetRange(0,255);
	m_Red.SetPos(m_nRedValue);

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

void SetColorDlg::Draw()
{
	CWnd *pWnd = GetDlgItem(IDC_COLOR);
	CDC  *pDC  = pWnd->GetDC();
	CBrush brush;
	brush.CreateSolidBrush(RGB(m_nRedValue,m_nGreenValue,m_nBlueValue));
	CBrush *pOldBrush = pDC->SelectObject(&brush);
	CRect  rcClient;
	pWnd->GetClientRect(rcClient);
	pDC->Rectangle(rcClient);
	pDC->SelectObject(pOldBrush);
}

void SetColorDlg::OnOutofmemoryBlue(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	Draw();
	*pResult = 0;
}

void SetColorDlg::OnCustomdrawBlue(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	//Draw();
	*pResult = 0;
	m_nBlueValue = m_Blue.GetPos();
	Draw();
}

void SetColorDlg::OnCustomdrawRed(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
	m_nRedValue = m_Red.GetPos();
	Draw();
}

void SetColorDlg::OnCustomdrawGreen(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
	m_nGreenValue = m_Green.GetPos();
	Draw();
}

void SetColorDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -