📄 lifedlg.cpp
字号:
}
}
}
//画生命曲线
void CLifeDlg::DrawLife()
{
double Position;
int Cycle;
//体力曲线
Cycle = 23;
Position = (double)(CLifeDlg::TimeSub() % Cycle);
CLifeDlg::DrawBioCurve(8 * (BioBottom - BioTop) / 16, Cycle, Position * BioWidth,RGB(0x0,0xFF,0xFF));
//情绪曲线
Cycle = 28;
Position = (double)(CLifeDlg::TimeSub() % (int)Cycle);
CLifeDlg::DrawBioCurve(8 * (BioBottom - BioTop) / 16, Cycle, Position * BioWidth,RGB(0,255,0));
//智力曲线
Cycle = 33;
Position = (double)(CLifeDlg::TimeSub() % (int)Cycle);
CLifeDlg::DrawBioCurve(8 * (BioBottom - BioTop) / 16, Cycle, Position * BioWidth,RGB(255,0,0));
}
//画焦点
void CLifeDlg:: DrawFocus(int pos)
{
static bool restory = false;
static int prePos = 0;
//清除焦点
if (restory)
{
DrawRect(prePos + 1,BioTop,BioWidth -1 + prePos, BioBottom, RGB(222,174,50), RGB(222,174,50));
restory = false;
DrawGradient(CRect(BioLeft, BioTop, BioRight, BioBottom + 15));
}
prePos = pos; //保存当前点
restory = true;
//画焦点
DrawRect(pos + 1, BioTop, BioWidth +pos, BioBottom, RGB(255,255,128), RGB(255,255,128));
DrawRect(3, 190, 100 , 210, RGB(0,0,0), RGB(0,0,0));
CTimeSpan day( (pos-BioLeft) / BioWidth, 1, 1, 1);
CTime curTime = m_curDate.GetTime();
curTime =curTime + day;
CString str = curTime.Format( "%Y, %m, %d" );
CFont font;
font.CreateFont (15, 9, 0, 0, FW_BLACK, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS,_T("Arial"));
OutText(4, 190, str, RGB(255,255,255), RGB(255,255,255), &font);
DrawBioBorder();
DrawLife();
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);
if(point.x >=BioLeft && point.x < BioRight && point.y >= BioTop && point.y < BioBottom)
{
point.x > BioRight - 40 ? point.x -= 40:point.x;
point.y > BioBottom - 20 ? point.y -= 20:point.y;
CClientDC dc(this);
CBrush brush(RGB(0, 110, 255));
dc.SelectObject(&brush);
dc.Ellipse(point.x - 5,point.y - 5,point.x + 40, point.y + 20);
ReleaseDC(&dc);
CFont font;
font.CreatePointFont(100,"Arial");
str = curTime.Format( "%w" );
OutText(point.x, point.y, "星期 "+str, RGB(255,255,255), RGB(0,0,255), &font);
UpdateData(true); //更新日期数据
}
}
//渐变颜色背景
void CLifeDlg::DrawGradient(CRect rectClient)
{
int stat = 0;
int end = 255;
double step = (double)(BioBottom + 15 - BioTop) / 123;
for(double i = BioTop; i < BioBottom + 15; i += step)
{
DrawRect(BioLeft, i, BioRight, i + step, RGB(stat,200,end), RGB(stat ,200,end));
stat += 2;
if(stat>60) end -= 2;
if(i > BioBottom + 15) return;
}
}
//播放背景音乐
void CLifeDlg::OnMusic()
{
if(isMusic)
{
isMusic = false;
HWND hWnd;
hWnd = GetSafeHwnd();
char inBuf[300], outBuf[60], fileName[255];
MCIERROR mciError;
strcpy(fileName,"music.mid");
wsprintf( inBuf,"open %s type sequencer alias myseq", fileName);
mciError = mciSendString( inBuf, outBuf, sizeof(outBuf), NULL);
if (mciError == 0)
{
mciError = mciSendString("play myseq notify", NULL, 0, hWnd);
if (mciError != 0)
mciSendString("close myseq", NULL, 0, NULL);
}
}
else
{
isMusic = true;
mciSendString("close myseq", NULL, 0, NULL);
}
}
// 日期差计算
int CLifeDlg::TimeSub()
{
CTime CurrTime; //当前日期
CTime BornTime; //出生日期
UpdateData(true); //更新日期数据
CurrTime = m_curDate.GetTime();
BornTime = m_bornDate.GetTime();
CTimeSpan sub = (CurrTime).operator - (BornTime);
return sub.GetDays();
}
///////////////////////////////////////////////////////////////////////////
//
// 消息处理函数
//
///////////////////////////////////////////////////////////////////////////
//鼠标左键事件处理函数
void CLifeDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
pos = BioLeft;
//找出鼠标点击的所在列
for (int i = 0; i < 31; pos = pos + BioWidth, i++)
{
if (point.x >= pos && point.x < BioWidth + pos && point.y >= BioTop && point.y < BioBottom)
{
DrawFocus(pos);//画焦点
return;
}
}
if(pos > 30) pos = BioLeft + BioWidth * 5;
PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));
CDialog::OnLButtonDown(nFlags, point);
}
//鼠标右键件处理函数
void CLifeDlg::OnContextMenu(CWnd*, CPoint point)
{
if (point.x == -1 && point.y == -1)
{
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_LIFE_DLG));
CMenu* pPopup = menu.GetSubMenu(0);
if (!isMusic)
pPopup->CheckMenuItem(ID_BACKDROP_MUSIC,MF_CHECKED);
ASSERT(pPopup != NULL);
pPopup->TrackPopupMenu(TPM_LEFTALIGN| TPM_LEFTBUTTON| TPM_RIGHTBUTTON, point.x, point.y,
AfxGetMainWnd());
}
void CLifeDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(point.x >= BioLeft && point.x < BioRight && point.y >= BioTop && point.y < BioBottom)
{
hCursor1 = AfxGetApp()->LoadCursor(IDC_NODROP);
SetCursor(hCursor1);
}
else
{
hCursor2 = AfxGetApp()->LoadStandardCursor(IDC_ARROW );
SetCursor(hCursor2);
}
CRect rect;
m_preMonth.GetWindowRect(&rect);
ScreenToClient(rect);
if(!rect.PtInRect(point))
{
m_preMonth.SetBitmap((HBITMAP)premonthBMP.m_hObject);
m_preMonth.EnableWindow(false);
}
else
{
m_preMonth.SetBitmap((HBITMAP)premonthBMP2.m_hObject);
m_preMonth.EnableWindow(true);
}
m_curDay.GetWindowRect(&rect);
ScreenToClient(rect);
if(!rect.PtInRect(point))
{
m_curDay.SetBitmap((HBITMAP)curtimeBMP.m_hObject);
m_curDay.EnableWindow(false);
}
else
{
m_curDay.SetBitmap((HBITMAP)curtimeBMP2.m_hObject);
m_curDay.EnableWindow(true);
}
m_nextMonth.GetWindowRect(&rect);
ScreenToClient(rect);
if(!rect.PtInRect(point))
{
m_nextMonth.SetBitmap((HBITMAP)nextmonthBMP.m_hObject);
m_nextMonth.EnableWindow(false);
}
else
{
m_nextMonth.SetBitmap((HBITMAP)nextmonthBMP2.m_hObject);
m_nextMonth.EnableWindow(true);
}
CDialog::OnMouseMove(nFlags, point);
}
HBRUSH CLifeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//-->>设置对话框背景颜色
static CBrush brush(RGB(0,0,0));
hbr = brush;
//--<<设置对话框背景颜色
return hbr;
}
//上一个月
void CLifeDlg::OnPremonth()
{
int month = m_curDate.GetMonth();
int year = m_curDate.GetYear();
if (month == 1)
{
month = 12;
year --;
}
else
month--;
m_curDate = CTime(year, month, m_curDate.GetDay(), 11, 00, 0);
UpdateData(false); //更新日期数据
InitDialog();
}
//当前时间
void CLifeDlg::OnCurtime()
{
m_curDate = CTime::GetCurrentTime();
pos = BioLeft;
UpdateData(false); //更新日期数据
InitDialog();
}
//下一个月
void CLifeDlg::OnNextmonth()
{
int month = m_curDate.GetMonth();
int year = m_curDate.GetYear();
if (month == 12)
{
month = 1;
year ++;
}
else
month++;
m_curDate = CTime(year, month, m_curDate.GetDay(), 11, 00, 0);
UpdateData(false); //更新日期数据
InitDialog();
}
void CLifeDlg::OnNextYear()
{
int month = m_curDate.GetMonth();
int year = m_curDate.GetYear();
year ++;
m_curDate = CTime(year,month,m_curDate.GetDay(),11,00,0);
UpdateData(false); //更新日期数据
InitDialog();
}
void CLifeDlg::OnPreYear()
{
int month = m_curDate.GetMonth();
int year = m_curDate.GetYear();
year --;
m_curDate = CTime(year,month,m_curDate.GetDay(),11,00,0);
UpdateData(false); //更新日期数据
InitDialog();
}
void CLifeDlg::OnBackdropMusic()
{
OnMusic() ;
}
void CLifeDlg::OnAbout()
{
}
void CLifeDlg::OnDatetimechangeCurDatetime(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE); //更新日期数据
pos = BioLeft;
InitDialog();
*pResult = 0;
}
void CLifeDlg::OnDatetimechangeBornDatetime(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(TRUE); //更新日期数据
InitDialog();
*pResult = 0;
}
void CLifeDlg::OnAboutbox()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CLifeDlg::OnHelp()
{
CHelpDialog helpDlg;
helpDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -