某一天下班忘了打卡....啊想破脑袋也记不起来下班的时间了...
难道就没有什么东西记录了我关机时间吗,难道加班费就这样没了....
对了,系统事件查看器,可是面里一大堆东西,只有出错记录,没有关机记录...
于是修改了以前的一个时钟
软件启动后会自行设定自启动
开机关机注销启动均会记录在注册表中
32位系统是在 [HKEY_LOCAL_MACHINE\SOFTWARE\TXTCLOCK]
64位系统是在 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\TXTCLOCK]
TXTCLOCK http://pan.baidu.com/s/1kV2oE5h
自行安装里面附带字体
//程序名:文本时钟/TextClock
//作者wisepragma
//主页:http://blog.csdn.net/wisepragma
//taskkill /im textclock.exe
//cl textclock.cpp /W3
//start textclock.exe
//#define UNICODE
#define _WIN32_WINNT 0x5051
#include <windows.h>
#include <winternl.h>
#include "registryconfig.h"
#include "tchar.h"
#include <stdio.h>
#include <WtsApi32.h>
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"WtsApi32.lib")
TCHAR * ClsName =TEXT("class_TextClock");
TCHAR * WndName = TEXT("window_TextClock");
TCHAR * lpszDayOfWeek[]= { TEXT("Sunday"),TEXT("Monday"),TEXT("Tuesday"),TEXT("Wednesday"),TEXT("Thursday"), TEXT("Friday"), TEXT("Saturday") };
TCHAR * lpszMonthOfYear[]= { TEXT("January"), TEXT("February"), TEXT("March"), TEXT("April"), TEXT("May"), TEXT("June"), TEXT("July"), TEXT("August"), TEXT("September"), TEXT("October"), TEXT("November"), TEXT("December")};
bool bAdjustWindow=TRUE;
const DWORD TEXTCOLOR=(RGB(48,157,163));// (RGB(202,202,202));//白灰
class TIMESTAMP
{
private:
RegistryConfig regtime;
TCHAR m_buf[100];
SYSTEMTIME m_st;
public:
TIMESTAMP()
{
regtime.reset(TEXT("Software\\TXTCLOCK"));
}
void setstamp(TCHAR *stamp)
{
memset(m_buf,0,sizeof(m_buf));
getcurtime(m_st);
gettimestr(m_st,m_buf,100);
regtime.set(m_buf,stamp);
}
void getcurtime(SYSTEMTIME &tt)
{
memset(&tt,0,sizeof(tt));
GetLocalTime(&tt);
}
void gettimestr(SYSTEMTIME &tt,TCHAR *buffer,DWORD buflen)
{
TCHAR *timeFormat=TEXT("%04d.%02d.%02d-%02d:%02d:%02d ");
memset(buffer,0,buflen);
wsprintf(buffer,timeFormat,tt.wYear,tt.wMonth,tt.wDay, tt.wHour,tt.wMinute,tt.wSecond);
}
};
TIMESTAMP ts;
RegistryConfig startup;
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT Msg,WPARAM wParam, LPARAM lParam)
{
static SYSTEMTIME sysTime;
static TCHAR buffer[100];
static HDC hdc;
static PAINTSTRUCT ps;
static LOGFONT lf;
static HBRUSH hbr;
static HRGN hrgn;
static HFONT hf;
static TEXTMETRIC tm;
switch(Msg)
{
case WM_QUERYENDSESSION:
{
// if(IDYES==MessageBoxA(hwnd,"是否允许?","我要关机了",MB_YESNO|MB_ICONQUESTION|MB_TOPMOST))
{
ts.setstamp(TEXT("系统关机/注销"));
return TRUE;//允许关机
}
// else return FALSE;//取消关机
}
break;
case WM_POWERBROADCAST:
{
if( wParam ==PBT_APMQUERYSUSPEND )
{
ts.setstamp(TEXT("系统休眠/待机"));
//return BROADCAST_QUERY_DENY;//取消休眠,待机
}
if( wParam ==PBT_APMRESUMESUSPEND )//BUGFIXED:休眠醒来后窗口残缺
{
ts.setstamp(TEXT("系统唤醒"));
bAdjustWindow=true;
InvalidateRect(hwnd,NULL,FALSE);
}
}
break;
case WM_TIMER:
InvalidateRect(hwnd,NULL,FALSE);
return 0;
case WM_CREATE:
SetTimer(hwnd,WM_NULL,100,NULL);
return 0;
case WM_LBUTTONDOWN:
if( GetKeyState(VK_CONTROL)&0x80000000 )SendMessage(hwnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam);
return 0;
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps);
GetTextMetrics(hdc,&tm);
memset(&lf,0,sizeof(lf));
lf.lfHeight=tm.tmHeight*4;
lf.lfWeight =FW_HEAVY;//FW_THIN,FW_BLACK FW_REGULAR;// FW_HEAVY FW_BLACK FW_DONTCARE
lf.lfItalic=TRUE;
TCHAR *FontFaceName=TEXT("Monotype Corsiva");
//DotumCheTEXT("Garamond");//TEXT("Nina");//TEXT("Courier New 7");TEXT("Monotype Corsiva");//TEXT("Monotype Corsiva")TEXT("Lucida Console"))TEXT("Fixedsys")TEXT("Verdana"))TEXT("DotumChe")TEXT("Arial Black"))TEXT("幼圆")
lstrcpy(lf.lfFaceName,FontFaceName);
memset(&sysTime,0,sizeof(sysTime));
GetLocalTime(&sysTime);
TCHAR *timeFormat=TEXT("%s %02ld,%ld.[%s]%02ld:%02ld.%02ld");
wsprintf(buffer,timeFormat,
lpszMonthOfYear[sysTime.wMonth-1]/*January在序号0*/,sysTime.wDay,sysTime.wYear,
lpszDayOfWeek[sysTime.wDayOfWeek]/*Sunday在序号0*/,
sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
hf=CreateFontIndirect(&lf);//+font(创建)
SelectObject(hdc,hf);// =font(使用)
RECT rectDesktop;
SystemParametersInfo(SPI_GETWORKAREA,0,&rectDesktop,0);
SIZE czStr;
GetTextExtentPoint32(hdc,buffer,lstrlen(buffer),&czStr);//根据字符串字体取得显示的宽度和亮度,然后用于首次显示调整窗体位置和大小
if(bAdjustWindow)
{
MoveWindow( hwnd, GetSystemMetrics(SM_CXFULLSCREEN)-czStr.cx-25,//微调
rectDesktop.bottom-czStr.cy,//rectDesktop.bottom是系统状态栏最高处的纵坐标
czStr.cx+20,
czStr.cy,
TRUE);
bAdjustWindow=false;
}
SetBkMode(hdc,TRANSPARENT);
BeginPath(hdc);
TextOut(hdc,0,0,buffer,lstrlen(buffer));
EndPath(hdc);
hrgn=PathToRegion(hdc);// +hrgn
hbr=CreateSolidBrush(TEXTCOLOR);//+Brush
FillRgn(hdc,hrgn,hbr);//=Brush
SetWindowRgn(hwnd,hrgn,TRUE);//=-hrgn(使用并删除)
DeleteObject(hbr);//-Brush
DeleteObject(hf);//-font(删除)
EndPaint(hwnd,&ps);
}
return 0;
case WM_KEYDOWN:
if(wParam==VK_ESCAPE) PostQuitMessage(WM_QUIT);
return 0;
case WM_CLOSE:
case WM_DESTROY:
{
//============...App died ======
ts.setstamp(TEXT("...App终止"));
//==================================
PostQuitMessage(WM_QUIT);
return 0;
}
}
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE,LPSTR lpCmdLine, int nCmdShow)
{
HANDLE hMutex=CreateMutex(NULL,FALSE,TEXT("OnlyOneInstance_TextClock"));
if( hMutex==NULL || ERROR_ALREADY_EXISTS==GetLastError() )
{
HWND hwnd=FindWindow(ClsName,WndName);
if(hwnd!=NULL)
{
BringWindowToTop(hwnd);
SetForegroundWindow(hwnd);
}
return 0;
}
startup.setautorun(TEXT("TXTCLOCK"));//AUTOSTARTUP
//============...App start time ======
ts.setstamp(TEXT("...App启动"));
//==================================
WNDCLASSEX m_WndClsEx;
m_WndClsEx.cbSize = sizeof(WNDCLASSEX);
m_WndClsEx.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
m_WndClsEx.lpfnWndProc = MainWndProc;
m_WndClsEx.cbClsExtra = 0;
m_WndClsEx.cbWndExtra = 0;
m_WndClsEx.hInstance = hInstance;
m_WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
m_WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
m_WndClsEx.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
m_WndClsEx.lpszMenuName = NULL;
m_WndClsEx.lpszClassName = ClsName;
m_WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&m_WndClsEx);
HWND hwnd = CreateWindowEx (WS_EX_TOOLWINDOW, //WS_EX_TOPMOST|
ClsName,WndName,WS_POPUPWINDOW,
0,0,1,1,
NULL, NULL, hInstance, NULL);
ShowWindow (hwnd,SW_SHOWNORMAL);
UpdateWindow (hwnd);
MSG Msg;
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
#pragma once
//#include <tchar.h>
//#include <stdio.h>
//#include <windows.h>
#include <winreg.h>
class RegistryConfig
{
private:
HKEY m_hRootKey;
HKEY m_hKey;
TCHAR *m_szSubKey;
char *m_pbValueData;
public:
~RegistryConfig()
{
if( NULL!=m_szSubKey )
{
delete []m_szSubKey;
m_szSubKey=NULL;
}
if( NULL!=m_pbValueData)
{
delete []m_pbValueData;
m_pbValueData=NULL;
}
RegCloseKey(m_hKey);
}
RegistryConfig()
{
}
RegistryConfig(TCHAR *szSubKey)
{
reset(szSubKey);
}
bool reset(TCHAR *szSubKey)
{
m_hRootKey=HKEY_LOCAL_MACHINE;
m_pbValueData=NULL;
//LPCTSTR SubKey=TEXT("SOFTWARE\\WisePragma");
/
m_szSubKey=new TCHAR[ lstrlen(szSubKey)*sizeof(TCHAR)];
lstrcpy(m_szSubKey,szSubKey);
//_tprintf(TEXT("---------------------- -------------------------------\n"));
if(ERROR_SUCCESS==RegOpenKeyEx(m_hRootKey,m_szSubKey,0,KEY_ALL_ACCESS,&m_hKey) )
{
// _tprintf(TEXT("RegOpenKeyEx成功!\n"));
}
else
{
// _tprintf(TEXT("RegOpenKeyEx失败!\n"));
if (ERROR_SUCCESS==RegCreateKey(m_hRootKey,m_szSubKey,&m_hKey))
{
// _tprintf(TEXT("RegCreateKey成功!\n"));
return true;
}
else
{
// _tprintf(TEXT("RegCreateKey失败!\n"));
}
}
// _tprintf(TEXT("---------------------- -------------------------------\n"));
return false;
}
bool deleteValue(TCHAR *szValueName)
{
if(NULL==szValueName || 0==lstrcmp(szValueName,TEXT("")) ) return false;
if( m_hKey!=NULL && ERROR_SUCCESS==RegDeleteValue(m_hKey, szValueName) )
{
return true;
}
else
{
return false;
}
}
bool setautorun(TCHAR *autoName)
{
HKEY key;
m_hRootKey = HKEY_LOCAL_MACHINE;
LPCTSTR m_szSubKey = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
if (ERROR_SUCCESS == RegOpenKeyEx(m_hRootKey, m_szSubKey, 0, KEY_ALL_ACCESS, &key))
{
// _tprintf(TEXT("RegOpenKeyEx成功!\n"));
}
else
{
// _tprintf(TEXT("RegOpenKeyEx失败!\n"));
if (ERROR_SUCCESS == RegCreateKey(m_hRootKey, m_szSubKey, &key))
{
// _tprintf(TEXT("RegCreateKey成功!\n"));
}
else
{
// _tprintf(TEXT("RegCreateKey失败!\n"));
return false;
}
}
TCHAR appname[MAX_PATH];
GetModuleFileName(NULL, appname, MAX_PATH);//TEXT("TXTCLOCK")
DWORD cbLen = lstrlen(appname)*sizeof(TCHAR);
if (key != NULL && ERROR_SUCCESS == RegSetValueEx(key, autoName, 0, REG_SZ, (const BYTE *)&appname, cbLen))
{
// _tprintf(TEXT("RegSetValueEx成功!\n"));
return true;
}
else
{
// _tprintf(TEXT("RegSetValueEx失败!\n"));
return false;
}
}
bool set(TCHAR *szValueName,DWORD dwValueData)
{
if(m_hKey!=NULL && ERROR_SUCCESS==RegSetValueEx(m_hKey,szValueName,0,REG_DWORD,(const BYTE *)&dwValueData,4) )
{
// _tprintf(TEXT("RegSetValueEx成功!\n"));
return true;
}
else
{
// _tprintf(TEXT("RegSetValueEx失败!\n"));
return false;
}
}
bool set(TCHAR *szValueName,TCHAR *szValueData)
{
DWORD cbLen=lstrlen(szValueData)*sizeof(TCHAR);
if( m_hKey!=NULL && ERROR_SUCCESS==RegSetValueEx(m_hKey,szValueName,0,REG_SZ,(const BYTE *)szValueData,cbLen) )
{
// _tprintf(TEXT("RegSetValueEx成功!\n"));
return true;
}
else
{
// _tprintf(TEXT("RegSetValueEx失败!\n"));
return false;
}
}
PVOID get(TCHAR *szValueName)
{
DWORD ValueBufferSize=0;
if( NULL!=m_pbValueData)
{
delete []m_pbValueData;
m_pbValueData=NULL;
}
方式一vista or later or xp64
//if( m_hKey!=NULL && ERROR_SUCCESS == RegGetValue( m_hRootKey, m_szSubKey,szValueName,RRF_RT_ANY,NULL/*&RegType*/, NULL, &ValueBufferSize) ) //取得缓冲大小
//{
//m_pbValueData=new char[ValueBufferSize];
//if(ERROR_SUCCESS == RegGetValue( m_hRootKey, m_szSubKey , szValueName, RRF_RT_ANY, NULL/*&RegType*/, (PVOID)m_pbValueData, &ValueBufferSize) )
//{
//return m_pbValueData;
//}
//}
方式二 xp or later//
if( m_hKey!=NULL && ERROR_SUCCESS == RegQueryValueEx(m_hKey,szValueName,NULL/*LPDWORD lpReserved*/, NULL/*&RegType*/, NULL,&ValueBufferSize) ) //取得缓冲大小
{
size_t len = ValueBufferSize + sizeof(TCHAR);
m_pbValueData=new char[len];//若为字符串如REG_SZ末尾必须要自行加入NULL
ZeroMemory(m_pbValueData, len);
if(ERROR_SUCCESS == RegQueryValueEx(m_hKey,szValueName,NULL/*LPDWORD lpReserved*/, NULL/*&RegType*/, (LPBYTE)m_pbValueData,&ValueBufferSize) )
{
m_pbValueData[ValueBufferSize]=0;
return m_pbValueData;
}
}
/
return NULL;
}
bool deletekey()
{
if(m_hKey!=NULL && ERROR_SUCCESS==RegDeleteKey(m_hRootKey,m_szSubKey) )
{
// printf("删除子键成功!\n");
return true;
}
else
{
// printf("删除子键失败!\n");
return false;
}
}
};