ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

trayicon.c
Go to the documentation of this file.
00001 /*
00002  *  ReactOS Task Manager
00003  *
00004  *  trayicon.c
00005  *
00006  *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
00007  *                2005         Klemens Friedl <frik85@reactos.at>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  */
00023 
00024 #include <precomp.h>
00025 
00026 HICON TrayIcon_GetProcessorUsageIcon(void)
00027 {
00028     HICON     hTrayIcon = NULL;
00029     HDC       hScreenDC = NULL;
00030     HDC       hDC = NULL;
00031     HBITMAP   hBitmap = NULL;
00032     HBITMAP   hOldBitmap = NULL;
00033     HBITMAP   hBitmapMask = NULL;
00034     ICONINFO  iconInfo;
00035     ULONG     ProcessorUsage;
00036     int       nLinesToDraw;
00037     HBRUSH    hBitmapBrush = NULL;
00038     RECT      rc;
00039 
00040     /*
00041      * Get a handle to the screen DC
00042      */
00043     hScreenDC = GetDC(NULL);
00044     if (!hScreenDC)
00045         goto done;
00046 
00047     /*
00048      * Create our own DC from it
00049      */
00050     hDC = CreateCompatibleDC(hScreenDC);
00051     if (!hDC)
00052         goto done;
00053 
00054     /*
00055      * Load the bitmaps
00056      */
00057     hBitmap = LoadBitmapW(hInst, MAKEINTRESOURCEW(IDB_TRAYICON));
00058     hBitmapMask = LoadBitmapW(hInst, MAKEINTRESOURCEW(IDB_TRAYMASK));
00059     if (!hBitmap || !hBitmapMask)
00060         goto done;
00061 
00062     hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0));
00063     if (!hBitmapBrush)
00064         goto done;
00065 
00066     /*
00067      * Select the bitmap into our device context
00068      * so we can draw on it.
00069      */
00070     hOldBitmap = (HBITMAP) SelectObject(hDC, hBitmap);
00071 
00072     /*
00073      * Get the cpu usage
00074      */
00075     ProcessorUsage = PerfDataGetProcessorUsage();
00076 
00077     /*
00078      * Calculate how many lines to draw
00079      * since we have 11 rows of space
00080      * to draw the cpu usage instead of
00081      * just having 10.
00082      */
00083     nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11;
00084     rc.left = 3;
00085     rc.top = 12 - nLinesToDraw;
00086     rc.right = 13;
00087     rc.bottom = 13;
00088 
00089     /*
00090      * Now draw the cpu usage
00091      */
00092     if (nLinesToDraw)
00093         FillRect(hDC, &rc, hBitmapBrush);
00094 
00095     /*
00096      * Now that we are done drawing put the
00097      * old bitmap back.
00098      */
00099     hBitmap = SelectObject(hDC, hOldBitmap);
00100     hOldBitmap = NULL;
00101 
00102     iconInfo.fIcon = TRUE;
00103     iconInfo.hbmMask = hBitmapMask;
00104     iconInfo.hbmColor = hBitmap;
00105 
00106     hTrayIcon = CreateIconIndirect(&iconInfo);
00107 
00108 done:
00109     /*
00110      * Cleanup
00111      */
00112     if (hScreenDC)
00113         ReleaseDC(NULL, hScreenDC);
00114     if (hDC)
00115         DeleteDC(hDC);
00116     if (hBitmapBrush)
00117         DeleteObject(hBitmapBrush);
00118     if (hBitmap)
00119         DeleteObject(hBitmap);
00120     if (hBitmapMask)
00121         DeleteObject(hBitmapMask);
00122 
00123     /*
00124      * Return the newly created tray icon (if successful)
00125      */
00126     return hTrayIcon;
00127 }
00128 
00129 BOOL TrayIcon_ShellAddTrayIcon(void)
00130 {
00131     NOTIFYICONDATAW nid;
00132     HICON           hIcon = NULL;
00133     BOOL            bRetVal;
00134     WCHAR           szMsg[64];
00135 
00136     memset(&nid, 0, sizeof(NOTIFYICONDATAW));
00137 
00138     hIcon = TrayIcon_GetProcessorUsageIcon();
00139 
00140     nid.cbSize = sizeof(NOTIFYICONDATAW);
00141     nid.hWnd = hMainWnd;
00142     nid.uID = 0;
00143     nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
00144     nid.uCallbackMessage = WM_ONTRAYICON;
00145     nid.hIcon = hIcon;
00146 
00147 
00148     LoadStringW( GetModuleHandleW(NULL), IDS_MSG_TRAYICONCPUUSAGE, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
00149     wsprintfW(nid.szTip, szMsg, PerfDataGetProcessorUsage());
00150 
00151     bRetVal = Shell_NotifyIconW(NIM_ADD, &nid);
00152 
00153     if (hIcon)
00154         DestroyIcon(hIcon);
00155 
00156     return bRetVal;
00157 }
00158 
00159 BOOL TrayIcon_ShellRemoveTrayIcon(void)
00160 {
00161     NOTIFYICONDATAW nid;
00162     BOOL            bRetVal;
00163 
00164     memset(&nid, 0, sizeof(NOTIFYICONDATAW));
00165 
00166     nid.cbSize = sizeof(NOTIFYICONDATAW);
00167     nid.hWnd = hMainWnd;
00168     nid.uID = 0;
00169     nid.uFlags = 0;
00170     nid.uCallbackMessage = WM_ONTRAYICON;
00171 
00172     bRetVal = Shell_NotifyIconW(NIM_DELETE, &nid);
00173 
00174     return bRetVal;
00175 }
00176 
00177 BOOL TrayIcon_ShellUpdateTrayIcon(void)
00178 {
00179     NOTIFYICONDATAW nid;
00180     HICON           hIcon = NULL;
00181     BOOL            bRetVal;
00182     WCHAR           szTemp[64];
00183 
00184     memset(&nid, 0, sizeof(NOTIFYICONDATAW));
00185 
00186     hIcon = TrayIcon_GetProcessorUsageIcon();
00187 
00188     nid.cbSize = sizeof(NOTIFYICONDATAW);
00189     nid.hWnd = hMainWnd;
00190     nid.uID = 0;
00191     nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
00192     nid.uCallbackMessage = WM_ONTRAYICON;
00193     nid.hIcon = hIcon;
00194     LoadStringW(hInst, IDS_MSG_TRAYICONCPUUSAGE, szTemp, sizeof(szTemp)/sizeof(szTemp[0]));
00195     wsprintfW(nid.szTip, szTemp, PerfDataGetProcessorUsage());
00196 
00197     bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid);
00198 
00199     if (hIcon)
00200         DestroyIcon(hIcon);
00201 
00202     return bRetVal;
00203 }

Generated on Sun May 27 2012 04:17:47 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.