📄 setcolor.cpp
字号:
// SetColor.cpp : implementation file
//
#include "stdafx.h"
#include "liming02.h"
#include "SetColor.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSetColor dialog
CSetColor::CSetColor(CWnd* pParent /*=NULL*/)
: CDialog(CSetColor::IDD, pParent)
{
//{{AFX_DATA_INIT(CSetColor)
//}}AFX_DATA_INIT
}
void CSetColor::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSetColor)
DDX_Control(pDX, IDC_SLIDERR, m_red);
DDX_Control(pDX, IDC_SLIDERG, m_green);
DDX_Control(pDX, IDC_SLIDERB, m_blue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSetColor, CDialog)
//{{AFX_MSG_MAP(CSetColor)
ON_WM_PAINT()
ON_WM_HSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSetColor message handlers
void CSetColor::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 CSetColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if(pScrollBar->GetDlgCtrlID ()==IDC_SLIDERR)
{
m_R=m_red.GetPos ();
Draw();
}
if(pScrollBar->GetDlgCtrlID ()==IDC_SLIDERG)
{
m_G=m_green.GetPos ();
Draw();
}
if(pScrollBar->GetDlgCtrlID ()==IDC_SLIDERB)
{
m_B=m_blue.GetPos ();
Draw();
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
//初始对话框
BOOL CSetColor::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_red.SetRange (0,255);
m_red.SetPos (0);
m_green.SetRange (0,255);
m_green.SetPos (0);
m_blue.SetRange (0,255);
m_blue.SetPos (0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//显示颜色的相关变化
void CSetColor::Draw()
{
CWnd* pWnd=GetDlgItem(IDC_DRAW);
CDC *pDC=pWnd->GetDC();
CBrush drawBrush;
drawBrush.CreateSolidBrush(RGB(m_R,m_G,m_B));
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 + -