📄 mydialog.cpp
字号:
// MyDialog.cpp : implementation file
//
#include "stdafx.h"
#include "AlarmInfo.h"
#include "MyDialog.h"
#include "fstream.h"
#include "about.h"
#include "MyInfoDlg.h"
#include "SetTimeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MESSAGE_SETTIME WM_USER+100
#define MESSAGE_EXIT WM_USER+1010
BOOL wshow = FALSE; //窗口状态
BOOL active = FALSE; //是否检测到禁止运行程序
MyString* DelProgName = new MyString[20];
CMyInfoDlg* pDlg = NULL;
CSetTimeDlg dlg;
/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/) : CDialog(CMyDialog::IDD, pParent)
{
ShowTime=5000; //5000毫秒=5秒钟
bSetFlag=false;
szMsg="到休息时间了!";
SetMinute = 45;
Minute = 0;
Second = 0;
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_MESSAGE(WM_HOTKEY,OnHotKey)
ON_WM_TIMER()
ON_COMMAND(ID_ABOUT, OnAbout)
ON_COMMAND(ID_CLOSESPY, OnCloseSpy)
ON_COMMAND(ID_SHUTDOWN, OnShutdown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers
void CMyDialog::TrayAdd()
{
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
// nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
strcpy(nid.szTip, "信息提示器");
nid.uCallbackMessage = WM_USER + 10;
nid.uID = 10;
nid.hWnd = m_hWnd;
Shell_NotifyIcon(NIM_ADD, &nid);
ShowWindow(SW_HIDE);
wshow = FALSE;
SetTimer(1, 1000, NULL);//设置OnTimer事件
}
BOOL CMyDialog::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uID = 10;
nid.hWnd = m_hWnd;
Shell_NotifyIcon(NIM_DELETE, &nid);
KillTimer(1);
return CDialog::DestroyWindow();
}
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
TrayAdd();
RegisterHotKey(m_hWnd, MESSAGE_SETTIME, MOD_CONTROL | MOD_ALT, 'S');
RegisterHotKey(m_hWnd, MESSAGE_EXIT, MOD_CONTROL | MOD_ALT, 'X');
TrayAdd();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMyDialog::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
IsTheTime();
CDialog::OnTimer(nIDEvent);
}
bool CMyDialog::IsTheTime()
{
if (Second == 60)
{
Minute++;
Second = 0;
}
else
Second++;
if (Minute == 60)
{
Minute = 0;
}
if (Minute == SetMinute)
{
Minute = 0;
Second = 0;
if (!pDlg)
{
pDlg = new CMyInfoDlg();
pDlg->Create(IDD_INFODIALOG);
}
pDlg->m_Info=szMsg;
pDlg->UpdateData(FALSE);
// ShowCursor(FALSE);
Beep(3000, 100); //提示声音
// Beep(3000, 400); //提示声音
// Beep(4000, 200); //提示声音
pDlg->BringWindowToTop();
pDlg->SetForegroundWindow();
pDlg->ShowWindow(SW_SHOWNORMAL);
pDlg->SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
pDlg->UpdateWindow();
// ShowCursor(TRUE);
Sleep(ShowTime); //显示窗口时间
pDlg->ShowWindow(SW_HIDE);
// pDlg->DestroyWindow();
Second+=5; //补偿暂停的时间
pDlg->ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);
}
return true;
}
void CMyDialog::OnAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlg;
dlg.DoModal();
}
void CMyDialog::OnCloseSpy()
{
// TODO: Add your command handler code here
DestroyWindow();
UnregisterHotKey(m_hWnd, MESSAGE_SETTIME);
UnregisterHotKey(m_hWnd, MESSAGE_EXIT);
::SendMessage(GetSafeHwnd(), WM_CLOSE, 0, 0); //关闭该程序
}
void CMyDialog::OnShutdown()
{
// TODO: Add your command handler code here
ExitWindowsEx(EWX_SHUTDOWN, 0);
}
void CMyDialog::OnHotKey(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your message handler code here and/or call default
switch (wParam)
{
case MESSAGE_SETTIME:
if(!bSetFlag)
{
bSetFlag=true;
CWnd* pWnd=AfxGetApp()->m_pMainWnd;
pWnd->SetForegroundWindow();
pWnd->BringWindowToTop();
pWnd->SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); //置顶窗口
if(dlg.DoModal()!=IDOK)
{
bSetFlag=false;
return;
}
bSetFlag=false;
SetMinute=dlg.m_Time;
szMsg=dlg.m_Msg;
int yn=dlg.m_Pause;
if(yn==0)
KillTimer(1);
else
SetTimer(1, 1000, NULL);//设置OnTimer事件
}
break;
case MESSAGE_EXIT:
KillTimer(1);
OnCloseSpy();
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -