void CRelaxReminderDlg::ProcessIconStatus() { CString strIconTips; if (FALSE == m_bTrayIconVisible) {// 通知栏图标不显示时,不用更新 return; } char *pchTime = GetFixedColonTime(); switch (m_tm.GetStatus()) { case STATUS_INIT: strIconTips = "ReRe"; m_uIconID = IDR_MAINFRAME; break; case STATUS_WORK: strIconTips.Format("%s(%d%%) %s", m_str.GetStr(TRAY_ICON_TIPS_WORK), m_tm.GetLS() * 100 / m_tm.GetWD(), pchTime); m_uIconID = IDI_ICON16 + m_tm.GetLS() * 15 / m_tm.GetWD(); break; case STATUS_SHORT_RELAX: strIconTips.Format("%s(%d%%) %s", m_str.GetStr(TRAY_ICON_TIPS_SHORT_RELAX), m_tm.GetLS() * 100 / m_tm.GetSRD(), pchTime); m_uIconID = IDI_ICON1 + m_tm.GetLS() * 15 / m_tm.GetSRD(); break; case STATUS_LONG_RELAX: strIconTips.Format("%s(%d%%) %s", m_str.GetStr(TRAY_ICON_TIPS_LONG_RELAX), m_tm.GetLS() * 100 / m_tm.GetLRD(), pchTime); m_uIconID = IDI_ICON1 + m_tm.GetLS() * 15 / m_tm.GetLRD(); break; case STATUS_PAUSE: case STATUS_AUTO_PAUSE: strIconTips.Format("%s(%d%%) %s", m_str.GetStr(TRAY_ICON_TIPS_PAUSE), m_tm.GetLS() * 100 / m_tm.GetWD(), pchTime); m_uIconID = IDI_ICON31 + m_tm.GetLS() * 15 / m_tm.GetWD(); break; case STATUS_RESET: case STATUS_AUTO_RESET: strIconTips = "ReRe"; // 复位时,闪烁托盘图标 m_uIconID = (m_uIconID == IDI_ICON_RESET_01) ? IDI_ICON_RESET_02 : IDI_ICON_RESET_01; break; default: break; } m_hIcon = AfxGetApp()->LoadIcon(m_uIconID); UpdateTrayIcon(strIconTips); }
void WinConsole::ApplyPrefs() { ShowWindow(GetConsoleWindow(), m_showConsole ? SW_SHOW : SW_HIDE); if (m_showTrayIcon) { UpdateTrayIcon(); } Shell_NotifyIcon(m_showTrayIcon ? NIM_ADD : NIM_DELETE, m_iconData); }
void CamuleDlg::CreateSystray() { wxCHECK_RET(m_wndTaskbarNotifier == NULL, wxT("Systray already created")); m_wndTaskbarNotifier = new CMuleTrayIcon(); // This will effectively show the Tray Icon. UpdateTrayIcon(0); }
// Calculate samples void Cwinproc::OnTimer(UINT /* nIDEvent */) { // Retrieve the total number of bytes received and sent by all network adapters, modulo 2^32. // Each network adapter counts from its own epoch, which is the last time the cable or wireless LAN was connected. DWORD r = 0; DWORD s = 0; bool ok = snmp.GetReceivedAndSentOctets(r, s); DWORD curRecv = 0; DWORD curSent = 0; if (ok) { if (m_PrevBytesOk) { curRecv = r - m_PrevBytesRecv; // With 32-bit unsigned wraparound curSent = s - m_PrevBytesSent; } m_PrevBytesRecv = r; m_PrevBytesSent = s; } m_TotalBytesRecv += curRecv; m_TotalBytesSent += curSent; m_PrevBytesOk = ok; // Don't depend upon timing of WM_TIMER messages. Get the true number of milliseconds elapsed DWORD dwTime = GetTickCount(); DWORD elapsed = dwTime - m_dwStartTime; m_dwStartTime = dwTime; // Calculate bits per second DWORD dwRecv_bps = 0; DWORD dwSent_bps = 0; if (elapsed > 0) { dwRecv_bps = (DWORD)(curRecv * 1000.0 / elapsed + 0.5); dwSent_bps = (DWORD)(curSent * 1000.0 / elapsed + 0.5); } // Shift over previous data for (int i = MAX_SAMPLES - 1; i >= 1; i--) { RecvStats[i] = RecvStats[i - 1]; SentStats[i] = SentStats[i - 1]; } // Calc the average bps and add new entry to array CalcAverages(m_TotalBytesRecv, dwTime, dwRecv_bps, RecvStats); CalcAverages(m_TotalBytesSent, dwTime, dwSent_bps, SentStats); // Get the icon for the system tray HICON hIcon = theApp.m_Icons.GetIcon(RecvStats, SentStats, g_IconStyle); UpdateTrayIcon(hIcon); DestroyIcon(hIcon); }
LRESULT WinConsole::TrayWndProc(HWND hwndWin, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == m_taskbarCreatedMessage) { ApplyPrefs(); return 0; } switch (uMsg) { case UM_TRAYICON: if (lParam == WM_LBUTTONUP && !m_doubleClick) { g_Options->SetPauseDownload(!g_Options->GetPauseDownload()); g_Options->SetPausePostProcess(g_Options->GetPauseDownload()); g_Options->SetPauseScan(g_Options->GetPauseDownload()); g_Options->SetResumeTime(0); UpdateTrayIcon(); } else if (lParam == WM_LBUTTONDBLCLK && m_doubleClick) { ShowWebUI(); } else if (lParam == WM_RBUTTONDOWN) { ShowMenu(); } return 0; case UM_QUIT: case WM_ENDSESSION: ExitProc(); return 0; case UM_SHOWWEBUI: ShowWebUI(); return 0; case UM_PREFSCHANGED: LoadPrefs(); ApplyPrefs(); return 0; default: return DefWindowProc(hwndWin, uMsg, wParam, lParam); } }
void CamuleDlg::ShowTransferRate() { float kBpsUp = theStats::GetUploadRate() / 1024.0; float kBpsDown = theStats::GetDownloadRate() / 1024.0; wxString buffer; if( thePrefs::ShowOverhead() ) { buffer = CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp % (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown % (theStats::GetDownOverheadRate() / 1024.0); } else { buffer = CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown; } buffer.Truncate(50); // Max size 50 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText ); label->SetLabel(buffer); label->GetParent()->Layout(); // Show upload/download speed in title if (thePrefs::GetShowRatesOnTitle()) { wxString UpDownSpeed = CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown; if (thePrefs::GetShowRatesOnTitle() == 1) { SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed); } else { SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle); } } wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon()); if (m_wndTaskbarNotifier) { // set trayicon-icon int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate()); UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown); wxString buffer2; if ( theApp->IsConnected() ) { buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer; } else { buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer; } m_wndTaskbarNotifier->SetTrayToolTip(buffer2); } wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap ); bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0))); }
void WinConsole::Run() { if (!m_appMode || m_addParam) { return; } CreateTrayIcon(); LoadPrefs(); ApplyPrefs(); BuildMenu(); if (m_showWebUI && !m_autoParam && mayStartBrowser) { ShowWebUI(); } mayStartBrowser = false; int counter = 0; while (!IsStopped()) { MSG msg; if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { usleep(20 * 1000); counter += 20; if (counter >= 200) { UpdateTrayIcon(); counter = 0; } } } Shell_NotifyIcon(NIM_DELETE, m_iconData); }
LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // the custom messages are not constant, therefore we can't handle them in the // switch-case below HandleCustomMessages(hwnd, uMsg, wParam, lParam); switch (uMsg) { case WM_SETTINGCHANGE: { aeroColors.AdjustColorsFromWallpaper(); UpdateTrayIcon(); } break; case WM_CREATE: { m_hwnd = hwnd; wpPath = aeroColors.AdjustColorsFromWallpaper(); threadRunning = true; _beginthreadex(NULL, 0, WatcherThread, this, 0, NULL); } break; case WM_COMMAND: return DoCommand(LOWORD(wParam)); break; case TRAY_WM_MESSAGE: { switch(lParam) { case WM_RBUTTONUP: case WM_CONTEXTMENU: { POINT pt; GetCursorPos(&pt); HMENU hMenu = LoadMenu(hResource, MAKEINTRESOURCE(IDC_AACLR)); HMENU hPopMenu = GetSubMenu(hMenu, 0); SetForegroundWindow(*this); TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, *this, NULL); DestroyMenu(hMenu); } break; case WM_LBUTTONDOWN: { if (randomcolors) { BOOL bDwmEnabled = FALSE; DwmIsCompositionEnabled(&bDwmEnabled); if (bDwmEnabled) aeroColors.SetRandomColor(); else MessageBox(NULL, L"Aero is disabled, cannot change the color!", L"AAClr", MB_ICONERROR); } } break; case WM_LBUTTONDBLCLK: { if (brightness) { POINT pt; GetCursorPos(&pt); CNotifySlider dlg(NULL); dlg.xPos = pt.x; dlg.yPos = pt.y; dlg.DoModal(hResource, IDD_NOTIFYSLIDER, NULL); } } break; case WM_MOUSEMOVE: UpdateTrayIcon(); break; } } break; case WM_DESTROY: Shell_NotifyIcon(NIM_DELETE,&niData); PostQuitMessage(0); break; case WM_TIMER: if (wParam == TIMER_DETECTCHANGES) { aeroColors.AdjustColorsFromWallpaper(); SetTimer(*this, TIMER_DETECTCHANGES, 1000, NULL); } break; case WM_DWMCOMPOSITIONCHANGED: UpdateTrayIcon(); break; case WM_QUERYENDSESSION: threadRunning = false; return TRUE; case WM_QUIT: threadRunning = false; break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; };