📄 dlgdemodlg.cpp
字号:
// DlgDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DlgDemo.h"
#include "DlgDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgDemoDlg dialog
CDlgDemoDlg::CDlgDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDlgDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgDemoDlg)
m_blue = 0;
m_green = 0;
m_red = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDlgDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgDemoDlg)
DDX_Text(pDX, IDC_EDT_BLUE, m_blue);
DDV_MinMaxUInt(pDX, m_blue, 0, 255);
DDX_Text(pDX, IDC_EDT_GREEN, m_green);
DDV_MinMaxUInt(pDX, m_green, 0, 255);
DDX_Text(pDX, IDC_EDT_RED, m_red);
DDV_MinMaxUInt(pDX, m_red, 0, 255);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDlgDemoDlg)
ON_EN_CHANGE(IDC_EDT_RED, OnChangeEdtRed)
ON_EN_CHANGE(IDC_EDT_GREEN, OnChangeEdtGreen)
ON_EN_CHANGE(IDC_EDT_BLUE, OnChangeEdtBlue)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgDemoDlg message handlers
BOOL CDlgDemoDlg::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
// TODO: Add extra initialization here
//设置红色值微调按钮
CSpinButtonCtrl *pSpinRed = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_RED);
ASSERT(pSpinRed!=NULL);
//设置伙伴窗口
pSpinRed->SetBuddy(GetDlgItem(IDC_EDT_RED));
pSpinRed->SetRange(0,255);
pSpinRed->SetPos(128);
//设置绿色值微调按钮
CSpinButtonCtrl *pSpinGreen = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_GREEN);
ASSERT(pSpinGreen!=NULL);
//设置伙伴窗口
pSpinGreen->SetBuddy(GetDlgItem(IDC_EDT_GREEN));
pSpinGreen->SetRange(0,255);
pSpinGreen->SetPos(128);
//设置蓝色值微调按钮
CSpinButtonCtrl *pSpinBlue = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_BLUE);
ASSERT(pSpinBlue!=NULL);
//设置伙伴窗口
pSpinBlue->SetBuddy(GetDlgItem(IDC_EDT_BLUE));
pSpinBlue->SetRange(0,255);
pSpinBlue->SetPos(128);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDlgDemoDlg::OnChangeEdtRed()
{
// 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
OnColorChange();
}
void CDlgDemoDlg::OnChangeEdtGreen()
{
// 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
OnColorChange();
}
void CDlgDemoDlg::OnChangeEdtBlue()
{
// 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
OnColorChange();
}
void CDlgDemoDlg::OnColorChange()
{
UpdateData(TRUE);
CBrush colorBrush;
COLORREF clRGB;
//得到RGB颜色值
clRGB = RGB(m_red,m_green,m_blue);
CClientDC * pClientDC;
//得到绘图环境
pClientDC = new CClientDC(this);
colorBrush.CreateSolidBrush(clRGB);
CRect rect(80,140,160,220);
//显示颜色
pClientDC->FillRect(rect,&colorBrush);
delete pClientDC;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -