pencolor.cpp
来自「计算机图形学实验中综合使用鼠标、菜单、橡皮条等交互技术实现直线、圆和矩形等基本图」· C++ 代码 · 共 122 行
CPP
122 行
// PenColor.cpp : implementation file
//
#include "stdafx.h"
#include "MyDraw.h"
#include "PenColor.h"
#include "MyDrawDoc.h"
#include "MyDrawView.h"
#include "afxtempl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPenColor dialog
CPenColor::CPenColor(CWnd* pParent /*=NULL*/)
: CDialog(CPenColor::IDD, pParent)
{
//{{AFX_DATA_INIT(CPenColor)
m_nRed = 0;
m_nBlue = 0;
m_nGreen = 0;
//}}AFX_DATA_INIT
}
void CPenColor::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPenColor)
DDX_Control(pDX, IDC_SLIDER3, m_sliderGreen);
DDX_Control(pDX, IDC_SLIDER2, m_sliderBlue);
DDX_Control(pDX, IDC_SLIDER1, m_sliderRed);
DDX_Slider(pDX, IDC_SLIDER1, m_nRed);
DDX_Slider(pDX, IDC_SLIDER2, m_nBlue);
DDX_Slider(pDX, IDC_SLIDER3, m_nGreen);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPenColor, CDialog)
//{{AFX_MSG_MAP(CPenColor)
ON_WM_HSCROLL()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPenColor message handlers
BOOL CPenColor::OnInitDialog()
{
CDialog::OnInitDialog();
m_sliderRed.SetRange(0,255);
m_sliderBlue.SetRange(0,255);
m_sliderGreen.SetRange(0,255);
m_nRed=m_nBlue=m_nGreen=0;
UpdateData(FALSE);
// 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 CPenColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int nID=pScrollBar->GetDlgCtrlID();
if(nID==IDC_SLIDER1){
if(nSBCode==SB_THUMBTRACK){
m_nRed=nPos;
}
}
else if(nID==IDC_SLIDER2){
if(nSBCode==SB_THUMBTRACK){
m_nBlue=nPos;
}
}
else if(nID==IDC_SLIDER3){
if(nSBCode==SB_THUMBTRACK){
m_nGreen=nPos;
}
}
if(m_nRed<=0)m_nRed=0;
if(m_nRed>=255)m_nRed=255;
if(m_nBlue<=0)m_nBlue=0;
if(m_nBlue>=255)m_nBlue=255;
if(m_nGreen<=0)m_nGreen=0;
if(m_nGreen>=255)m_nGreen=255;
Invalidate();
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
/*void CPenColor::OnOK()
{
// TODO: Add extra validation here
//CMyDrawDoc* pDoc = GetDocument();
pDoc->DocRed=m_nRed;
pDoc->DocBlue=m_nBlue;
pDoc->DocGreen=m_nGreen;
CDialog::OnOK();
}*/
HBRUSH CPenColor::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
UpdateData(TRUE);
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?