home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Utility / attsetup.exe / plugins / api / vc++ / example / cpuload / cpuload.cpp next >
C/C++ Source or Header  |  2005-05-11  |  4KB  |  163 lines

  1. // cpuload.cpp : Defines the entry point for the DLL application.
  2. //
  3. #include "Winuser.h"
  4. #include "stdafx.h"
  5. #include "shellapi.h"
  6. #include "resource.h"
  7. #include "cpuusage.h"
  8. #include <math.h>
  9. int timerID=4400;
  10. int TRAY_CALLBACK=4666; 
  11.  
  12. HINSTANCE hinstDLLl;
  13. lppatt_proc Main_Proc;
  14. HWND MainWin;
  15. HWND MetterWindow;
  16. int is_started=0;
  17. HICON icons[14];
  18. NOTIFYICONDATA tnd;    
  19. CCpuUsage usageA;
  20.  
  21. BOOL APIENTRY DllMain( HANDLE hModule, 
  22.                        DWORD  ul_reason_for_call, 
  23.                        LPVOID lpReserved
  24.                      )
  25. {
  26.     hinstDLLl=(HINSTANCE)hModule;
  27.     return TRUE;
  28. }
  29.  
  30. void APIENTRY get_plug_info(PPlugInfo Data) {
  31.     strcpy(Data->Menu_Text,"CPU Load meter");
  32.     Data->PluginType=PL_RunTime;
  33.     Data->Sign=ATT_Sign;
  34. }
  35.  
  36.  
  37. /*
  38. BOOL CALLBACK MyDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  39.     HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST1); 
  40.     //LV_ITEM lvI;
  41.                                       
  42.     bool result=false;
  43.     switch (uMsg) {
  44.         case WM_INITDIALOG:     
  45.             break;
  46.         case WM_CLOSE: 
  47.                 EndDialog(hwndDlg,0);
  48.                 result=true;
  49.                 break;
  50.         case WM_COMMAND:
  51.             switch (LOWORD(wParam))  { 
  52.             case IDOK:  
  53.                     EndDialog(hwndDlg,0); 
  54.                     result=true; 
  55.  
  56.             } 
  57.         case WM_KEYDOWN:
  58.             if (wParam==2) {
  59.                 EndDialog(hwndDlg,0);
  60.                 result=true;                
  61.             }
  62.  
  63.         break;
  64.     }
  65.     return result;
  66.     
  67. }
  68. */
  69. LRESULT CALLBACK WindowProc( HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam )  {
  70.  
  71.     switch (uMsg) {          
  72.     
  73.     case WM_CREATE:
  74.  
  75.                 return 0;
  76.                 break;
  77.     
  78.     default:
  79.  
  80.         return (DefWindowProc(hwnd, uMsg, wParam, lParam));
  81.     }
  82.     
  83. }
  84. VOID CALLBACK TimerProc(
  85.   HWND hwnd,         // handle to window
  86.   UINT uMsg,         // WM_TIMER message
  87.   UINT_PTR idEvent,  // timer identifier
  88.   DWORD dwTime       // current system time
  89.   ) {
  90.         int SystemWideCpuUsage = usageA.GetCpuUsage();
  91.         int curid=0;
  92.         NOTIFYICONDATA tnd2;
  93.         tnd2.uID = 4666;
  94.         tnd2.cbSize = sizeof (NOTIFYICONDATA);
  95.         tnd2.hWnd = MetterWindow;
  96.     
  97.         curid=(int)ceil(SystemWideCpuUsage / 6.66);
  98.         if (curid>14) { curid=14; }
  99.         tnd2.hIcon = icons[curid];
  100.         tnd2.uFlags = NIF_ICON | NIF_TIP;
  101.         sprintf(tnd2.szTip,"Cpu Usage : %d%%",SystemWideCpuUsage);
  102.         Shell_NotifyIcon (NIM_MODIFY , &tnd2);
  103.  
  104. }
  105.  
  106.  
  107.  
  108. void APIENTRY exec_plugin (HWND Win_Handle, lppatt_proc ATT_Proc) {
  109.     if (is_started==1) return;
  110.     Main_Proc=ATT_Proc;
  111.     MainWin=Win_Handle;
  112.     is_started=1;
  113.     //
  114.     for (int i=0; i<15;i++) {
  115.     icons[i]= LoadIcon(hinstDLLl,MAKEINTRESOURCE(102+i));
  116.     }
  117.     WNDCLASSEX wcexMain;
  118.     wcexMain.cbSize = sizeof(WNDCLASSEX); 
  119.     wcexMain.style = CS_HREDRAW | CS_VREDRAW;
  120.     wcexMain.lpfnWndProc = WindowProc;
  121.     wcexMain.cbClsExtra = 0;
  122.     wcexMain.cbWndExtra = 0;
  123.     wcexMain.hInstance = hinstDLLl;
  124.     wcexMain.hIcon = 0;
  125.     wcexMain.hCursor = 0;
  126.     wcexMain.hbrBackground = 0;
  127.     wcexMain.lpszMenuName = NULL;
  128.     wcexMain.lpszClassName = "MainCPULoad";
  129.     wcexMain.hIconSm = 0;
  130.     if (!RegisterClassEx(&wcexMain)) {
  131.         return ;
  132.     }
  133.     MetterWindow = CreateWindow("MainCPULoad", NULL, 0, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hinstDLLl, NULL);
  134.     //Set Tray ICON
  135.     tnd.uID = 4666;
  136.     tnd.cbSize = sizeof (NOTIFYICONDATA);
  137.     tnd.hWnd = MetterWindow;
  138.     tnd.uCallbackMessage = TRAY_CALLBACK;
  139.     tnd.hIcon = icons[5];
  140.     
  141.     tnd.uFlags = NIF_MESSAGE | NIF_ICON;
  142.     Shell_NotifyIcon (NIM_ADD, &tnd);
  143.  
  144.     SetTimer(MetterWindow,timerID,500,TimerProc);
  145.  
  146. }
  147.  
  148. void APIENTRY done_plugin() {
  149.     if (!is_started==1) return;
  150.     KillTimer(MetterWindow,timerID);
  151.  
  152.     Shell_NotifyIcon (NIM_DELETE, &tnd);
  153.     DestroyWindow(MetterWindow);
  154.     UnregisterClass("MainCPULoad",hinstDLLl);
  155.     is_started=0;
  156. }
  157.  
  158. void APIENTRY config_plugin(HWND Win_Handle) {
  159.   
  160. }
  161. void APIENTRY suspend_restore() {
  162.     
  163. }