?? sliderusedlg.cpp
字號:
// SliderUseDlg.cpp : implementation file
//
#include "stdafx.h"
#include "evcstudy.h"
#include "SliderUseDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSliderUseDlg dialog
CSliderUseDlg::CSliderUseDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSliderUseDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSliderUseDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSliderUseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SLIDER_RED, m_slider_red);
DDX_Control(pDX, IDC_SLIDER_GREEN, m_slider_green);
DDX_Control(pDX, IDC_SLIDER_BLUE, m_slider_blue);
//{{AFX_DATA_MAP(CSliderUseDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSliderUseDlg, CDialog)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
//{{AFX_MSG_MAP(CSliderUseDlg)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSliderUseDlg message handlers
BOOL CSliderUseDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
//設置紅色值滑動條
CSliderCtrl *pSliderRed = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_RED);
ASSERT(pSliderRed!=NULL);
//設置滑動條取值范圍
pSliderRed->SetRange(0,255);
pSliderRed->SetPos(128);
//設置綠色值滑動條
CSliderCtrl *pSliderGreen = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_GREEN);
ASSERT(pSliderGreen!=NULL);
//設置滑動條取值范圍
pSliderGreen->SetRange(0,255);
pSliderGreen->SetPos(128);
//設置藍色值滑動條
CSliderCtrl *pSliderBlue = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_BLUE);
ASSERT(pSliderBlue!=NULL);
//設置滑動條取值范圍
pSliderBlue->SetRange(0,255);
pSliderBlue->SetPos(128);
SetTimer(100,100,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
//水平滾動事件
void CSliderUseDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int iRed,iGreen,iBlue;
//得到紅色、綠色和藍色滑動條滾動事件
if ((pScrollBar->GetDlgCtrlID() == IDC_SLIDER_RED)
|| (pScrollBar->GetDlgCtrlID() == IDC_SLIDER_GREEN)
|| (pScrollBar->GetDlgCtrlID() == IDC_SLIDER_BLUE))
{
CSliderCtrl *pSliderRed = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_RED);
CSliderCtrl *pSliderGreen = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_GREEN);
CSliderCtrl *pSliderBlue = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_BLUE);
iRed = pSliderRed->GetPos();
iGreen = pSliderGreen->GetPos();
iBlue = pSliderBlue->GetPos();
}
UpdateData(TRUE);
CBrush colorBrush;
COLORREF clRGB;
//得到RGB顏色值
clRGB = RGB(iRed,iGreen,iBlue);
CClientDC * pClientDC;
//得到繪圖環境
pClientDC = new CClientDC(this);
colorBrush.CreateSolidBrush(clRGB);
CRect rect(80,120,160,200);
//顯示顏色
pClientDC->FillRect(rect,&colorBrush);
delete pClientDC;
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CSliderUseDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CSliderUseDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);
CBrush colorBrush;
COLORREF clRGB;
//得到RGB顏色值
clRGB = RGB(Random(),Random(),Random());
CClientDC * pClientDC;
//得到繪圖環境
pClientDC = new CClientDC(this);
colorBrush.CreateSolidBrush(clRGB);
CRect rect(180,120,260,200);
//顯示顏色
pClientDC->FillRect(rect,&colorBrush);
delete pClientDC;
CDialog::OnTimer(nIDEvent);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -