📄 timerecorddlg.cpp
字号:
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
for(int i=0;i<counts;i++)
{
lvitem.iItem=i;
m_list.InsertItem(&lvitem);
for(int j=0;j<m_fields.GetSize();j++)
m_list.SetItemText(i,j,values[i].GetAt(j));
}
temp.Format("共有%d条提醒信息",counts);
SetDlgItemText(IDC_STATIC_LIST,temp);
}
void CTimerecordDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CStringArray values;
POSITION pos = m_list.GetFirstSelectedItemPosition();
if (pos == NULL)
{
*pResult = 0;
return;//TRACE0("No items were selected!\n");
}
else
{
while (pos)
{
int nItem = m_list.GetNextSelectedItem(pos);
//TRACE1("Item %d was selected!\n", nItem);
// you could do your own processing on nItem here
for(int i=0;i<m_fields.GetSize();i++)
values.Add( m_list.GetItemText( nItem, i ));
break;
}
}
CString temp,temp1;
int Y,M,D,h,m,s;
SetDlgItemText(IDC_EDIT_ID,values.GetAt(6));
SetDlgItemText(IDC_EDIT_TITILE,values.GetAt(0));
SetDlgItemText(IDC_EDIT_TEXT,values.GetAt(1));
temp = values.GetAt(2);
temp1=temp.Left(temp.Find("-",0));
Y=atoi(temp1);
temp1=temp1+"-";
temp.Replace(temp1,"");
temp1=temp.Left(temp.Find("-",0));
M=atoi(temp1);
temp1=temp1+"-";
temp.Replace(temp1,"");
D=atoi(temp);
temp = values.GetAt(3);
temp1=temp.Left(temp.Find(":",0));
h=atoi(temp1);
temp1=temp1+":";
temp.Replace(temp1,"");
temp1=temp.Left(temp.Find(":",0));
m=atoi(temp1);
temp1=temp1+":";
temp.Replace(temp1,"");
s=atoi(temp);
CTime time(Y,M,D,h,m,s);
m_date=time;
m_time=time;
values.GetAt(4)=="1"?m_use=true:m_use=false;
UpdateData(false);
SetDlgItemText(IDC_BUTTON_ADD_EDIT,"修 改");
GetDlgItem(IDC_CHECK_USE)->ShowWindow(true);
*pResult = 0;
}
void CTimerecordDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
if(m_list.GetSelectedCount() !=1)
return;
CPoint point;
GetCursorPos(&point);//GetWindowRect(&rect);
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(IDR_MENU_POP));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN
| TPM_RIGHTBUTTON, point.x,
point.y, pWndPopupOwner);
*pResult = 0;
}
void CTimerecordDlg::initADDorEDIT()
{
CTime nowtime = CTime::GetCurrentTime();
m_time = nowtime;
m_date = nowtime;
SetDlgItemText(IDC_EDIT_TITILE,"");
SetDlgItemText(IDC_EDIT_TEXT,"");
m_use=false;
GetDlgItem(IDC_CHECK_USE)->ShowWindow(false);
UpdateData(false);
}
void CTimerecordDlg::OnMenuitemDelrecord()
{
// TODO: Add your command handler code here
CString temp,titile;
POSITION pos = m_list.GetFirstSelectedItemPosition();
if (pos == NULL)
return;//TRACE0("No items were selected!\n");
else
{
while (pos)
{
int nItem = m_list.GetNextSelectedItem(pos);
//TRACE1("Item %d was selected!\n", nItem);
// you could do your own processing on nItem here
temp = m_list.GetItemText( nItem, 6);
titile = m_list.GetItemText( nItem, 0);
break;
}
}
char msg[255];
titile="真的要删除标题为'"+titile+"'的记录吗?";
if(AfxMessageBox(titile,MB_YESNO)!=IDYES)
return;
temp="where id="+temp;
strcpy(msg,temp);
if(theApp.m_pingdatabase->_deleteRecord("recordmsg",msg,1,msg) !=1)
{
temp.Format("%s",msg);
AfxMessageBox(temp);
return;
}
AfxMessageBox("成功删除此条信息");
OnRadio1();
}
void CTimerecordDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CString sql,date,time;
CTime nowtime = CTime::GetCurrentTime();
date = nowtime.Format(_T("%Y-%m-%d"));
time = nowtime.Format(_T("%H:%M:%S"));
switch(m_radio)
{
case 0:
sql="";
break;
case 1:
sql="where use='0'";
break;
case 2:
sql="where use='1'";
break;
case 3:
sql="where date='"+date+"' and time>='"+time+"' or date >'"+date+"'";
break;
default:
break;
}
showWideToListCtrl(sql,0);
}
void CTimerecordDlg::running (WPARAM wParam, LPARAM lParam)
{
if(!m_xc_date.run)
{
TerminateThread( Thread, 0);
KillTimer(1);
KillTimer(3);
Shell_NotifyIcon(NIM_DELETE, &nid);
CDialog::OnCancel();
}
else
{
for(int i=0;i<m_xc_date.id.GetSize();i++)
{
bool s=false;
for(int j=0;j<id.GetSize();j++)
{
if(id.GetAt(j)==m_xc_date.id.GetAt(i))
{
s=true;
break;
}
}
if(!s)
id.Add( m_xc_date.id.GetAt(i));
}
m_xc_date.id.RemoveAll();
}
}
UINT xc_check(LPVOID pParam)
{
XC_DATE* m_xc_date = (XC_DATE*) pParam;
while(m_xc_date->run)
{
CTime nowtime=CTime::GetCurrentTime();
CString date,time,sql;
date = nowtime.Format(_T("%Y-%m-%d"));
time = nowtime.Format(_T("%H:%M:%S"));
sql.Format("where date='%s' and time ='%s'",date,time);
char msg[255];
strcpy(msg,sql);
int counts = theApp.m_pingdatabase->_selectCountsFromDatabase("recordmsg",msg,msg);
if(counts>0)
{
CStringArray *myvalues,myfields;
myvalues = new CStringArray[counts];
myfields.Add("id");
if( theApp.m_pingdatabase->_selectDataFromDatabase("recordmsg",msg,&myfields,myvalues,counts,msg) ==counts)
{
for(int i=0;i<counts;i++)
m_xc_date->id.Add((myvalues+i)->GetAt(0));
::PostMessage(m_xc_date->m_xc,WM_MAX_XC,0,0);
}
}
Sleep(1000);
}
::PostMessage(m_xc_date->m_xc,WM_MAX_XC,0,0);
return 0;
}
void CTimerecordDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)//显示提示
{
if(id.GetSize()>0)
{
if(showmsg==false)
{
CShowMsg m_dlg;
m_dlg.id=id.GetAt(0);
showmsg=true;
m_dlg.DoModal();
showmsg=false;
id.RemoveAt(0);
}
}
}
else if(nIDEvent==2)//检查是否有提示的
{
KillTimer(2);
this->ShowWindow(SW_HIDE);
m_xc_date.m_xc = m_hWnd;
m_xc_date.run = true;
m_xc_date.id.RemoveAll();
Thread = AfxBeginThread( xc_check, &m_xc_date);
}
else if(nIDEvent==3)//显示时间
{
CString temp;
CTime nowtime = CTime::GetCurrentTime();
temp = nowtime.Format(_T("现在时间:%Y-%m-%d %H:%M:%S"));
SetDlgItemText(IDC_STATIC_NOWTIME,temp);
}
CDialog::OnTimer(nIDEvent);
}
void CTimerecordDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(cx==0&&cy==0)
ShowWindow(SW_HIDE);//隐藏主窗口
}
LRESULT CTimerecordDlg::onShowTask(WPARAM wParam,LPARAM lParam)//wParam接收的是图标的ID,而lParam接收的是鼠标的行为
{
if(wParam!=IDR_MAINFRAME)
return 1;
switch(lParam)
{
case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭”
{
LPPOINT lpoint=new tagPOINT;
::GetCursorPos(lpoint);//得到鼠标位置
/* CMenu menu;
menu.CreatePopupMenu();//声明一个弹出式菜单
//增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已
//隐藏),将程序结束。
menu.AppendMenu(MF_STRING,WM_DESTROY,"关闭");
//确定弹出式菜单的位置
menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this);
//资源回收
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
*/
CMenu menu;
VERIFY(menu.LoadMenu(IDR_MENU_POP));
CMenu* pPopup = menu.GetSubMenu(1);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN
| TPM_RIGHTBUTTON, lpoint->x,
lpoint->y, pWndPopupOwner);
delete lpoint;
}
break;
case WM_LBUTTONDBLCLK://双击左键的处理
{
this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿
ShowWindow(SW_SHOWDEFAULT);
}
break;
}
return 0;
}
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if(m_showabout)
{
maxtime=10;
SetTimer(1,1000,NULL);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
maxtime--;
if(maxtime==0)
{
PostMessage(WM_CLOSE,0,0);
}
else
{
CString temp;
temp.Format("关于 信息提醒小秘书 (在%d秒后自动关闭)",maxtime);
SetWindowText(temp);
}
}
CDialog::OnTimer(nIDEvent);
}
void CTimerecordDlg::OnMenuitemAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlgAbout;
dlgAbout.m_showabout=false;
dlgAbout.DoModal();
}
void CTimerecordDlg::OnMenuitemShowframe()
{
// TODO: Add your command handler code here
this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿
ShowWindow(SW_SHOWDEFAULT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -