typedef struct _tagLASTINPUTINFO {
UINT cbSize;
DWORD dwTime;
} MYLASTINPUTINFO;
typedef BOOL (WINAPI*MyGetLastInputInfo)(MYLASTINPUTINFO* plii);
MyGetLastInputInfo pfnGetLastInputInfo = NULL;
BOOL CallMyGetLastInputInfo(MYLASTINPUTINFO* plii)
{
BOOL result = FALSE;
if (pfnGetLastInputInfo == NULL){
pfnGetLastInputInfo = (MyGetLastInputInfo)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetLastInputInfo");
}
if (pfnGetLastInputInfo){
result = pfnGetLastInputInfo(plii);
}
return result;
}
//===================
// 啟動Hook
//===================
bool *Dlg::StartHook()
{
if( m_AntViewMgr.m_AntLoginInfo.m_nAutoAway > 0 ) // 按伺服器端的設定來
{
m_dwAutoAwayTime = m_AntViewMgr.m_AntLoginInfo.m_nAutoAway*60*1000;
// 啟動Hook定時器,時間為10秒中
m_nTimerHook = SetTimer( TIMER_HOOK, TIME_HOOK, NULL );
}
else
{
CAntViewBaseFun::GetAutoAwayInfo( m_bAutoAway, m_nAutoAwayTime );
if( m_bAutoAway ) //
{
if( m_nAutoAwayTime < 1 )
m_nAutoAwayTime = 10;
m_dwAutoAwayTime = m_nAutoAwayTime*60*1000;
// 啟動Hook定時器,時間為10秒中
m_nTimerHook = SetTimer( TIMER_HOOK, TIME_HOOK, NULL );
}
}
return true;
}
// 停止hook
bool *Dlg::StopHook()
{
if( m_bAutoAway )
{
KillTimer( m_nTimerHook );
m_nTimerHook = 0;
m_bStartHook = false;
}
return true;
}
// 接受Hook的Mouse訊息
// void CBigAntBaseDlg::OnAsHookMouse( WPARAM wParam, LPARAM lParam )
// {
// if( m_bAutoAway && m_bLogined )
// {
// m_dwHookTime = timeGetTime();
// if( m_AntViewMgr.m_AntLoginInfo.m_nStatus == ANT_ONLINESTATUS_AUTOAWAY )
// {
// CString strTemp = _T("");
//
// strTemp.Format( _T("OnAsHookMouse Online %d"), wParam );
// // m_AntViewMgr.WriteToLogFile( strTemp );
// m_AntViewMgr.SetUserStatus( ANT_ONLINESTATUS_ONLINE, _T("") );
// ChangeUserStatusIcon( ANT_ONLINESTATUS_ONLINE );
// }
// }
// }
//
// //============================
// // 接受Hook的Keyboard訊息
// //============================
// void CBigAntBaseDlg::OnAsHookKey( WPARAM wParam, LPARAM lParam )
// {
// if( m_bAutoAway && m_bLogined )
// {
// m_dwHookTime = timeGetTime();
// if( m_AntViewMgr.m_AntLoginInfo.m_nStatus == ANT_ONLINESTATUS_AUTOAWAY )
// {
// // m_AntViewMgr.WriteToLogFile( _T("OnAsHookKey Online") );
// m_AntViewMgr.SetUserStatus( ANT_ONLINESTATUS_ONLINE, _T("") );
// ChangeUserStatusIcon( ANT_ONLINESTATUS_ONLINE );
// }
// }
// }
//==============================
// Hook定時器定時檢查的時間
//==============================
void *Dlg::OnHookTime()
{
DWORD dwCurrent = timeGetTime();
CString strTemp = _T("");
if( !m_bAutoAway || !m_bLogined ) // 使用自動離開和已經登入
return;
MYLASTINPUTINFO li = {0};
li.cbSize = sizeof(li);
if(CallMyGetLastInputInfo(&li))
{
DWORD idle = GetTickCount() - li.dwTime;
if (idle > m_dwAutoAwayTime)
{
if( m_AntViewMgr.m_AntLoginInfo.m_nStatus == ANT_ONLINESTATUS_ONLINE )
{
m_AntViewMgr.SetUserStatus( ANT_ONLINESTATUS_AUTOAWAY, _T("") );
ChangeUserStatusIcon( ANT_ONLINESTATUS_AUTOAWAY );
if (m_nTimerHook != 0){
KillTimer(m_nTimerHook);
}
m_nTimerHook = SetTimer(TIMER_HOOK, 2000, NULL);
}
}
else
{
if( m_AntViewMgr.m_AntLoginInfo.m_nStatus == ANT_ONLINESTATUS_AUTOAWAY )
{
m_AntViewMgr.SetUserStatus( ANT_ONLINESTATUS_ONLINE, _T("") );
ChangeUserStatusIcon( ANT_ONLINESTATUS_ONLINE );
if (m_nTimerHook != 0){
KillTimer(m_nTimerHook);
}
m_nTimerHook = SetTimer(TIMER_HOOK, TIME_HOOK, NULL);
}
}
}
}