课程表

作者在 2006-10-25 16:06:00 发布以下内容

虽然很简单,我还是决定把这些都记录下来,毕竟这是我学习的生涯。

UploadFiles/2006-10/1025396380.rar

关键代码如下:

#define ICON_NOTIFY    WM_USER+100
#define COURSE_ID    0

void CMyCourseDlg::InitialTip()
{
 //加载图标
 m_ntfIcon.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 //提示框
 char *tip="课程表";
 strcpy(m_ntfIcon.szTip,tip);

 //窗口句柄
 m_ntfIcon.hWnd=GetSafeHwnd();
 //图标ID
 m_ntfIcon.uID=COURSE_ID;
 //消息响应
 m_ntfIcon.uCallbackMessage=ICON_NOTIFY;
 //图标类型
 m_ntfIcon.uFlags=NIF_ICON | NIF_TIP | NIF_MESSAGE;

 //放入托盘
 Shell_NotifyIcon(NIM_ADD,&m_ntfIcon);
}

 

BOOL CMyCourseDlg::OnInitDialog()
{
 .....


 CTime t_now=CTime::GetCurrentTime();
 CTime t_start(2006,9,4,0,0,0);
 CTimeSpan def=t_now-t_start;
 m_nWeeks=(int)def.GetDays()/7+1;
 
 CString str;
 str.Format(_T("本周是第%d周"),m_nWeeks);

 GetDlgItem(IDC_COURSE0)->SetWindowText(str);
 if (m_nWeeks%2==0)//双周
 {
  GetDlgItem(IDC_COURSE5)->SetWindowText(_T(""));
  GetDlgItem(IDC_COURSE10)->SetWindowText(_T(""));
 }
 
 CTime t=CTime::GetCurrentTime();
 str.Format(_T("%d - %d - %d "),t.GetYear(),t.GetMonth(),t.GetDay());
 str+=m_arrStr.GetAt((t.GetDayOfWeek()-2+7)%7);
 GetDlgItem(IDC_DATE)->SetWindowText(str);

 m_menu.LoadMenu(IDR_MENU);

 SetTimer(ID_TIME_UPDATA,1000,NULL);

 return TRUE;
}

 

void CMyCourseDlg::OnClose()
{
 InitialTip();
 ShowWindow(SW_HIDE);
}

LRESULT CMyCourseDlg::OnNotify(WPARAM uID,LPARAM lEvent)
{
 if (uID!=COURSE_ID || (lEvent!=WM_RBUTTONDOWN&&lEvent!=WM_LBUTTONDOWN))
  return 0;

 if (lEvent==WM_LBUTTONDOWN)
 {
  Shell_NotifyIcon(NIM_DELETE,&m_ntfIcon);
  ShowWindow(SW_SHOW);
 }

 if (lEvent==WM_RBUTTONDOWN)
 {
  CPoint pt;
  GetCursorPos(&pt);
  
  m_pMenu=m_menu.GetSubMenu(0);
  m_pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
   pt.x,pt.y,this);
 }
 
 return 1;
}

void CMyCourseDlg::OnOpen()
{
 Shell_NotifyIcon(NIM_DELETE,&m_ntfIcon);
 ShowWindow(SW_SHOW);
}

开发经验 | 阅读 1385 次
文章评论,共0条
游客请输入验证码
浏览67801次