?? mybuttondlg.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 + -