📄 colorsetdlg.cpp
字号:
// ColorSetDlg.cpp : implementation file
//
#include "stdafx.h"
#include "zhangfujk02.h"
#include "ColorSetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorSetDlg dialog
CColorSetDlg::CColorSetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CColorSetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CColorSetDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CColorSetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CColorSetDlg)
DDX_Control(pDX, IDC_SLIDERB, m_blue);
DDX_Control(pDX, IDC_SLIDERG, m_green);
DDX_Control(pDX, IDC_SLIDERR, m_red);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CColorSetDlg, CDialog)
//{{AFX_MSG_MAP(CColorSetDlg)
ON_WM_HSCROLL()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorSetDlg message handlers
BOOL CColorSetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_red.SetRange(0,255);
m_red.SetPos(m_RValue);
m_green.SetRange(0,255);
m_green.SetPos(m_GValue);
m_blue.SetRange(0,255);
m_blue.SetPos(m_BValue);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CColorSetDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
//红色滚动条
if(pScrollBar->GetDlgCtrlID()==IDC_SLIDERR)
{
m_RValue=m_red.GetPos();
Draw();
}
//绿色滚动条
if(pScrollBar->GetDlgCtrlID()==IDC_SLIDERG)
{
m_GValue=m_green.GetPos();
Draw();
}
///蓝色滚动条
if(pScrollBar->GetDlgCtrlID()==IDC_SLIDERB)
{
m_BValue=m_blue.GetPos();
Draw();
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
//控件中绘图
void CColorSetDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CWnd* pWnd=GetDlgItem(IDC_DRAW);
pWnd->UpdateWindow();
Draw();
// Do not call CDialog::OnPaint() for painting messages
}
void CColorSetDlg::Draw()
{
CWnd* pWnd=GetDlgItem(IDC_DRAW);
CDC *pDC=pWnd->GetDC();
CBrush drawBrush;
drawBrush.CreateSolidBrush(RGB(m_RValue,m_GValue,m_BValue));
CBrush *pOldBrush=pDC->SelectObject(&drawBrush);
CRect rect;
pWnd->GetClientRect(&rect);
pDC->Rectangle(rect);
pDC->SelectObject(pOldBrush);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -