📄 workdlg.cpp
字号:
// WorkDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "SMS.h"
#include "WorkDlg.h"
#include "StdLib.h"
// CWorkDlg 对话框
IMPLEMENT_DYNAMIC(CWorkDlg, CDialog)
CWorkDlg::CWorkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWorkDlg::IDD, pParent)
, m_pSet(&theApp.m_db )
, m_pLogionSet(&theApp.m_db )
{
//显示窗口颜色
m_backcolor=m_RGB_BkColor;
m_brush.CreateSolidBrush(m_backcolor);
}
CWorkDlg::~CWorkDlg()
{
}
void CWorkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_WORK_TAB, m_Work_TabCtrl);
}
BEGIN_MESSAGE_MAP(CWorkDlg, CDialog)
ON_NOTIFY(TCN_SELCHANGE, IDC_WORK_TAB, &CWorkDlg::OnTcnSelchangeWorkTab)
ON_WM_TIMER()
ON_WM_CLOSE()
ON_WM_CTLCOLOR()
ON_COMMAND(ID_WORK_CALENDA, &CWorkDlg::OnWorkCalenda)
ON_COMMAND(ID_WORK_PARTTIME,&CWorkDlg::OnWorkParttime )
ON_COMMAND(ID_WORK_CLOSE,&CWorkDlg::OnWorkClose )
ON_UPDATE_COMMAND_UI(ID_WORK_CALENDA, &CWorkDlg::OnUpdateWorkCalenda)
ON_UPDATE_COMMAND_UI(ID_WORK_PARTTIME, &CWorkDlg::OnUpdateWorkParttime)
ON_WM_CONTEXTMENU()
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
// CWorkDlg 消息处理程序
BOOL CWorkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
//设置定时期
SetTimer(WORK_TIMER,10000,NULL);//每隔10秒检测一次
//显示日程信息
CTime tTime=CTime::GetCurrentTime();
CString StrTime=DateToString(tTime);
CString StartDate;
CString EndDate;
CString StrCalendaInfo=L"";
if(m_pSet.IsOpen ())
m_pSet.Close ();
m_pSet.Open (AFX_DB_USE_DEFAULT_TYPE,L"Select * From Calenda order by cStartDate");
if(m_pSet.GetRecordCount ()!=0)
{
m_pSet.MoveFirst ();
while(!m_pSet.IsEOF ())
{
StartDate=DateToString(m_pSet.m_cStartDate );
EndDate=DateToString(m_pSet.m_cEndDate );
if(StartDate<=StrTime&&EndDate>=StrTime)
{
StrCalendaInfo+=(CString)m_pSet.m_cName+L"; ";
}
m_pSet.MoveNext ();
}
}
m_pSet.Close ();
if(StrCalendaInfo!=L"")
SetDlgItemText(IDC_WORK_CALENDA_STATIC,StrCalendaInfo);
//下面显示名言
CString StrLogion;
if(m_pLogionSet.IsOpen())
m_pLogionSet.Close();
m_pLogionSet.Open();
int Count;
m_pLogionSet.m_strFilter .Empty ();
Count=m_pLogionSet.GetRecordCount();
if(Count==0)//如果没有名言,则显示默认的名言,要很经典才行
{
StrLogion=L"只有向自己提出伟大的目标并以自己的全部力量为之奋斗的人,才是幸福的人。";
SetDlgItemText(IDC_TODAY_LOGION_STATIC,StrLogion);
m_pLogionSet.Close ();
}
else//否则随机选择显示
{
Count=0;
m_pLogionSet.MoveFirst();
while(!m_pLogionSet.IsEOF())
{
m_pLogionSet.MoveNext();
Count++;//先计算总数
}
m_pLogionSet.MoveFirst();//再跳回到第一个
srand((unsigned)time(NULL)*rand());
srand((unsigned) time(NULL)*rand());//为了防止和主界面的相同,在这里采用不同的算法
srand(rand());//再种多一个随机种子
int rth=rand()%Count;//随机找到那个
int i=0;
while(!m_pLogionSet.IsEOF())
{
if(i==rth)//随机取一个
{
StrLogion=m_pLogionSet.m_lContent;//直接复制,并且退出循环
break;
}
i++;
m_pLogionSet.MoveNext();
}
m_pLogionSet.Close();
}
SetDlgItemText(IDC_TODAY_LOGION_STATIC,StrLogion);
//
TCITEM item;
item.mask =TCIF_TEXT;
CRect r;
m_Work_TabCtrl.GetClientRect (&r);
item.pszText =_T("兼 职");
m_Work_TabCtrl.InsertItem (0,&item);
item.pszText =_T("日 程");
m_Work_TabCtrl.InsertItem (1,&item);
//
m_WorkParttimeDlg.Create (IDD_WORK_PARTTIME_DLG, &m_Work_TabCtrl);
m_WorkCalendaDlg.Create (IDD_WORK_CALENDA_DLG, &m_Work_TabCtrl);
//
m_WorkParttimeDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_WorkCalendaDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CWorkDlg::OnTcnSelchangeWorkTab(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
CRect r;
m_Work_TabCtrl.GetClientRect (&r);
switch(m_Work_TabCtrl.GetCurSel ())
{
case 0:
m_WorkParttimeDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_WorkCalendaDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
break;
case 1:
m_WorkParttimeDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_WorkCalendaDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
break;
}
*pResult = 0;
}
void CWorkDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(nIDEvent==WORK_TIMER)
{
//显示日程信息
// pThread=AfxBeginThread(ThreadFunc,&m_pSet);
CTime tTime=CTime::GetCurrentTime();
CString StrTime=DateToString(tTime);
CString StartDate;
CString EndDate;
CString StrCalendaInfo=L"";
if(m_pSet.IsOpen ())
m_pSet.Close ();
m_pSet.Open (AFX_DB_USE_DEFAULT_TYPE,L"Select * From Calenda order by cStartDate");
if(m_pSet.GetRecordCount ()==0)
return ;
m_pSet.MoveFirst ();
while(!m_pSet.IsEOF ())
{
StartDate=DateToString(m_pSet.m_cStartDate );
EndDate=DateToString(m_pSet.m_cEndDate );
if(StartDate<=StrTime&&EndDate>=StrTime)
{
StrCalendaInfo+=(CString)m_pSet.m_cName+L"; ";
}
m_pSet.MoveNext ();
}
m_pSet.Close ();
if(StrCalendaInfo!=L"")
SetDlgItemText(IDC_WORK_CALENDA_STATIC,StrCalendaInfo);
//下面显示名言
CString StrLogion;
if(m_pLogionSet.IsOpen())
m_pLogionSet.Close();
m_pLogionSet.Open();
int Count;
m_pLogionSet.m_strFilter .Empty ();
Count=m_pLogionSet.GetRecordCount();
if(Count==0)//如果没有名言,则显示默认的名言,要很经典才行
{
StrLogion=L"只有向自己提出伟大的目标并以自己的全部力量为之奋斗的人,才是幸福的人。";
SetDlgItemText(IDC_TODAY_LOGION_STATIC,StrLogion);
m_pLogionSet.Close ();
}
else//否则随机选择显示
{
Count=0;
m_pLogionSet.MoveFirst();
while(!m_pLogionSet.IsEOF())
{
m_pLogionSet.MoveNext();
Count++;//先计算总数
}
m_pLogionSet.MoveFirst();//再跳回到第一个
srand((unsigned)time(NULL)*rand());
srand((unsigned) time(NULL)*rand());//为了防止和主界面的相同,在这里采用不同的算法
srand(rand());//再种多一个随机种子
int rth=rand()%Count;//随机找到那个
int i=0;
while(!m_pLogionSet.IsEOF())
{
if(i==rth)//随机取一个
{
StrLogion=m_pLogionSet.m_lContent;//直接复制,并且退出循环
break;
}
i++;
m_pLogionSet.MoveNext();
}
m_pLogionSet.Close();
}
SetDlgItemText(IDC_TODAY_LOGION_STATIC,StrLogion);
}
CDialog::OnTimer(nIDEvent);
}
void CWorkDlg::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
KillTimer(WORK_TIMER);
CDialog::OnClose();
}
void CWorkDlg::OnCancel()
{
// TODO: 在此添加专用代码和/或调用基类
DestroyWindow();
}
void CWorkDlg::PostNcDestroy()
{
// TODO: 在此添加专用代码和/或调用基类
CDialog::PostNcDestroy();
AfxGetMainWnd()->SendMessage(WM_USER_WORKDLG_DESTROYED,0,0);
delete this;
}
HBRUSH CWorkDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何属性
if(m_bColor)//如果用系统的,则直接返回
return hbr;
pDC->SetTextColor (m_RGB_CtrlColor);
pDC->SetBkMode(BKMODE_LAST);pDC->SetBkColor (m_RGB_BkColor);
return (HBRUSH)m_brush.GetSafeHandle ();
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
// return hbr;
}
void CWorkDlg::OnWorkCalenda ()
{
CRect r;
m_Work_TabCtrl.GetClientRect (&r);
m_Work_TabCtrl.SetCurSel(1);
m_WorkParttimeDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
m_WorkCalendaDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
}
void CWorkDlg::OnWorkParttime ()
{
CRect r;
m_Work_TabCtrl.GetClientRect (&r);
m_Work_TabCtrl.SetCurSel(0);
m_WorkParttimeDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
m_WorkCalendaDlg.SetWindowPos(NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
}
void CWorkDlg::OnWorkClose ()
{
this->DestroyWindow ();
}
void CWorkDlg::OnUpdateWorkParttime (CCmdUI *pCmdUI)
{
pCmdUI->SetCheck (m_Work_TabCtrl.GetCurSel ()==0);
}
void CWorkDlg::OnUpdateWorkCalenda(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck (m_Work_TabCtrl.GetCurSel ()==1);
}
void CWorkDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: 在此处添加消息处理程序代码
CMenu menu;
CPoint pos=point;
ScreenToClient(&pos);
CRect rect;
GetClientRect(&rect);
if(rect.PtInRect (pos))
{
menu.LoadMenu(IDR_WORK_MENU);
menu.GetSubMenu (0)->TrackPopupMenu (TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
return ;
}
CWnd::OnContextMenu (pWnd,point);
}
void CWorkDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{
ASSERT(pPopupMenu != NULL); // Check the enabled state of various menu items.
CCmdUI state;
state.m_pMenu = pPopupMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL); // Determine if menu is popup in top-level menu and set m_pOther to
// it if so (m_pParentMenu == NULL indicates that it is secondary popup).
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu) state.m_pParentMenu = pPopupMenu;
// Parent == child for tracking popup.
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = this;
// Child windows don't have menus--need to go to the top!
if (pParent != NULL &&(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
{
// When popup is found, m_pParentMenu is containing menu.
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue; // Menu separator or invalid cmd - ignore it.
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
// Possibly a popup menu, route to first item of that popup.
state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL||(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||state.m_nID == (UINT)-1)
{
continue; // First item of popup can't be routed to.
}
state.DoUpdate(this, TRUE); // Popups are never auto disabled.
}
else
{ // Normal menu item.
// Auto enable/disable if frame window has m_bAutoMenuEnable
// set and command is _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(this, FALSE);
}
// Adjust for menu deletions and additions.
UINT nCount = pPopupMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -