📄 lifedlg.cpp
字号:
// lifeDlg.cpp : implementation file
#include "stdafx.h"
#include "life.h"
#include "lifeDlg.h"
#include "HelpDialog.h"
#include "math.h"
#include "resource.h"
#include <Mmsystem.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)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLifeDlg dialog
void CLifeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLifeDlg)
DDX_Control(pDX, IDC_CURTIME, m_curDay);
DDX_Control(pDX, IDC_NEXTMONTH, m_nextMonth);
DDX_Control(pDX, IDC_PREMONTH, m_preMonth);
DDX_Control(pDX, IDC_BORN_DATETIME, m_bornDateCtr);
DDX_Control(pDX, IDC_CUR_DATETIME, m_curDateCtr);
DDX_DateTimeCtrl(pDX, IDC_BORN_DATETIME, m_bornDate);
DDX_DateTimeCtrl(pDX, IDC_CUR_DATETIME, m_curDate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLifeDlg, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CLifeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_BACKDROP_MUSIC, OnBackdropMusic)
ON_COMMAND(ID_NEXT_YEAR, OnNextYear)
ON_COMMAND(ID_PRE_YEAR, OnPreYear)
ON_COMMAND(ID_ABOUT, OnAbout)
ON_BN_CLICKED(IDC_PREMONTH, OnPremonth)
ON_BN_CLICKED(IDC_NEXTMONTH, OnNextmonth)
ON_BN_CLICKED(IDC_CURTIME, OnCurtime)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CUR_DATETIME, OnDatetimechangeCurDatetime)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_BORN_DATETIME, OnDatetimechangeBornDatetime)
ON_COMMAND(IDD_ABOUTBOX, OnAboutbox)
ON_BN_CLICKED(ID_HELP, OnHelp)
ON_COMMAND(IDD_HELP, OnHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CLifeDlg::CLifeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLifeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLifeDlg)
m_bornDate = 0;
m_curDate = 0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
isMusic = true;
m_bornDate = CTime(1980, 6, 16, 0, 0, 1);//日历控件初始
m_curDate = CTime(2003, 6, 26, 1, 0, 1); //日历控件初始
premonthBMP.LoadBitmap(IDB_PRE_MONTH);
premonthBMP2.LoadBitmap(IDB_PRE_MONTH2);
nextmonthBMP.LoadBitmap(IDB_NEXT_MONTH);
nextmonthBMP2.LoadBitmap(IDB_NEXT_MONTH2);
curtimeBMP.LoadBitmap(IDB_CUR_TIME);
curtimeBMP2.LoadBitmap(IDB_CUR_TIME2);
BioTop = 40;
BioBottom = 342;
BioLeft = 115;
BioRight =580;
BioWidth = (BioRight - BioLeft) / 31;
BioHeigh = (BioBottom - BioTop) / 10;
}
/////////////////////////////////////////////////////////////////////////////
// CLifeDlg message handlers
BOOL CLifeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
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);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
/////////////////////////////////////
UpdateData(TRUE); //更新 日期数据
OnMusic() ; //放音乐
InitDialog(); //初始化窗体
////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CLifeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CLifeDlg::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();
InitDialog();//初始化窗体
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CLifeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLifeDlg::OnCancel()
{
CDialog::OnCancel();
}
////////////////////////////////////////////////////////////////////////
//
// 处理函数
//
//////////////////////////////////////////////////////////////////////
void CLifeDlg::InitDialog()
{
//-->>3D字体效果
CFont font;
font.CreateFont (20, 17, 0, 0, FW_BLACK, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS,_T("Arial"));
OutText(155, 10, "人体生命曲线 2.0 版", RGB(0,255,0), RGB(0,0,0), &font);
OutText(154, 9, "人体生命曲线 2.0 版", RGB(255,255,255), RGB(0,0,0), &font);
OutText(153, 8, "人体生命曲线 2.0 版", RGB(255,0,0), RGB(0,0,0), &font);
//--<<3D字体效果
CFont font1;
font1.CreateFont (16, 8, 0, 0, FW_BLACK, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS,_T("Arial"));
OutText(5, 45, "公历出生日期:", RGB(0X00,0XD4,0XD8),RGB(0,0,0), &font1);
OutText(5, 110, "公历查询日期:", RGB(0X00,0XD4,0XD8), RGB(0,0,0), &font1);
OutText(5, 170, " 以下是您在", RGB(0X58,0X5C,0XFF), RGB(0,0,0), &font1);
OutText(5, 215, " 时间状态", RGB(0X58,0X5C,0XFF), RGB(0,0,0), &font1);
DrawGradient(CRect(BioLeft, BioTop, BioRight, BioBottom + 15));//画背景
DrawBioBorder();//画边框
DrawFocus(pos); //画焦点列
DrawLife();//画生命曲线
}
//文本输出处理函数
void CLifeDlg::OutText(int x, int y, CString str, long textColor,long bkColor,CFont *font)
{
CClientDC dc(this);
dc.SelectObject(font);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(textColor);
dc.SetBkColor(bkColor);
dc.TextOut(x, y, str);
ReleaseDC(&dc);
}
//画线函数
void CLifeDlg::DrawLine (int x1, int y1, int x2, int y2, int DrawWidth, long rgb )
{
CClientDC dc(this);
CPen pen;
pen.CreatePen(PS_SOLID, DrawWidth, rgb);
dc.SelectObject(&pen);
dc.MoveTo (x1, y1);
dc.LineTo (x2, y2);
pen.DeleteTempMap();
ReleaseDC(&dc);
}
//画框
void CLifeDlg::DrawBioBorder()
{
CClientDC dc(this);
CPen Pen;
Pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 180));
dc.SelectObject(&Pen);
CFont font;
font.CreateFont (14, 4, 0, 0, FW_EXTRALIGHT, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS,_T("Arial"));
dc.SelectObject(&font);
//画竖线
for (int i = BioHeigh + BioTop; i < BioBottom; i = i + BioHeigh)
{
CLifeDlg::DrawLine (BioLeft, i, BioRight, i, 1, RGB(0, 0, 180) );
}
CTime curDate = m_curDate.GetTime();
CTimeSpan day( 1, 0, 0, 0);
//画横线
for (double t = (double)BioLeft + BioWidth; t < (double)BioRight; t = t + BioWidth)
{
OutText(t-12, BioBottom, curDate.Format("%d"), RGB(20,20,0), RGB(222,174,50), &font);
CString str = curDate.Format("%d");
curDate = curDate + day;
dc.SetBkColor(RGB(150,150,0));
dc.MoveTo (t, BioTop);
dc.LineTo (t, BioBottom);
}
//加粗中线
CLifeDlg::DrawLine (BioLeft, (BioBottom+BioTop) / 2, BioRight, (BioBottom + BioTop) / 2, 2, RGB(50,0,250) );
Pen.DeleteTempMap();
ReleaseDC(&dc);
}
//画矩形
void CLifeDlg:: DrawRect(int x1, int y1,int x2,int y2, long penColor,long brushColor)
{
CClientDC dc(this);
CPen Pen;
Pen.CreatePen(PS_SOLID, 0, penColor);
dc.SelectObject(&Pen);
CBrush brush(brushColor);
dc.SelectObject(&brush);
dc.Rectangle(x1, y1, x2, y2);//擦除
Pen.DeleteTempMap();
ReleaseDC(&dc);
}
//画曲线
void CLifeDlg::DrawBioCurve(double Swing, int Cycle, double Position,long rgb)
{
double x, y;
double Currentx;
double Currenty;
int DrawWidth = 1;
double Pi = 3.1415926353;
Currentx = -1;
for(x = BioLeft; x <= BioRight; x = x + 12)
{
y = (BioBottom - BioTop) / 2 + BioTop - Swing * sin((x - BioLeft + Position) * 2 * Pi / (Cycle * (BioRight - BioLeft) / 31));
if (pos >= x && pos <= x +11)
{
CString percent;
CClientDC dc(this);
CBrush brush3(RGB(0,0,0));
dc.SelectObject(&brush3);
if(Cycle == 23)
{
dc.Rectangle(4, 235, 100, 260);//擦除
percent.Format("%d", (int)(BioBottom-y) * 100 / (BioBottom - BioTop));
OutText(x, y > (BioBottom-10)?BioBottom-15:y, "体", RGB(0x0,0xFF,0xFF), RGB(222,174,50));
OutText(4, 245, "体力:"+percent, RGB(0x0,0xFF,0xFF), RGB(255,255,255));
}
else if(Cycle == 28)
{
dc.Rectangle(4, 270, 100, 290);//擦除
percent.Format("%d", (int)(BioBottom-y) *100 / (BioBottom - BioTop));
OutText(x, y > (BioBottom-10)?BioBottom-15:y, "情", RGB(0,255,0), RGB(222,174,50));
OutText(4, 270, "情绪:"+percent, RGB(0,255,0), RGB(255,255,255));
}
else if(Cycle == 33)
{
dc.Rectangle(4, 295, 100, 315);//擦除
percent.Format("%d", (int)(BioBottom-y) *100 / (BioBottom - BioTop));
OutText(x, y > (BioBottom-10)?BioBottom-15:y, "智", RGB(255,0,0), RGB(222,174,50));
OutText(4, 295, "智力:"+percent, RGB(255,0,0), RGB(255,255,255));
}
}
if( Currentx== -1)
{
Currentx = x;
Currenty = y;
}
else
{
CLifeDlg::DrawLine ( Currentx, Currenty, x, y, DrawWidth, rgb);
Currentx = x;
Currenty = y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -