⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mybuttondlg.cpp

📁 FaltBottom,用于多种按钮
💻 CPP
字号:
// MyButtonDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MyButton.h"
#include "MyButtonDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CMyButtonDlg dialog

CMyButtonDlg::CMyButtonDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyButtonDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyButtonDlg)
		// 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(IDI_ICON7);
}

void CMyButtonDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyButtonDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	DDX_Control(pDX,IDC_EMAIL,m_email);
	DDX_Control(pDX,IDC_WEB,m_web);
}

BEGIN_MESSAGE_MAP(CMyButtonDlg, CDialog)
	//{{AFX_MSG_MAP(CMyButtonDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyButtonDlg message handlers

BOOL CMyButtonDlg::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

  //创建图标按钮1
  m_confirm.SubclassDlgItem(IDC_BUTTON1, this);
  //设置按钮文字
  m_confirm.SetWindowText("平面按钮");
  //设置交换的图标
  m_confirm.SetIcon(IDI_ICON1, IDI_ICON2); 
  //鼠标经过,绘制边框
  m_confirm.DrawBorder(true);
  m_confirm.SetInactiveBgColor(RGB(162,189,252));
  //鼠标经过,改变颜色
  m_confirm.SetActiveBgColor(RGB(220,220,220));
  //鼠标经过,字体颜色
  m_confirm.SetActiveFgColor(RGB(255,0,0));
  //鼠标滑过,字体颜色
  m_confirm.SetInactiveFgColor(RGB(0,0,0));
  //设置鼠标形状
  m_confirm.SetBtnCursor(IDC_HAND);

  //创建图标按钮2
  m_cancel.SubclassDlgItem(IDC_BUTTON2, this);
  //取消平面按钮
  m_cancel.SetFlat(false);
  //设置鼠标点击交换的图标
  m_cancel.SetIcon(IDI_ICON3, IDI_ICON4); 
  //设置按钮文字
  m_cancel.SetWindowText("取消平面");
  //鼠标点击,改变颜色
  m_cancel.SetActiveBgColor(RGB(220,220,220));
  m_cancel.SetInactiveBgColor(RGB(162,189,252));

  //创建图标按钮3
  m_btn1.SubclassDlgItem(IDC_BUTTON3,this);
  m_btn1.SetIcon(IDI_ICON6, IDI_ICON5);
  m_btn1.DrawBorder(false);
  m_btn1.SetShowText(false);
  m_btn1.SetInactiveBgColor(RGB(160,180,220));

  //创建图标按钮4
  m_btn2.SubclassDlgItem(IDC_BUTTON4,this);
  m_btn2.SetIcon(IDI_ICON6, IDI_ICON5);
  m_btn2.SetWindowText("文字居下");
  m_btn2.SetAlign(CButtonST::ST_ALIGN_VERT);
  m_btn2.SetInactiveBgColor(RGB(162,189,252));

  //创建显示提示文字和打开URL的按钮
  m_btn3.SubclassDlgItem(IDC_BUTTON5,this);
  m_btn3.SetIcon(IDI_ICON2,IDI_ICON7);
  m_btn3.SetWindowText("打开URL");
  m_btn3.SetURL("http://moonhai.com");
  m_btn3.SetTooltipText("提示文字\nhttp://moonhai.com");
  m_btn3.SetInactiveBgColor(RGB(162,189,252));

  //创建XP样式的按钮(激活时是圆角按钮)
  m_btn4.SubclassDlgItem(IDC_BUTTON6,this);
  m_btn4.SetWindowText("WinXP样式按钮");
  m_btn4.SetInactiveBgColor(RGB(162,189,252));
  m_btn4.SetXPStyle(true);
  

  //确定按钮
  m_ok.SubclassDlgItem(IDOK,this);
  m_ok.SetInactiveBgColor(RGB(220,220,220));
  m_ok.SetInactiveFgColor(RGB(225,0,0));
  m_ok.SetActiveBgColor(RGB(255,255,255));
  m_ok.SetTooltipText("退出");

  //设置超连接
  m_email.SetURL(_T("mailto:guojianbest@163.com"));
  m_email.SetUnderline(true);
  m_email.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_HAND));

  m_web.SetURL(_T("http://www.moonhai.com"));
  m_web.SetUnderline(false);
  m_web.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_HAND));
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyButtonDlg::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 CMyButtonDlg::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 CMyButtonDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//改变对话框元素的背景色和文字颜色
HBRUSH CMyButtonDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(nCtlColor==CTLCOLOR_LISTBOX)
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkColor(RGB(233,233,220));
		HBRUSH b=CreateSolidBrush(RGB(233,233,220));
		return b;
	}
	else if(nCtlColor==CTLCOLOR_SCROLLBAR)
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkColor(RGB(233,233,220));
		HBRUSH b=CreateSolidBrush(RGB(233,233,220));
		return b;
	}
	else if(nCtlColor==CTLCOLOR_EDIT)
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkColor(RGB(233,233,220));
		HBRUSH b=CreateSolidBrush(RGB(233,233,220));
		return b;
	}
	else if(nCtlColor==CTLCOLOR_STATIC)
	{
		//pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkColor(RGB(160,180,220));
		HBRUSH b=CreateSolidBrush(RGB(160,180,220));
		return b;
	}
	else if(nCtlColor==CTLCOLOR_DLG)
	{
		pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkColor(RGB(160,180,220));
		HBRUSH b=CreateSolidBrush(RGB(160,180,220));
		return b;
	}	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CMyButtonDlg::OnOK() 
{
	// TODO: Add extra validation here
	if(MessageBox("确定退出?","提示:",MB_OKCANCEL | MB_ICONQUESTION)!=IDOK)
		return;
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -