void CMainDlg::SetTrayIcon(int iWorkMode) { if(iWorkMode == 255) iWorkMode = m_bWorkMode; if(iWorkMode == XF_PASS_ALL) m_TrayIcon.SetIcon(IDI_SMALL_PASS); else if(iWorkMode == XF_QUERY_ALL) m_TrayIcon.SetIcon(IDI_SMALL_QUERY); else if(iWorkMode == XF_DENY_ALL) m_TrayIcon.SetIcon(IDI_SMALL_DENY); else m_TrayIcon.SetIcon(IDI_SMALL_PASS); }
DWORD WINAPI SplashIcon(LPVOID pVoid) { m_IsSplash = TRUE; for(int i = 0; i < 3; i++) { m_TrayIcon.SetIcon(IDI_SMALL_ALERT); if(i == 2) continue; Sleep(180); m_TrayIcon.SetIcon(IDI_SMALL_NULL); Sleep(400); } m_IsSplash = FALSE; return 0; }
DWORD WINAPI CMainDlg::SplashIcon(LPVOID pVoid) { CMainDlg* pMainDlg = (CMainDlg*)pVoid; pMainDlg->SetSplash(TRUE); for(int i = 0; i < 3; i++) { m_TrayIcon.SetIcon(IDI_SMALL_ALERT); if(i == 2) continue; Sleep(180); m_TrayIcon.SetIcon(IDI_SMALL_NULL); Sleep(400); } pMainDlg->SetSplash(FALSE); return 0; }
DWORD WINAPI SplashMessage(LPVOID pVoid) { for(int i = 0; i < MAX_NET_COMMAND; i++) { if(theApp.m_sMessage[i][0] != '\0') { m_MessageIndex = i; m_IsSplash = TRUE; while(m_MessageIndex) { m_TrayIcon.SetIcon(IDI_SMALL_MESSAGE); Sleep(180); m_TrayIcon.SetIcon(IDI_SMALL_NULL); Sleep(400); } theApp.SetTrayIcon(); m_IsSplash = FALSE; } } ODS("Exit Thread SplashMessage..."); return 0; }
DWORD WINAPI CMainDlg::SplashMessage(LPVOID pVoid) { CMainDlg* pMainDlg = (CMainDlg*)pVoid; for(int i = 0; i < MAX_NET_COMMAND; i++) { if(pMainDlg->GetOnLine()->GetInternet()->m_sMessage[i][0] != 0) { pMainDlg->SetMessageIndex(i); pMainDlg->SetSplash(TRUE); while(pMainDlg->GetMessageIndex()) { m_TrayIcon.SetIcon(IDI_SMALL_MESSAGE); Sleep(180); m_TrayIcon.SetIcon(IDI_SMALL_NULL); Sleep(400); } pMainDlg->SetSplash(FALSE); } } ODS("Exit Thread SplashMessage..."); return 0; }
void NetThread::Run() { g_receive_buffer = new (std::nothrow)ReceiveBuffer(); g_send_buffer = new (std::nothrow)SendBuffer(); WSAEVENT event_array[1]; g_connect_event = WSACreateEvent(); if(WSA_INVALID_EVENT == g_connect_event) { Log::Error("Create WSAEVENT failed %d", GetLastError()); } CONNECTTOSERVER: g_TrayIcon.SetIcon(IDI_ICONRED); g_TrayIcon.SetTooltipText((LPCTSTR)"Toast agent disconnected!"); g_connect_sock = ConnectToServer(serverhost.c_str(), serverport.c_str()); if(!IsRequestStop()&&g_connect_sock != -1) { SetIsConnected(1); WSAEventSelect(g_connect_sock, g_connect_event, FD_READ|FD_WRITE|FD_CLOSE); event_array[0] = g_connect_event; AgentSystemInfo info; GetAgentInfo(&info); SendAgentInfo(info); } else { Log::Info("Request exist or error, socket fd is -1"); return; } g_TrayIcon.SetIcon(IDI_ICONGREEN); g_TrayIcon.SetTooltipText((LPCTSTR)"Toast agent connected!"); while(!IsRequestStop()) { DWORD Index; Index = WSAWaitForMultipleEvents(1, event_array, FALSE, 1000, FALSE); if(Index == WSA_WAIT_FAILED) { Log::Error("WSAWaitForMultipleEvents error: %d", WSAGetLastError()); continue; // error occure } if(Index == WSA_WAIT_TIMEOUT) { int res = SendProcessing(g_connect_sock, g_send_buffer); if(res == 1) { ClearWrite(); } else if(res == -1) // some error occur, may be server is closed { ClearWrite(); Log::Debug("Send data error"); CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } // ok we send data } else { Index = Index - WSA_WAIT_EVENT_0; WSANETWORKEVENTS network_event; if(0==WSAEnumNetworkEvents(g_connect_sock, g_connect_event, &network_event)) { if(network_event.lNetworkEvents&FD_READ) { if(network_event.iErrorCode[FD_READ_BIT] != 0) { // read error // close connection and Log::Error("WSAEnumNetworkEvents read error: %d", WSAGetLastError()); CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } else { // ok we receive data int res = ReceiveProcessing(g_connect_sock, g_receive_buffer); if(0 == res || -1 == res) { Log::Debug("Server close or error %d ", res); CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } } } if(network_event.lNetworkEvents&FD_WRITE) { if(network_event.iErrorCode[FD_WRITE_BIT] != 0) { // network error Log::Error("WSAEnumNetworkEvents Write error: %d", WSAGetLastError()); CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } int res = SendProcessing(g_connect_sock, g_send_buffer); if(res == 1) { ClearWrite(); } else if(res == -1) // some error occur, may be server is closed { ClearWrite(); Log::Debug("Send data error"); CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } // ok we send data } if(network_event.lNetworkEvents&FD_CLOSE) { Log::Error("WSAEnumNetworkEvents connection closed error: %d", WSAGetLastError()); CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } } else { // error occureWSAGetLastError CloseConnectionToServer(g_connect_sock); goto CONNECTTOSERVER; } } } CloseConnectionToServer(g_connect_sock); }