home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 November / PCWorld_2004-11_cd.bin / software / temacd / poweroff / pwroff30.exe / src / process.c < prev    next >
C/C++ Source or Header  |  2002-02-16  |  3KB  |  130 lines

  1. #include "poweroff.h"
  2.  
  3. BOOL CALLBACK CheckProcessAlive(DWORD dw,WORD w16,LPCSTR lpstr,LPARAM lParam)
  4. {
  5.   PowerSettings *ps;
  6.  
  7.   ps=(PowerSettings*)lParam;
  8.   if (!_stricmp(lpstr,ps->process.process))
  9.     return FALSE;
  10.   return TRUE;
  11. }
  12.  
  13. void CheckProcessTimer(HWND hWnd,PowerSettings *ps)
  14. {
  15.   Log("CheckProcessTimer start");
  16.   if (EnumProcs(CheckProcessAlive,(LPARAM)ps))
  17.   {
  18.     KillTimer(hWnd,ps->active_timer);
  19.     ps->active_timer=0;
  20.     PowerOff(hWnd,ps);
  21.   }
  22.   Log("CheckProcessTimer start");
  23. }
  24.  
  25. BOOL CALLBACK FillProcBrowser(DWORD dw,WORD w16,LPCSTR lpstr,LPARAM lParam)
  26. {
  27.   if (lpstr[0])
  28.   {
  29.     SendDlgItemMessage((HWND)lParam,IDC_PROCESS_LIST,LB_ADDSTRING,0,(LPARAM)lpstr);
  30.   }
  31.   return TRUE;
  32. }
  33.  
  34. BOOL FAR PASCAL ProcessBrowserProc(HWND hWnd, unsigned message,DWORD wParam, LONG lParam)
  35. {
  36.   static PowerSettings *ps;
  37.  
  38.   switch (message) 
  39.   {
  40.     case WM_INITDIALOG:
  41.       {
  42.         ps=(PowerSettings*)lParam;
  43.         EnumProcs(FillProcBrowser,(LPARAM)hWnd);
  44.       }      
  45.       return TRUE;
  46.     case WM_COMMAND:
  47.       switch (LOWORD(wParam))
  48.       {
  49.         case IDCANCEL:
  50.           EndDialog(hWnd,TRUE);
  51.           break;
  52.         case IDOK:
  53.           {
  54.             char str[MAX_PATH];
  55.             int cur_sel;
  56.  
  57.             cur_sel=SendDlgItemMessage(hWnd,IDC_PROCESS_LIST,LB_GETCURSEL,0,0);
  58.             if (cur_sel==LB_ERR)
  59.               Error(ps,hWnd,"No process selected");
  60.             else
  61.             {
  62.               SendDlgItemMessage(hWnd,IDC_PROCESS_LIST,LB_GETTEXT,(WPARAM)cur_sel,(LPARAM)str);
  63.               SetDlgItemText(GetParent(hWnd),IDC_PROCESS,str);
  64.               EndDialog(hWnd,TRUE);
  65.             }
  66.           }
  67.           break;
  68.         case IDC_PROCESS_LIST:
  69.           if ((HIWORD(wParam))==LBN_DBLCLK)
  70.             SendMessage(hWnd,WM_COMMAND,IDOK,0);
  71.           break;
  72.       }
  73.       break;
  74.       default:
  75.          break;
  76.   }
  77.   return FALSE;
  78. }
  79.  
  80.  
  81. BOOL FAR PASCAL ProcessProc(HWND hWnd, unsigned message,DWORD wParam, LONG lParam)
  82. {
  83.   static PowerSettings *ps;
  84.  
  85.   switch (message) 
  86.   {
  87.     case WM_INITDIALOG:
  88.       {
  89.         ps=(PowerSettings*)lParam;
  90.         SetDlgItemText(hWnd,IDC_PROCESS,ps->process.process);
  91.       }      
  92.       return TRUE;
  93.     case WM_COMMAND:
  94.       switch (LOWORD(wParam))
  95.       {
  96.         case IDCANCEL:
  97.           EndDialog(hWnd,TRUE);
  98.           break;
  99.         case IDOK:
  100.           GetDlgItemText(hWnd,IDC_PROCESS,ps->process.process,200);
  101.           EndDialog(hWnd,TRUE);
  102.           break;
  103.         case IDC_BUT_PROCESS:
  104.         {
  105.           FARPROC dlgproc;
  106.  
  107.           dlgproc=MakeProcInstance((FARPROC)ProcessBrowserProc,hInst);
  108.             if (DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_PROCESS_BROWSER),hWnd,(DLGPROC)dlgproc,(LPARAM)ps)==-1)
  109.             DisplayLastError(ps,hWnd);
  110.             FreeProcInstance(dlgproc);
  111.         }
  112.       }
  113.       break;
  114.       default:
  115.          break;
  116.   }
  117.   return FALSE;
  118. }
  119.  
  120. void ShowProcessDialog(HWND hWnd,PowerSettings *ps)
  121. {
  122.   FARPROC dlgproc;
  123.  
  124.   Log("ShowProcessDialog start");
  125.   dlgproc=MakeProcInstance((FARPROC)ProcessProc,hInst);
  126.     if (DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_PROCESS),hWnd,(DLGPROC)dlgproc,(LPARAM)ps)==-1)
  127.     DisplayLastError(ps,hWnd);
  128.     FreeProcInstance(dlgproc);
  129.   Log("ShowProcessDialog end");
  130. }