📄 clock.cpp
字号:
// Clock.cpp : Defines the entry point for the application.
//
#include <string.h>
#include <wchar.h>
#include <windows.h>
#include "resource.h"
#include <time.h>
#include "hook.h"
#include <mmsystem.h>
#include <shellapi.h>
#include <winuser.h>
#include <IO.H>
#define WM_WINPOPUP WM_USER+200
#define ID_TIMER 1
#define ID_TIMERSEC 2
//#define YEAR (datetime->tm_year % 100)
//#define MONTH (datetime->tm_mon + 1)
//#define MDAY (datetime->tm_mday)
//#define WDAY (datetime->tm_wday)
#define HOUR (datetime->tm_hour)
#define MIN (datetime->tm_min)
#define SEC (datetime->tm_sec)
CHAR cBuffer[30];//,cEyeOut[800] ;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
void CALLBACK WndPaint (HWND hwnd, HDC hdc);
BOOL CALLBACK EyeDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
VOID CALLBACK EyeOut(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime);
void SizeTheWindow (int *, int *, int *, int *) ;
void SetInternational (void);
char sDate[2], sTime[2], sAMPM[2][5] , aCurrentPath[MAX_PATH];
int iDate, iTime ;
int bz=1,iRestTime;
TCHAR m_MidiOpen[250],m_MidiClose[250]; //PC下用到的MIDI播放和关闭
NOTIFYICONDATA m_tray;
void AddTray();
void AddToSystem();
HWND hWnd,m_hEyeOut=NULL;
HICON hicon;
HINSTANCE hInstance;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = "眼轻松(作者:韦一平)" ;
//HWND hwnd ;
MSG msg ;
int xStart, yStart, xClient, yClient ;
WNDCLASSEX wndclass ;//ex
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = 0;//CS_OWNDC;//CS_HREDRAW | CS_VREDRAW; //|CS_NOCLOSE;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_EYE) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_EYE);
RegisterClassEx (&wndclass) ;
hicon=wndclass.hIconSm ;
SizeTheWindow (&xStart, &yStart, &xClient, &yClient) ;
hWnd = CreateWindow (szAppName, szAppName,
//WS_EX_TOOLWINDOW|WS_MAXIMIZEBOX,
WS_POPUP | WS_DLGFRAME | WS_SYSMENU,
xStart, yStart,
xClient, yClient,
NULL, NULL, hInstance, NULL) ;
//SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE
ShowWindow (hWnd, SW_HIDE);//
UpdateWindow (hWnd) ;
AddToSystem();
AddTray();
DWORD dLenth;
TCHAR tcAppFullPath[MAX_PATH]={'\0'};
dLenth = GetModuleFileName(NULL,tcAppFullPath,MAX_PATH);
strncpy(aCurrentPath,tcAppFullPath,dLenth-9); // Q11PC.exe
strcpy(m_MidiOpen,TEXT("play "));
strcat(m_MidiOpen,aCurrentPath);
strcat(m_MidiOpen,TEXT("\\北国之春.mid "));
strcpy(m_MidiClose,TEXT("close "));
strcat(m_MidiClose,aCurrentPath);
strcat(m_MidiClose,TEXT("\\北国之春.mid"));
// int ihow1=MessageBox(0,m_MidiOpen,"警告",MB_YESNOCANCEL|MB_ICONWARNING|MB_TOPMOST );
// if(ihow1==IDCANCEL)
// exit(0);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
VOID CALLBACK WndPaint (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
// HDC hdc;
// char buf[256];
static char szWday[] = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat" ;
int iLength=0;
// RECT rect ;
struct tm *datetime ;
time_t lTime ;
// SetWindowPos(hwnd,0,0,0,0,SSP_NOSIZE|WSP_NOMOVE);
// BOOL dan;
time (&lTime) ;
datetime = localtime (&lTime) ;
if((MIN==30||MIN==0)&&bz==1)
{
//屏蔽系统热键 很可惜该功能无法在MT上运行,不知有谁能告诉我怎样做吗?
SetTimer (m_hEyeOut, ID_TIMERSEC,1000, EyeOut) ;
ShowWindow(m_hEyeOut,SW_SHOW);//(MessageBox(NULL,"create Dialog Secce","cdlgMsg",MB_OK);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,FALSE,"1",NULL);
EnableWindow(GetDesktopWindow(),FALSE);//在指定的窗口里允许或禁止所有鼠标及键盘输入
// mciSendString(m_MidiOpen,buf,sizeof(buf),NULL);
iRestTime=240;
MessageBeep (-1);
bz=0;
// BringWindowToTop(hwnd);
// SetForegroundWindow(hwnd);
SetWindowPos( hWnd,HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
// SendMessage(hwnd,WM_SETFOCUS, 0, 0);
// SetActiveWindow(hwnd);
SetForegroundWindow(m_hEyeOut);
if(!EnableMouseCapture())MessageBox(NULL,"Lock Kboard Fail","LockMdsg",MB_OK);
;
EnableKboadCapture();
}
if((MIN==34||MIN==4)&&bz==0)
{
DisableMouseCapture();
DisableKboadCapture();
// mciSendString(m_MidiClose,buf,sizeof(buf),NULL);
KillTimer (m_hEyeOut, ID_TIMERSEC);
SetWindowPos( hWnd,HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
ShowWindow(m_hEyeOut,SW_HIDE);//(MessageBox(NULL,"create Dialog Secce","cdlgMsg",MB_OK);
ShowWindow(hwnd,SW_HIDE);//(MessageBox(NULL,"create Dialog Secce","cdlgMsg",MB_OK);
MessageBeep (-1);
bz=1;
//恢复系统热键 很可惜该功能无法在MT上运行,不知有谁能告诉我怎样做吗?
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,TRUE,"1",NULL);
EnableWindow(GetDesktopWindow(),TRUE);
}
/* iLength = wsprintf (cBuffer, " %s %d%s%02d%s%02d \r\n",
(PSTR) szWday + 4 * WDAY,
iDate == 1 ? MDAY : iDate == 2 ? YEAR : MONTH, (PSTR) sDate,
iDate == 1 ? MONTH : iDate == 2 ? MONTH : MDAY, (PSTR) sDate,
iDate == 1 ? YEAR : iDate == 2 ? MDAY : YEAR) ;
if (iTime == 1)
iLength += wsprintf (cBuffer + iLength, " %02d%s%02d%s%02d ",
HOUR, (PSTR) sTime, MIN, (PSTR) sTime, SEC) ;
else
iLength += wsprintf (cBuffer + iLength, " %d%s%02d%s%02d %s ",
(HOUR % 12) ? (HOUR % 12) : 12,
(PSTR) sTime, MIN, (PSTR) sTime, SEC,
(PSTR) sAMPM [HOUR / 12]) ;
hdc=GetDC(hwnd); //1
GetClientRect (hwnd, &rect) ;
DrawText (hdc, cBuffer, -1, &rect, DT_CENTER | DT_NOCLIP) ;
if (cBuffer)
{
lstrcpyn(m_tray.szTip, cBuffer, sizeof(m_tray.szTip));
}
else
{
m_tray.szTip[0] = '\0';
}
ReleaseDC(hwnd,hdc);//1
*/
// Shell_NotifyIcon(NIM_MODIFY , &m_tray);
}
int iShow=SW_SHOW;
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
// HDC hdc ;
// PAINTSTRUCT ps ;
switch (iMsg)
{
case WM_CREATE :
{
SetInternational () ;
m_hEyeOut = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_EYEOUT),
hwnd, EyeDlgProc);
}
return 0 ;
case WM_SYSCOMMAND :
switch(wParam)
{
case SC_MINIMIZE:
ShowWindow (hwnd, SW_HIDE);//SW_SHOW) ;
return 0;
}
case WM_WINPOPUP:
{
// 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();
delete lpoint;*/
}
break;
case WM_LBUTTONUP://双击左键的处理
{
ShowWindow(hwnd,SW_HIDE);//(MessageBox(NULL,"create Dialog Secce","cdlgMsg",MB_OK);
/*
ShowWindow(hwnd,iShow);//简单的显示主窗口完事儿
if(iShow==SW_SHOW)
{
SetForegroundWindow(hwnd);
iShow=SW_HIDE;
}
else
iShow=SW_SHOW;
*/
;
}
break;
}
return 0;
}
case WM_WININICHANGE :
SetInternational () ;
InvalidateRect (hwnd, NULL, TRUE) ;
return 0 ;
case WM_DESTROY :
KillTimer (hwnd, ID_TIMER) ;
Shell_NotifyIcon(NIM_DELETE , &m_tray);
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
void SizeTheWindow (int *pxStart, int *pyStart,
int *pxClient, int *pyClient)
{
HDC hdc ;
TEXTMETRIC tm ;
hdc = CreateIC ("DISPLAY", NULL, NULL, NULL) ;
GetTextMetrics (hdc, &tm) ;
DeleteDC (hdc) ;
*pxClient = GetSystemMetrics (SM_CXDLGFRAME) + 12*tm.tmAveCharWidth ;
*pxStart = GetSystemMetrics (SM_CXSCREEN) - *pxClient ;
*pyClient = int(GetSystemMetrics (SM_CYDLGFRAME) + 1.5*tm.tmHeight );
*pyStart = 0 ;
}
void SetInternational (void)
{
static char cName [] = "intl" ;
iDate = GetProfileInt (cName, "iDate", 0) ;
iTime = GetProfileInt (cName, "iTime", 0) ;
GetProfileString (cName, "sDate", "/", sDate, 2) ;
GetProfileString (cName, "sTime", ":", sTime, 2) ;
GetProfileString (cName, "s1159", "AM", sAMPM[0], 5) ;
GetProfileString (cName, "s2359", "PM", sAMPM[1], 5) ;
}
void AddTray()
{
m_tray.cbSize=sizeof(NOTIFYICONDATA); //结构的大小,必须设置
m_tray.hWnd=hWnd; //接受回调消息的窗口的句柄
m_tray.uID=IDI_CLOCK; //应用程序定义的图标标志
m_tray.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; //标志,可以是NIF_ICON NIF_MESSAGE,NIF_TIP或其组合
m_tray.uCallbackMessage=WM_WINPOPUP; //应用程序定义的回调消息标志
m_tray.hIcon=hicon;//LoadIcon(NULL, (LPCTSTR)IDI_SMALL); //图标句柄
if(!m_tray.hIcon)MessageBox(NULL,"Icon fial","fail",MB_OK);
/*********************************************
发布一定要修改的地方
**********************************************/
// ystrcpyn(m_tray.szTip, cBuffer, sizeof(m_tray.szTip));
// _tcscpy(m_tray.szTip,_T("眼轻松(作者:韦一平)")); //提示字串
strcpy(m_tray.szTip,("眼轻松(作者:韦一平)")); //提示字串
if(!::Shell_NotifyIcon(NIM_ADD,&m_tray))MessageBox(NULL,"ddkd","oidkk",MB_OK);
;
SetTimer (hWnd, ID_TIMER,1000, WndPaint) ;
}
BOOL CALLBACK EyeDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
//HICON m_hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_EYE1);
// SetIcon(m_hIcon); // Set big icon
break;
case WM_DESTROY :
KillTimer (hwnd, ID_TIMERSEC) ;
break;
default:
return FALSE;
}
return TRUE;
}
VOID CALLBACK EyeOut(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
CHAR cEyeOut[300] ;
iRestTime--;
wsprintf (cEyeOut, "请休息:%1d分%2d钞",
int(iRestTime/60),iRestTime%60);
SetDlgItemText(m_hEyeOut,IDC_EYEPRINT,cEyeOut);
}
void AddToSystem()
{
HKEY hKEY;
char CurrentPathSpy[MAX_PATH],CurrentPath[MAX_PATH],CurrentPathBgzc[MAX_PATH];
char SysPath[MAX_PATH],SysPathSpy[MAX_PATH],SysPathBgzc[MAX_PATH];
long ret;
LPSTR FileNewName,FileNewNameSpy,FileNewNameBgzc;
LPSTR FileCurrentName,FileCurrentNameSpy,FileCurrentNameBgzc;
DWORD type=REG_SZ;
DWORD size=MAX_PATH;
LPCTSTR Rgspath="Software\\Microsoft\\Windows\\CurrentVersion\\Run" ;
//Get System Path
GetSystemDirectory(SysPath,size);//系统目录
GetCurrentDirectory(size,CurrentPath);//工作目录
strncpy(aCurrentPath,CurrentPath,7);//[MAX_PATH][MAX_PATH]
lstrcpy(CurrentPathSpy,CurrentPath);//工作目录
lstrcpy(CurrentPathBgzc,CurrentPath);//工作目录
//int ihow1=MessageBox(0,aCurrentPath,"警告1",MB_YESNOCANCEL|MB_ICONWARNING|MB_TOPMOST );
//if(ihow1==IDCANCEL)
// exit(0);
//Copy File
FileCurrentName = lstrcat(CurrentPath,"\\EyeB.exe");//工作目录文件
FileCurrentNameSpy = lstrcat(CurrentPathSpy,"\\Spy1.dll");//spy1.dll
FileCurrentNameBgzc =lstrcat(CurrentPathBgzc,"\\北国之春.mid");//
lstrcpy(SysPathSpy,SysPath);//目标路径
lstrcpy(SysPathBgzc,SysPath);//
FileNewName = lstrcat(SysPath,"\\EyeB.exe");//copy to windir\system\serveZ.exe
FileNewNameSpy= lstrcat(SysPathSpy,"\\Spy1.dll");//copy to windir\system\Spy1.dll
FileNewNameBgzc=lstrcat(SysPathBgzc,"\\北国之春.mid");
struct _finddata_t EyeB;
if(_findfirst(FileNewName,&EyeB)!=-1)
return;//已经安装!
int ihow=MessageBox(0,"该程序将在半点和整点琐住键盘和鼠标!\n继续运行该程序将使这台机器处于被控制的状态!\n如果您不想这样,请按“取消”按钮退出。\n按下“是”按钮该程序将被复制到您的机器上,并随系统启动自动运行。\n按下“否”按钮,程序只运行一次,不会在您的系统内留下任何东西。","警告",MB_YESNOCANCEL|MB_ICONWARNING|MB_TOPMOST );
if(ihow==IDCANCEL)
exit(0);
if(ihow==IDNO)
return;//只运行一次
//复制文件
ret = CopyFile(FileCurrentName,FileNewName,TRUE);
if (!ret)
{
MessageBox(NULL,"Copy Eye fail","CpyEye",MB_OK);
return ;
}
// MessageBox(NULL,FileCurrentName,FileNewNameSpy,MB_OK);
ret = CopyFile(FileCurrentNameSpy,FileNewNameSpy,TRUE);
if (!ret)
{
MessageBox(NULL,"Copy Spy fail","CpyEye",MB_OK);
return ;
}
ret = CopyFile(FileCurrentNameBgzc,FileNewNameBgzc,TRUE);
if (!ret)
{
MessageBox(NULL,"Copy Bgzc fail","CpyEye",MB_OK);
return ;
}
//else MessageBox(NULL,"Copy Bgzc Succe","CpyEye",MB_OK);
//加入注册表
ret=RegOpenKeyEx(HKEY_LOCAL_MACHINE,Rgspath,0,KEY_WRITE, &hKEY);
if(ret!=ERROR_SUCCESS)
{
RegCloseKey(hKEY);
return ;
}
//Set Key
ret=RegSetValueEx(hKEY,"Eye",NULL,type,(const unsigned char*)FileNewName,size);
if(ret!=ERROR_SUCCESS)
{
RegCloseKey(hKEY);
return ;
}
RegCloseKey(hKEY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -