📄 myclockdlg.cpp
字号:
else
{
m_BDBSTime=true;
}
if(m_BDBSTime)
{
m_strBDBS=_T("1");
}
else
{
m_strBDBS=_T("0");
}
this->WriteFile1();
}
void CMyClockDlg::OnZdbs()
{
// TODO: Add your command handler code here
if(m_ZDBSTime)
{
m_ZDBSTime=false;
}
else
{
m_ZDBSTime=true;
}
if(m_ZDBSTime)
{
m_strZDBS=_T("1");
}
else
{
m_strZDBS=_T("0");
}
this->WriteFile1();
}
//整点报时和半点报时配置的信息
void CMyClockDlg::WriteFile1()
{
CFile file;
file.Open(_T("BDZD.ini"),CFile::modeCreate | CFile::modeWrite);
file.Write(m_strBDBS,m_strBDBS.GetLength());
file.Write(m_strZDBS,m_strZDBS.GetLength());
file.Close();
}
void CMyClockDlg::ReadFile1()
{
CFile file;
if(!file.Open(_T("BDZD.ini"), CFile::modeRead))
{
return ;
}
else
{
char ch[3];
memset(ch,'0',3);
file.Read(ch,3);
m_strBDBS.Format(_T("%c"),ch[0]);
m_strZDBS.Format(_T("%c"),ch[1]);
}
file.Close();
if(m_strBDBS==_T("1"))
{
m_BDBSTime=true;
}
else
{
m_BDBSTime=false;
}
if(m_strZDBS==_T("1"))
{
m_ZDBSTime=true;
}
else
{
m_ZDBSTime=false;
}
}
void CMyClockDlg::OnZl()
{
// TODO: Add your command handler code here
CZLDDLG dlg;
dlg.DoModal();
}
void CMyClockDlg::OnAutorun()
{
// TODO: Add your command handler code here
if(m_IsAutoRun)
{
m_IsAutoRun=false;
}
else
{
m_IsAutoRun=true;
}
if(m_IsAutoRun)
{
m_strAutoRun=_T("1");
}
else
{
m_strAutoRun=_T("0");
}
this->AutoRun(m_IsAutoRun);
this->WriteFile2();
}
void CMyClockDlg::OnUpdateAutorun(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_IsAutoRun);
}
void CMyClockDlg::OnTopmost()
{
// TODO: Add your command handler code here
if(m_IsTopMost)
{
m_IsTopMost=false;
}
else
{
m_IsTopMost=true;
}
if(m_IsTopMost)
{
m_strTopMost=_T("1");
}
else
{
m_strTopMost=_T("0");
}
this->TopMost(m_IsTopMost);
this->WriteFile2();
}
void CMyClockDlg::OnUpdateTopmost(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_IsTopMost);
}
//开机运行和窗口置于最顶层的配置信息
void CMyClockDlg::WriteFile2()
{
CFile file;
file.Open(_T("AuTop.ini"),CFile::modeCreate | CFile::modeWrite);
file.Write(m_strAutoRun,m_strAutoRun.GetLength());
file.Write(m_strTopMost,m_strTopMost.GetLength());
file.Close();
}
void CMyClockDlg::ReadFile2()
{
CFile file;
if(!file.Open(_T("AuTop.ini"), CFile::modeRead))
{
return ;
}
else
{
char ch[3];
memset(ch,'0',3);
file.Read(ch,3);
m_strAutoRun.Format(_T("%c"),ch[0]);
m_strTopMost.Format(_T("%c"),ch[1]);
}
file.Close();
if(m_strAutoRun==_T("1"))
{
m_IsAutoRun=true;
}
else
{
m_IsAutoRun=false;
}
if(m_strTopMost==_T("1"))
{
m_IsTopMost=true;
}
else
{
m_IsTopMost=false;
}
}
void CMyClockDlg::BDZDTime()//半点 整点报时
{
CTime time=CTime::GetCurrentTime();
int min,sec;
min=time.GetMinute();
sec=time.GetSecond();
if(m_BDBSTime)
{
if(min==30&&sec==0)
{
ShellExecute(this->m_hWnd,_T("open"),_T("FXTime.exe"),_T(""),_T(""),SW_SHOW);
}
}
if(m_ZDBSTime)
{
if(min==0&&sec==0)
{
ShellExecute(this->m_hWnd,_T("open"),_T("FXTime.exe"),_T(""),_T(""),SW_SHOW);
}
}
}
void CMyClockDlg::AutoRun(BOOL Is)//开机自动运行
{
HKEY sub;
char bufname[200];
::GetModuleFileName(NULL,bufname,200);
CString str;
str.Format("%s",bufname);
CString skey=
"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
::RegCreateKey(HKEY_LOCAL_MACHINE,skey,&sub);
if(Is)
{
::RegSetValueEx(sub,"MyClock",NULL,REG_SZ,(const BYTE*)str.GetBuffer(0),str.GetLength());
}
else
{
::RegDeleteValue(sub,"MyClock");
}
}
void CMyClockDlg::TopMost(BOOL Is)//窗口置于最顶层
{
CRect rect;
GetWindowRect(rect);
if(Is)
{
this->SetWindowPos(&(this->wndTopMost),rect.left,rect.top,rect.Width(),rect.Height(),NULL);
}
else
{
this->SetWindowPos(&(this->wndNoTopMost),rect.left,rect.top,rect.Width(),rect.Height(),NULL);
}
}
void CMyClockDlg::AddIcon(BOOL Is)//添加系统托盘图标
{
m_traydata.cbSize = sizeof(NOTIFYICONDATA);
m_traydata.hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
m_traydata.hWnd = m_hWnd;
m_traydata.uCallbackMessage=WM_TRARMESSAGE;
char *m_str = "时钟";
strncpy(m_traydata.szTip,m_str,strlen(m_str)+1);//strlen +1表示将空字符拷贝到目标字符串中
m_traydata.uFlags = NIF_ICON |NIF_MESSAGE |NIF_TIP;
if(Is)
{
Shell_NotifyIcon(NIM_ADD,&m_traydata);
}
else
{
Shell_NotifyIcon(NIM_DELETE,&m_traydata);
}
}
LRESULT CMyClockDlg::OnTrayMessage(WPARAM wParam,LPARAM lParam)
{
if (lParam == WM_RBUTTONUP)
{
/*CPoint m_point;
::GetCursorPos(&m_point);
CIconMenu* m_submenu = (CIconMenu*)m_menu.GetSubMenu(0);
m_submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, m_point.x,m_point.y,AfxGetApp()->m_pMainWnd,TPM_LEFTALIGN);*/
CPoint point;
::GetCursorPos(&point);
CMenu menu;
menu.LoadMenu(IDR_MENU1);
CMenu *pmenu=menu.GetSubMenu(0);
pmenu->TrackPopupMenu(TPM_LEFTBUTTON | TPM_LEFTALIGN,point.x,point.y,this);
pmenu->DestroyMenu();
}
if(lParam == WM_LBUTTONDOWN)
{
PostMessage(WM_LBUTTONDOWN,HTCAPTION,0);
}
if(lParam == WM_LBUTTONDBLCLK)
{
str="隐藏时钟";
ShowWindow(SW_SHOW);
}
return 1;
}
void CMyClockDlg::OnDsgj()
{
// TODO: Add your command handler code here
CSETTIME dlg;
dlg.DoModal();
}
void CMyClockDlg::CloseComputer()//关闭计算机
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
// privilege.
if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
CString str;
str="OpenProcessToken failed.";
MessageBox(str);
}
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
{
CString str1;
str1="AdjustTokenPrivileges enable failed.";
MessageBox(str1);
}
// Display the shutdown dialog box and start the time-out countdown.
fResult = InitiateSystemShutdown(NULL, NULL ,0,FALSE, FALSE); // reboot after shutdown
if (!fResult)
{
CString str1;
str1="InitiateSystemShutdown failed.";
MessageBox(str1);
}
}
void CMyClockDlg::OnKsgj()
{
// TODO: Add your command handler code here
this->CloseComputer();
}
void CMyClockDlg::OnIshide()
{
// TODO: Add your command handler code here
if(str=="隐藏时钟")
{
str="显示时钟";
ShowWindow(SW_HIDE);
}
else
{
str="隐藏时钟";
ShowWindow(SW_SHOW);
}
}
void CMyClockDlg::OnUpdateIshide(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetText(str);
}
void CMyClockDlg::OnZysqts()
{
// TODO: Add your command handler code here
CZYSQTS dlg;
dlg.DoModal();
}
void CMyClockDlg::OnLockcomputer()
{
// TODO: Add your command handler code here
CLockComputer dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -