📄 scrolldlg.cpp
字号:
// ScrollDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Ex_CommCtrls.h"
#include "ScrollDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScrollDlg dialog
CScrollDlg::CScrollDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScrollDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScrollDlg)
m_RValue = 0;
m_GValue = 0;
m_BValue = 0;
//}}AFX_DATA_INIT
}
void CScrollDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScrollDlg)
DDX_Control(pDX, IDC_SPIN2, m_Spin);
DDX_Control(pDX, IDC_SLIDER1, m_Slider);
DDX_Control(pDX, IDC_SCROLLBAR1, m_Scroll);
DDX_Text(pDX, IDC_EDIT1, m_RValue);
DDV_MinMaxInt(pDX, m_RValue, 0, 255);
DDX_Text(pDX, IDC_EDIT2, m_GValue);
DDV_MinMaxInt(pDX, m_GValue, 0, 255);
DDX_Text(pDX, IDC_EDIT3, m_BValue);
DDV_MinMaxInt(pDX, m_BValue, 0, 255);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScrollDlg, CDialog)
//{{AFX_MSG_MAP(CScrollDlg)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_WM_PAINT()
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit)
ON_WM_HSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScrollDlg message handlers
void CScrollDlg::OnChangeEdit()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!m_bEditOK) return;
UpdateData();
m_Scroll.SetScrollPos(m_RValue);
m_Slider.SetPos(m_GValue);
Draw();
}
void CScrollDlg::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CScrollDlg::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
}
BOOL CScrollDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_Scroll.SetScrollRange(0,255);
m_Scroll.SetScrollPos(m_RValue);
m_Slider.SetRange(0,255);
m_Slider.SetPos(m_GValue);
m_Spin.SetRange(0,255);
UpdateData(FALSE);
m_bEditOK=true;
// 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 CScrollDlg::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)
{
m_GValue=m_Slider.GetPos();
}
if (nID==IDC_SCROLLBAR1)
{
switch(nSBCode)
{
case SB_LINELEFT: m_RValue--;
break;
case SB_LINERIGHT: m_RValue++;
break;
case SB_PAGELEFT: m_RValue-=10;
break;
case SB_PAGERIGHT: m_RValue+=10;
break;
case SB_THUMBTRACK: m_RValue=nPos;
break;
}
if(m_RValue<0) m_RValue=0;
if(m_RValue>255) m_RValue=255;
m_Scroll.SetScrollPos(m_RValue);
}
UpdateData(FALSE);
Draw();
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CScrollDlg::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 rcClient;
pWnd->GetClientRect(rcClient);
pDC->Rectangle(rcClient);
pDC->SelectObject(pOldBrush);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -