![](http://img.blog.itpub.net/blog/attachment/201311/6/27660822_1383727236CJD2.jpg?x-oss-process=style/bb)
![](http://img.blog.itpub.net/blog/attachment/201311/6/27660822_13837272380BiF.jpg?x-oss-process=style/bb)
![](http://img.blog.itpub.net/blog/attachment/201311/6/27660822_13837272434hOk.jpg?x-oss-process=style/bb)
// SCORLLBARDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SCORLLBAR.h"
#include "SCORLLBARDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CSCORLLBARDlg dialog
CSCORLLBARDlg::CSCORLLBARDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSCORLLBARDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSCORLLBARDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSCORLLBARDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSCORLLBARDlg)
DDX_Control(pDX, IDC_SCROLLBAR3, m_Blue_ScrollBar);
DDX_Control(pDX, IDC_SCROLLBAR2, m_Green_ScrollBar);
DDX_Control(pDX, IDC_SCROLLBAR1, m_Red_ScrollBar);
DDX_Control(pDX, IDC_EDIT3, m_Edit3);
DDX_Control(pDX, IDC_EDIT2, m_Edit2);
DDX_Control(pDX, IDC_EDIT1, m_Edit1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSCORLLBARDlg, CDialog)
//{{AFX_MSG_MAP(CSCORLLBARDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CSCORLLBARDlg message handlers
BOOL CSCORLLBARDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_Red_ScrollBar.SetScrollRange(0,255); // 设定Red滚动条的滚动范围
m_Green_ScrollBar.SetScrollRange(0,255); // 设定Green滚动条的滚动范围
m_Blue_ScrollBar.SetScrollRange(0,255); // 设定Blue滚动条的滚动范围
m_Red_ScrollBar.SetScrollPos(100); // 设定Red滚动条当前位置
m_Green_ScrollBar.SetScrollPos(100); // 设定Green滚动条当前位置
m_Blue_ScrollBar.SetScrollPos(100); // 设定Blue滚动条当前位置
char sPos[10]; //
itoa(m_Red_ScrollBar.GetScrollPos(),sPos,10); // 字符与整型转换
m_Edit1.SetWindowText(sPos); // 将当前Red滚动条的位置输出
itoa(m_Green_ScrollBar.GetScrollPos(),sPos,10);//
m_Edit2.SetWindowText(sPos); // 将当前Green滚动条的位置输出
itoa(m_Blue_ScrollBar.GetScrollPos(),sPos,10); //
m_Edit3.SetWindowText(sPos); // 将当前Blue滚动条的位置输出
return TRUE; //
}
void CSCORLLBARDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSCORLLBARDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSCORLLBARDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSCORLLBARDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
char sPos[10]; //记录滚动条位置的字符数组
int iRedNowPos,iGreenNowPos,iBlueNowPos; //记录滚动条的整型数
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //获得Red滚动条当前位置
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//获得Green滚动条当前位置
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos(); //获得Blue滚动条当前位置
if(pScrollBar==&m_Red_ScrollBar) //对红色滚动条进行操作
{
switch(nSBCode)
{
case SB_THUMBTRACK: //拖动滚动条的滑块
m_Red_ScrollBar.SetScrollPos(nPos); //设定滚动条滑块的位置
iRedNowPos=nPos;
break;
case SB_LINEDOWN: //单击向下按钮
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos+1; //位置量加一
if(iRedNowPos>255)
iRedNowPos=255;
break;
case SB_LINEUP: //单击向上按钮
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos-1; //位置量减一
if(iRedNowPos<0)
iRedNowPos=0;
break;
case SB_PAGEDOWN: //单击向上按钮和滑块之间的区域
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos+10; //位置量+10
if(iRedNowPos>255)
iRedNowPos=255;
break;
case SB_PAGEUP: //单击向下按钮和滑块之间的区域
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos-10; //位置量-10
if(iRedNowPos<0)
iRedNowPos=0;
break;
}
}
if(pScrollBar==&m_Green_ScrollBar) //对绿色滚动条进行操作
{
switch(nSBCode)
{
case SB_THUMBTRACK: //拖动滚动条的滑块
m_Green_ScrollBar.SetScrollPos(nPos); //设定滚动条滑块的位置
iGreenNowPos=nPos;
break;
case SB_LINEDOWN: //单击向下按钮
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos+1; //位置量加一
if(iGreenNowPos>255)
iGreenNowPos=255;
break;
case SB_LINEUP: //单击向上按钮
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos-1; //位置量减一
if(iGreenNowPos<0)
iGreenNowPos=0;
break;
case SB_PAGEDOWN: //单击向上按钮和滑块之间的区域
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos+10; //位置量+10
if(iGreenNowPos>255)
iGreenNowPos=255;
break;
case SB_PAGEUP: //单击向下按钮和滑块之间的区域
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos-10; //位置量-10
if(iGreenNowPos<0)
iGreenNowPos=0;
break;
}
}
if(pScrollBar==&m_Blue_ScrollBar) //对蓝色滚动条进行操作
{
switch(nSBCode)
{
case SB_THUMBTRACK: //拖动滚动条的滑块
m_Blue_ScrollBar.SetScrollPos(nPos); //设定滚动条滑块的位置
iBlueNowPos=nPos;
break;
case SB_LINEDOWN: //单击向下按钮
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos+1; //位置量加一
if(iBlueNowPos>255)
iBlueNowPos=255;
break;
case SB_LINEUP: //单击向上按钮
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos-1; //位置量减一
if(iBlueNowPos<0)
iBlueNowPos=0;
break;
case SB_PAGEDOWN: //单击向上按钮和滑块之间的区域
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos+10; //位置量+10
if(iBlueNowPos>255)
iBlueNowPos=255;
break;
case SB_PAGEUP: //单击向下按钮和滑块之间的区域
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos-10; //位置量-10
if(iBlueNowPos<0)
iBlueNowPos=0;
break;
}
}
m_Red_ScrollBar.SetScrollPos(iRedNowPos);
itoa(iRedNowPos,sPos,10);
m_Edit1.SetWindowText(sPos);
m_Green_ScrollBar.SetScrollPos(iGreenNowPos);
itoa(iGreenNowPos,sPos,10);
m_Edit2.SetWindowText(sPos);
m_Blue_ScrollBar.SetScrollPos(iBlueNowPos);
itoa(iBlueNowPos,sPos,10);
m_Edit3.SetWindowText(sPos);
m_Red_ScrollBar.SetScrollPos(iRedNowPos);
itoa(iRedNowPos,sPos,10);
m_Edit1.SetWindowText(sPos);
m_Green_ScrollBar.SetScrollPos(iGreenNowPos);
itoa(iGreenNowPos,sPos,10);
m_Edit2.SetWindowText(sPos);
m_Blue_ScrollBar.SetScrollPos(iBlueNowPos);
itoa(iBlueNowPos,sPos,10);
m_Edit3.SetWindowText(sPos);
CDC *pDC=GetDC(); //得到设备环境句柄
CBrush newBrush; //定义新画刷
CPen newPen; //定义新画笔
newBrush.CreateSolidBrush(RGB(iRedNowPos,iGreenNowPos,iBlueNowPos));
newPen.CreatePen(PS_SOLID,1,RGB(iRedNowPos,iGreenNowPos,iBlueNowPos));
pDC->SelectObject(&newBrush); //选入新画刷
pDC->SelectObject(&newPen); //选入新画笔
pDC->Rectangle(50,100,280,172); //左间距上间距,右间距下间距.
ReleaseDC(pDC);
CDialog::OnVScroll(nSBCode,nPos,pScrollBar);
}
void CSCORLLBARDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
//
#include "stdafx.h"
#include "SCORLLBAR.h"
#include "SCORLLBARDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CSCORLLBARDlg dialog
CSCORLLBARDlg::CSCORLLBARDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSCORLLBARDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSCORLLBARDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSCORLLBARDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSCORLLBARDlg)
DDX_Control(pDX, IDC_SCROLLBAR3, m_Blue_ScrollBar);
DDX_Control(pDX, IDC_SCROLLBAR2, m_Green_ScrollBar);
DDX_Control(pDX, IDC_SCROLLBAR1, m_Red_ScrollBar);
DDX_Control(pDX, IDC_EDIT3, m_Edit3);
DDX_Control(pDX, IDC_EDIT2, m_Edit2);
DDX_Control(pDX, IDC_EDIT1, m_Edit1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSCORLLBARDlg, CDialog)
//{{AFX_MSG_MAP(CSCORLLBARDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CSCORLLBARDlg message handlers
BOOL CSCORLLBARDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_Red_ScrollBar.SetScrollRange(0,255); // 设定Red滚动条的滚动范围
m_Green_ScrollBar.SetScrollRange(0,255); // 设定Green滚动条的滚动范围
m_Blue_ScrollBar.SetScrollRange(0,255); // 设定Blue滚动条的滚动范围
m_Red_ScrollBar.SetScrollPos(100); // 设定Red滚动条当前位置
m_Green_ScrollBar.SetScrollPos(100); // 设定Green滚动条当前位置
m_Blue_ScrollBar.SetScrollPos(100); // 设定Blue滚动条当前位置
char sPos[10]; //
itoa(m_Red_ScrollBar.GetScrollPos(),sPos,10); // 字符与整型转换
m_Edit1.SetWindowText(sPos); // 将当前Red滚动条的位置输出
itoa(m_Green_ScrollBar.GetScrollPos(),sPos,10);//
m_Edit2.SetWindowText(sPos); // 将当前Green滚动条的位置输出
itoa(m_Blue_ScrollBar.GetScrollPos(),sPos,10); //
m_Edit3.SetWindowText(sPos); // 将当前Blue滚动条的位置输出
return TRUE; //
}
void CSCORLLBARDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSCORLLBARDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSCORLLBARDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSCORLLBARDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
char sPos[10]; //记录滚动条位置的字符数组
int iRedNowPos,iGreenNowPos,iBlueNowPos; //记录滚动条的整型数
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //获得Red滚动条当前位置
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//获得Green滚动条当前位置
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos(); //获得Blue滚动条当前位置
if(pScrollBar==&m_Red_ScrollBar) //对红色滚动条进行操作
{
switch(nSBCode)
{
case SB_THUMBTRACK: //拖动滚动条的滑块
m_Red_ScrollBar.SetScrollPos(nPos); //设定滚动条滑块的位置
iRedNowPos=nPos;
break;
case SB_LINEDOWN: //单击向下按钮
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos+1; //位置量加一
if(iRedNowPos>255)
iRedNowPos=255;
break;
case SB_LINEUP: //单击向上按钮
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos-1; //位置量减一
if(iRedNowPos<0)
iRedNowPos=0;
break;
case SB_PAGEDOWN: //单击向上按钮和滑块之间的区域
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos+10; //位置量+10
if(iRedNowPos>255)
iRedNowPos=255;
break;
case SB_PAGEUP: //单击向下按钮和滑块之间的区域
iRedNowPos=m_Red_ScrollBar.GetScrollPos(); //得到当前滚动条滑块位置
iRedNowPos=iRedNowPos-10; //位置量-10
if(iRedNowPos<0)
iRedNowPos=0;
break;
}
}
if(pScrollBar==&m_Green_ScrollBar) //对绿色滚动条进行操作
{
switch(nSBCode)
{
case SB_THUMBTRACK: //拖动滚动条的滑块
m_Green_ScrollBar.SetScrollPos(nPos); //设定滚动条滑块的位置
iGreenNowPos=nPos;
break;
case SB_LINEDOWN: //单击向下按钮
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos+1; //位置量加一
if(iGreenNowPos>255)
iGreenNowPos=255;
break;
case SB_LINEUP: //单击向上按钮
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos-1; //位置量减一
if(iGreenNowPos<0)
iGreenNowPos=0;
break;
case SB_PAGEDOWN: //单击向上按钮和滑块之间的区域
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos+10; //位置量+10
if(iGreenNowPos>255)
iGreenNowPos=255;
break;
case SB_PAGEUP: //单击向下按钮和滑块之间的区域
iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iGreenNowPos=iGreenNowPos-10; //位置量-10
if(iGreenNowPos<0)
iGreenNowPos=0;
break;
}
}
if(pScrollBar==&m_Blue_ScrollBar) //对蓝色滚动条进行操作
{
switch(nSBCode)
{
case SB_THUMBTRACK: //拖动滚动条的滑块
m_Blue_ScrollBar.SetScrollPos(nPos); //设定滚动条滑块的位置
iBlueNowPos=nPos;
break;
case SB_LINEDOWN: //单击向下按钮
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos+1; //位置量加一
if(iBlueNowPos>255)
iBlueNowPos=255;
break;
case SB_LINEUP: //单击向上按钮
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos-1; //位置量减一
if(iBlueNowPos<0)
iBlueNowPos=0;
break;
case SB_PAGEDOWN: //单击向上按钮和滑块之间的区域
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos+10; //位置量+10
if(iBlueNowPos>255)
iBlueNowPos=255;
break;
case SB_PAGEUP: //单击向下按钮和滑块之间的区域
iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();//得到当前滚动条滑块位置
iBlueNowPos=iBlueNowPos-10; //位置量-10
if(iBlueNowPos<0)
iBlueNowPos=0;
break;
}
}
m_Red_ScrollBar.SetScrollPos(iRedNowPos);
itoa(iRedNowPos,sPos,10);
m_Edit1.SetWindowText(sPos);
m_Green_ScrollBar.SetScrollPos(iGreenNowPos);
itoa(iGreenNowPos,sPos,10);
m_Edit2.SetWindowText(sPos);
m_Blue_ScrollBar.SetScrollPos(iBlueNowPos);
itoa(iBlueNowPos,sPos,10);
m_Edit3.SetWindowText(sPos);
m_Red_ScrollBar.SetScrollPos(iRedNowPos);
itoa(iRedNowPos,sPos,10);
m_Edit1.SetWindowText(sPos);
m_Green_ScrollBar.SetScrollPos(iGreenNowPos);
itoa(iGreenNowPos,sPos,10);
m_Edit2.SetWindowText(sPos);
m_Blue_ScrollBar.SetScrollPos(iBlueNowPos);
itoa(iBlueNowPos,sPos,10);
m_Edit3.SetWindowText(sPos);
CDC *pDC=GetDC(); //得到设备环境句柄
CBrush newBrush; //定义新画刷
CPen newPen; //定义新画笔
newBrush.CreateSolidBrush(RGB(iRedNowPos,iGreenNowPos,iBlueNowPos));
newPen.CreatePen(PS_SOLID,1,RGB(iRedNowPos,iGreenNowPos,iBlueNowPos));
pDC->SelectObject(&newBrush); //选入新画刷
pDC->SelectObject(&newPen); //选入新画笔
pDC->Rectangle(50,100,280,172); //左间距上间距,右间距下间距.
ReleaseDC(pDC);
CDialog::OnVScroll(nSBCode,nPos,pScrollBar);
}
void CSCORLLBARDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27660822/viewspace-775899/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27660822/viewspace-775899/