📄 colordlg.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// ColorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Color.h"
#include "ColorDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorDlg dialog
CColorDlg::CColorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CColorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CColorDlg)
// 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);
// initially: gray color
m_nRed = m_nGreen = m_nBlue = 192;
}
void CColorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CColorDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_RED, m_nRed);
DDX_Text(pDX, IDC_GREEN, m_nGreen);
DDX_Text(pDX, IDC_BLUE, m_nBlue);
pDX->PrepareEditCtrl(IDC_RED);
DDV_MinMaxInt(pDX, m_nRed, 0, 255);
pDX->PrepareEditCtrl(IDC_GREEN);
DDV_MinMaxInt(pDX, m_nGreen, 0, 255);
pDX->PrepareEditCtrl(IDC_BLUE);
DDV_MinMaxInt(pDX, m_nBlue, 0, 255);
}
BEGIN_MESSAGE_MAP(CColorDlg, CDialog)
//{{AFX_MSG_MAP(CColorDlg)
ON_BN_CLICKED(IDC_CHOOSECOLOR, OnChooseColor)
ON_MESSAGE(WM_CTLCOLORLISTBOX, OnColorLBox)
ON_BN_CLICKED(IDC_APPLY, OnApply)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorDlg message handlers
BOOL CColorDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
// Choose Color Dialog
void CColorDlg::OnChooseColor()
{
CColorDialog colorDlg(RGB(m_nRed, m_nGreen, m_nBlue));
if(colorDlg.DoModal() == IDOK)
{
COLORREF nColor = colorDlg.m_cc.rgbResult;
m_nRed = nColor & 0xFF;
m_nGreen = (nColor >> 8) & 0xFF;
m_nBlue = (nColor >> 16) & 0xFF;
UpdateData(FALSE);
RefreshWindow();
}
}
HBRUSH CColorDlg::OnColorLBox(WPARAM wParam, LPARAM lParam)
{
return CreateSolidBrush(RGB(m_nRed, m_nGreen, m_nBlue));
}
// Set new color
void CColorDlg::OnApply()
{
if(UpdateData(TRUE))
RefreshWindow();
}
// Refresh the colored window
void CColorDlg::RefreshWindow()
{
CWnd* pWnd = GetDlgItem(IDC_COLORFIELD);
if(pWnd)
{
pWnd->Invalidate();
pWnd->UpdateWindow();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -