// DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Demo.h"
#include "DemoDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemoDlg)
m_text1 = _T("0");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_col = RGB(255, 0, 0);
m_setCol = false;
m_font.CreatePointFont(200, "华文楷体");
m_brush.CreateSolidBrush(RGB(0, 255, 0));
}
void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoDlg)
DDX_Control(pDX, IDC_BUTTON1, m_Button1);
DDX_Control(pDX, IDC_BT_UPANDDOWN, m_BtnUpAndDown);
DDX_Text(pDX, IDC_EDIT1, m_text1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_BUTTON1, OnColor)
ON_BN_CLICKED(IDC_BUTTON2, OnSetFont)
ON_WM_MOUSEMOVE()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers
BOOL CDemoDlg::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
GetDlgItem(IDC_ST_Pic)->GetWindowRect(m_rect);
m_rect.top += 3;
m_rect.left += 3;
m_rect.right -= 3;
m_rect.bottom -=3;
ScreenToClient(&m_rect);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDemoDlg::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 CDemoDlg::OnPaint()
{
CPaintDC dc(this);
CBrush br(m_col);
dc.FillRect(m_rect, &br);
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 CDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDemoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default IDI_BT_DOWN
if (::ChildWindowFromPoint(m_hWnd,point) == m_BtnUpAndDown.m_hWnd)
{
SetCapture();
SetCursor(AfxGetApp()->LoadCursor(IDC_BT_DOWN));
m_BtnUpAndDown.SetIcon(AfxGetApp()->LoadIcon(IDI_BT_DOWN));
m_setCol = TRUE;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CDemoDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ReleaseCapture();
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
m_BtnUpAndDown.SetIcon(AfxGetApp()->LoadIcon(IDI_BT_UP));
m_setCol = false;
CDialog::OnLButtonUp(nFlags, point);
}
void CDemoDlg::OnColor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
//为了保留先前的设置而进行的操作
dlg.m_cc.Flags |= CC_RGBINIT;
dlg.m_cc.rgbResult = m_col;
if(IDOK == dlg.DoModal())
{
// m_col = dlg.m_cc.rgbResult; //这两种方式都可以
m_col = dlg.GetColor();
}
InvalidateRect(m_rect,true);
}
void CDemoDlg::OnSetFont()
{
// TODO: Add your control notification handler code here
CFontDialog dlg;
if(IDOK == dlg.DoModal())
{
if(m_font.m_hObject)
m_font.DeleteObject();
m_font.CreateFontIndirect(dlg.m_cf.lpLogFont);
Invalidate();
}
}
void CDemoDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_setCol)
{
//坐标转换
ClientToScreen(&point);
//获得桌面上鼠标移到的任意一点的颜色 ::GetDC(0) 用0表示全局即桌面
m_col=::GetPixel(::GetDC(0),point.x,point.y);
InvalidateRect(m_rect,true);
}
CDialog::OnMouseMove(nFlags, point);
}
HBRUSH CDemoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd->GetDlgCtrlID() == IDC_ST_Font)
{
pDC->SelectObject(&m_font);
}
if(pWnd->GetDlgCtrlID() == IDC_EDIT1)
{
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkMode(TRANSPARENT);
return m_brush;
}
if(pWnd->GetDlgCtrlID() == IDC_BUTTON1)
{
pDC->SetTextColor(RGB(255, 0, 255));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
没有合适的资源?快使用搜索试试~ 我知道了~
字体,颜色对话框和exit编辑框设置颜色和button控件颜色及平面效果和取屏幕上任意一点的颜色
共33个文件
h:5个
cpp:4个
obj:4个
4星 · 超过85%的资源 需积分: 10 102 下载量 166 浏览量
2010-01-10
14:17:12
上传
评论 1
收藏 1.81MB RAR 举报
温馨提示
字体,颜色对话框 exit编辑框设置颜色 button控件颜色及平面效果 取屏幕上任意一点的颜色 程序有参考别人的代码谁有用请随便用
资源推荐
资源详情
资源评论
收起资源包目录
exit编辑框设置颜色和button控件颜色及平面效果和取屏幕上任意一点的颜色.rar (33个子文件)
Demo
DemoBtn.cpp 3KB
StdAfx.cpp 206B
resource.h 1KB
DemoBtn.h 1KB
Demo.dsw 516B
DemoDlg.cpp 7KB
Debug
Demo.pch 5.25MB
Demo.exe 112KB
vc60.pdb 356KB
vc60.idb 201KB
Demo.res 5KB
DemoBtn.obj 13KB
Demo.ilk 250KB
StdAfx.obj 103KB
Demo.pdb 297KB
DemoDlg.obj 36KB
Demo.obj 14KB
Demo.h 1KB
DemoDlg.h 2KB
StdAfx.h 1KB
Demo.ncb 41KB
Demo.opt 53KB
Demo.clw 1KB
Demo.aps 23KB
Demo.rc 6KB
res
Demo.rc2 396B
mag_glass.ico 766B
Demo.ico 1KB
cursor1.cur 326B
icon1.ico 766B
Demo.cpp 2KB
Demo.plg 2KB
Demo.dsp 4KB
共 33 条
- 1
资源评论
- yw10062013-07-23确实有点复杂啊
- yufengyu20082012-04-17部分内容参考可以成功,有些没有看懂
- 走召羊君2014-05-07借鉴一下啊,不一定跟自己很相符
- dongyf7272012-03-06设置背景色可以参考 但按钮没有动态效果
- d75d2012-07-10比较复杂啊。没有文档说明
wwwxhb
- 粉丝: 30
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功