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

  1. #include "poweroff.h"
  2.  
  3. void BrowseSoundFile(HWND hWnd)
  4. {
  5.   OPENFILENAME openFile;
  6.   char filename[MAX_PATH]="\0";
  7.   char filter[100]="Sound Files\0*.WAV\0All Files\0*.*\0\0\0";
  8.  
  9.   Log("BrowseSoundFile start");
  10.   openFile.lStructSize=sizeof(OPENFILENAME);
  11.   openFile.hwndOwner=hWnd;
  12.   openFile.hInstance=NULL;
  13.   openFile.lpstrFilter=filter;
  14.   openFile.lpstrCustomFilter=NULL;
  15.   openFile.nMaxCustFilter=255;
  16.   openFile.nFilterIndex=0;
  17.   openFile.lpstrFile=filename;
  18.   openFile.nMaxFile=MAX_PATH;
  19.   openFile.lpstrFileTitle=NULL;
  20.   openFile.nMaxFileTitle=0;
  21.   openFile.lpstrInitialDir=NULL;
  22.   openFile.lpstrTitle=NULL;
  23.   openFile.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
  24.   openFile.nFileOffset=0;
  25.   openFile.nFileExtension=0;
  26.   openFile.lpstrDefExt=NULL;
  27.   openFile.lCustData=0;
  28.   openFile.lpfnHook=NULL;
  29.   openFile.lpTemplateName=NULL;
  30.   GetOpenFileName(&openFile);
  31.   if (filename[0])
  32.   {
  33.     SetDlgItemText(hWnd,IDC_SOUND_FILE,filename);
  34.   }
  35.   Log("BrowseSoundFile end, filename=%s",filename);
  36. }
  37.  
  38.  
  39. BOOL FAR PASCAL MessageProc(HWND hWnd, unsigned message,DWORD wParam, LONG lParam)
  40. {
  41.   static PowerSettings *ps;
  42.  
  43.   switch (message) 
  44.   {
  45.     case WM_INITDIALOG:
  46.       {
  47.         char tmpstr[100];
  48.  
  49.         ps=(PowerSettings*)lParam;
  50.         sprintf(tmpstr,"%u",ps->warning.seconds);
  51.         SetDlgItemText(hWnd,IDC_WARNING_TIME,tmpstr);
  52.         SetDlgItemText(hWnd,IDC_WARNING_MESSAGE,ps->warning.message);
  53.         CheckDlgButton(hWnd,IDC_PLAY_SOUND,ps->warning.play_sound?BST_CHECKED:BST_UNCHECKED);
  54.         if (ps->warning.play_sound)
  55.           SetDlgItemText(hWnd,IDC_SOUND_FILE,ps->warning.sound_file);
  56.         else
  57.         {
  58.           EnableWindow(GetDlgItem(hWnd,IDC_SOUND_FILE),FALSE);
  59.           EnableWindow(GetDlgItem(hWnd,IDC_BROWSE_SOUND),FALSE);
  60.         }
  61.       }      
  62.       return TRUE;
  63.     case WM_COMMAND:
  64.       switch (LOWORD(wParam))
  65.       {
  66.         case IDCANCEL:
  67.           EndDialog(hWnd,TRUE);
  68.           break;
  69.         case IDOK:
  70.           {
  71.             char tmpstr[100];
  72.  
  73.             GetDlgItemText(hWnd,IDC_WARNING_TIME,tmpstr,100);
  74.             ps->warning.seconds=atoi(tmpstr);
  75.             GetDlgItemText(hWnd,IDC_WARNING_MESSAGE,ps->warning.message,200);
  76.             ps->warning.play_sound=IsDlgButtonChecked(hWnd,IDC_PLAY_SOUND);
  77.             if (ps->warning.play_sound)
  78.               GetDlgItemText(hWnd,IDC_SOUND_FILE,ps->warning.sound_file,MAX_PATH);
  79.             EndDialog(hWnd,TRUE);
  80.           }
  81.           break;
  82.         case IDC_PLAY_SOUND:
  83.           EnableWindow(GetDlgItem(hWnd,IDC_SOUND_FILE),IsDlgButtonChecked(hWnd,IDC_PLAY_SOUND));
  84.           EnableWindow(GetDlgItem(hWnd,IDC_BROWSE_SOUND),IsDlgButtonChecked(hWnd,IDC_PLAY_SOUND));
  85.           break;
  86.         case IDC_BROWSE_SOUND:
  87.           BrowseSoundFile(hWnd);
  88.           break;
  89.       }
  90.       break;
  91.       default:
  92.          break;
  93.   }
  94.   return FALSE;
  95. }
  96.  
  97. void ShowMessageDialog(HWND hWnd,PowerSettings *ps)
  98. {
  99.   FARPROC dlgproc;
  100.  
  101.   Log("ShowMessageDialog start");
  102.   dlgproc=MakeProcInstance((FARPROC)MessageProc,hInst);
  103.     if (DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_WARNING_MESSAGE),hWnd,(DLGPROC)dlgproc,(LPARAM)ps)==-1)
  104.     DisplayLastError(ps,hWnd);
  105.     FreeProcInstance(dlgproc);
  106.   Log("ShowMessageDialog end");
  107. }