📄 unibtndlg.cpp
字号:
// UniBtnDlg.cpp : implementation file
//
#include "stdafx.h"
#include "UniBtn.h"
#include "UniBtnDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CUniBtnDlg dialog
CUniBtnDlg::CUniBtnDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUniBtnDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUniBtnDlg)
// 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);
}
void CUniBtnDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUniBtnDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUniBtnDlg, CDialog)
//{{AFX_MSG_MAP(CUniBtnDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUniBtnDlg message handlers
BOOL CUniBtnDlg::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
HRGN r;
r = CreateEllipticRgn(0, 0, 63, 31);
m_Btn1.Create("Btn 1", WS_CHILD | WS_VISIBLE, CPoint(100, 15), r, this, UNI_BTN1, 2, GetSysColor(COLOR_BTNFACE), RGB(0, 255, 0), RGB(0, 255, 0), GetSysColor(COLOR_BTNFACE));
DeleteObject(r);
HDC hDC = CreateCompatibleDC(GetDC() -> GetSafeHdc());
HRGN c;
LOGFONT lf;
GetFont() -> GetLogFont(&lf);
lf.lfHeight = -128;
lf.lfWeight = 1000;
HFONT hFont = CreateFontIndirect(&lf);
HFONT hOldFont = (HFONT) SelectObject(hDC, hFont);
c = CreateRectRgn(0, 0, 0, 0);
int mode = SetBkMode(hDC, TRANSPARENT);
BeginPath(hDC);
TextOut(hDC, 0, 0, "$", 1);
EndPath(hDC);
c = PathToRegion(hDC);
SetBkMode(hDC, mode);
m_Btn2.Create("", WS_CHILD | WS_VISIBLE, CPoint(15, 15), c, this, UNI_BTN2, RGB(255, 255, 0));
SelectObject(hDC, hOldFont);
DeleteObject(hFont);
DeleteObject(c);
HRGN cr;
HRGN r1;
HRGN r2;
BeginPath(hDC);
MoveToEx(hDC, 0, 32, NULL);
LineTo(hDC, 48, 32);
LineTo(hDC, 48, 16);
LineTo(hDC, 96, 48);
LineTo(hDC, 48, 80);
LineTo(hDC, 48, 64);
LineTo(hDC, 0, 64);
LineTo(hDC, 0, 32);
EndPath(hDC);
cr = CreateRectRgn(0, 0, 63, 63);
cr = PathToRegion(hDC);
m_Btn3.Create("Btn 3", WS_CHILD | WS_VISIBLE, CPoint(80, 50), cr, this, UNI_BTN3, 2, RGB(250, 207, 194), RGB(255, 0, 0), RGB(255, 0, 0), GetSysColor(COLOR_BTNFACE));
DeleteObject(cr);
DeleteObject(hDC);
hDC = CreateCompatibleDC(GetDC() -> GetSafeHdc());
BeginPath(hDC);
MoveToEx(hDC, 31, 15, NULL);
CPoint p[7];
p[ 0] = CPoint(5, 0);
p[ 1] = CPoint(0, 55);
p[ 2] = CPoint(0, 28);
p[ 3] = CPoint(31, 64);
p[ 4] = CPoint(59, 55);
p[ 5] = CPoint(59, 0);
p[ 6] = CPoint(31, 15);
PolyBezier(hDC, &p[0], 7);
EndPath(hDC);
cr = CreateRectRgn(0, 0, 63, 63);
cr = PathToRegion(hDC);
m_Btn4.Create("Btn 4", WS_CHILD | WS_VISIBLE, CPoint(200, 10), cr, this, UNI_BTN4, 2, RGB(151, 244, 219), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
DeleteObject(cr);
DeleteObject(hDC);
c = CreateRectRgn(16, 0, 80, 31);
r1 = CreateEllipticRgn(0, 0, 32, 32);
r2 = CreateEllipticRgn(64, 0, 96, 32);
CombineRgn(c, c, r1, RGN_OR);
CombineRgn(c, c, r2, RGN_OR);
m_Btn5.Create("Btn 5", WS_CHILD | WS_VISIBLE, CPoint(180, 80), c, this, UNI_BTN5, 2, GetSysColor(COLOR_BTNFACE), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
DeleteObject(c);
DeleteObject(r1);
DeleteObject(r2);
return TRUE; // return TRUE unless you set the focus to a control
}
void CUniBtnDlg::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 CUniBtnDlg::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 CUniBtnDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -