home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / rleapp / rledlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-12  |  12.0 KB  |  304 lines

  1. /*----------------------------------------------------------------------------*\
  2. |   rledlg.c - Dialog boxes for the RLE app                                    |
  3. \*----------------------------------------------------------------------------*/
  4. #include <windows.h>
  5. #include <mmsystem.h>
  6.  
  7. #include "rleapp.h"
  8. #include "dib.h"
  9. #include "rle.h"            // for RLE globals
  10.  
  11. extern double atof(char *pch);
  12.  
  13. /*----------------------------------------------------------------------------*\
  14. |   fDialog(id,hwnd,fpfn)                                                      |
  15. |                                                                              |
  16. |   Description:                                                               |
  17. |       This function displays a dialog box and returns the exit code.         |
  18. |       the function passed will have a proc instance made for it.             |
  19. |                                                                              |
  20. |   Arguments:                                                                 |
  21. |       id              resource id of dialog to display                       |
  22. |       hwnd            parent window of dialog                                |
  23. |       fpfn            dialog message function                                |
  24. |                                                                              |
  25. |   Returns:                                                                   |
  26. |       exit code of dialog (what was passed to EndDialog)                     |
  27. |                                                                              |
  28. \*----------------------------------------------------------------------------*/
  29. BOOL fDialog(int id,HWND hwnd,FARPROC fpfn)
  30. {
  31.     BOOL        f;
  32.     HANDLE      hInst;
  33.  
  34.     hInst = GetWindowWord(hwnd,GWW_HINSTANCE);
  35.     fpfn  = MakeProcInstance(fpfn,hInst);
  36.     f = DialogBox(hInst,MAKEINTRESOURCE(id),hwnd,fpfn);
  37.     FreeProcInstance (fpfn);
  38.     return f;
  39. }
  40.  
  41. /*----------------------------------------------------------------------------*\
  42. |   fDialogParam(id,hwnd,fpfn,lParam)                                          |
  43. |                                                                              |
  44. |   Description:                                                               |
  45. |       This function displays a dialog box and returns the exit code.         |
  46. |       the function passed will have a proc instance made for it.             |
  47. |       Just like fDialog, but calls DialogBoxParam.                           |
  48. |   Arguments:                                                                 |
  49. |       id              resource id of dialog to display                       |
  50. |       hwnd            parent window of dialog                                |
  51. |       fpfn            dialog message function                                |
  52. |       dwParam         Parameter for DialogBoxParam                            |
  53. |   Returns:                                                                   |
  54. |       exit code of dialog (what was passed to EndDialog)                     |
  55. |                                                                              |
  56. \*----------------------------------------------------------------------------*/
  57. BOOL fDialogParam(int id,HWND hwnd,FARPROC fpfn,DWORD dwParam)
  58. {
  59.     BOOL        f;
  60.     HANDLE      hInst;
  61.  
  62.     hInst = GetWindowWord(hwnd,GWW_HINSTANCE);
  63.     fpfn  = MakeProcInstance(fpfn,hInst);
  64.     f = DialogBoxParam(hInst,MAKEINTRESOURCE(id),hwnd,fpfn,dwParam);
  65.     FreeProcInstance (fpfn);
  66.     return f;
  67. }
  68.  
  69. /* FrameDlgProc(hwnd, wMsg, wParam, lParam)
  70.  *
  71.  * This function handles messages when changing the Frames/Sec of the movie
  72.  */
  73. BOOL EXPORT                // TRUE iff message has been processed
  74. FrameDlgProc(hwnd, wMsg, wParam, lParam)
  75. HWND            hwnd;           // window handle of dialog box
  76. short           wMsg;           // message number
  77. WORD            wParam;         // message-dependent parameter
  78. LONG            lParam;         // message-dependent parameter
  79. {
  80.     switch (wMsg) 
  81.     {
  82.     char ach[80];
  83.     
  84.     case WM_INITDIALOG:
  85.             wsprintf(ach, "%d.%03d",
  86.                 (WORD)(FramesSec/FramesSecScale),
  87.                 (WORD)(FramesSec%FramesSecScale) );
  88.         SetDlgItemText(hwnd, ID_FRAMESSEC, (LPSTR)ach);
  89.         return TRUE;
  90.         
  91.     case WM_COMMAND:
  92.         switch (wParam) 
  93.         {
  94.  
  95.         case IDOK:
  96.             GetDlgItemText(hwnd,ID_FRAMESSEC, (LPSTR)ach, 80);
  97.                     FramesSec = (long)(atof(ach) * FramesSecScale);
  98.                     if (FramesSec <= 0 || FramesSec > 100 * FramesSecScale) 
  99.             {
  100.             ErrMsg("Bad parameter value.  Frame Rate not changed");
  101.             break;
  102.             }
  103.             EndDialog(hwnd, TRUE);
  104.             break;
  105.             
  106.         case IDCANCEL:          // "Done"
  107.             EndDialog(hwnd, FALSE);
  108.         break;
  109.         }
  110.         break;
  111.     }   
  112.     return FALSE;
  113. }
  114.  
  115. /*---------------------------------------------------------------------*\
  116. |   fnRangeDlg( hDlg, uiMessage, wParam, lParam )                       |
  117. |                                                                       |
  118. |   Arguments:                                                          |
  119. |       hDlg            window handle of about dialog window            |
  120. |       uiMessage       message number                                  |
  121. |       wParam          message-dependent                               |
  122. |       lParam          message-dependent                               |
  123. |                                                                       |
  124. |   Returns:                                                            |
  125. |       TRUE if message has been processed, else FALSE                  |
  126. |                                                                       |
  127. \*---------------------------------------------------------------------*/
  128.  
  129. BOOL EXPORT fnRangeDlg(HWND hdlg, short msg, WORD wParam, LONG lParam)
  130. {
  131.     int     id;
  132.  
  133.     static  RANGEDIALOGPARAM rdp;
  134.     static  iPos;
  135.  
  136.     switch (msg)
  137.     {
  138.     case WM_COMMAND:
  139.         switch (wParam)
  140.         {
  141.         case IDOK:
  142.             EndDialog(hdlg,iPos);
  143.             break;
  144.  
  145.         case IDCANCEL:
  146.             EndDialog(hdlg,(int)rdp.current);
  147.             break;
  148.         }
  149.         break;
  150.  
  151.     case WM_HSCROLL:
  152.         id = GetWindowWord(HIWORD(lParam),GWW_ID);
  153.  
  154.         switch (wParam)
  155.         {
  156.         case SB_LINEDOWN:      iPos += 1; break;
  157.         case SB_LINEUP:        iPos -= 1; break;
  158.         case SB_PAGEDOWN:      iPos += 10; break;
  159.         case SB_PAGEUP:        iPos -= 10; break;
  160.         case SB_THUMBTRACK:
  161.         case SB_THUMBPOSITION: iPos = LOWORD(lParam); break;
  162.         default:
  163.             return TRUE;
  164.         }
  165.  
  166.         iPos = max(rdp.min,iPos);
  167.         iPos = min(rdp.max,iPos);
  168.         SetScrollPos(HIWORD(lParam),SB_CTL,iPos,TRUE);
  169.         SetDlgItemInt(hdlg,ID_TEXT,iPos,FALSE);
  170.         break;
  171.  
  172.     case WM_INITDIALOG:
  173.         rdp = *(LPRANGEDIALOGPARAM) lParam;
  174.         iPos = rdp.current;
  175.         iPos = max(rdp.min,iPos);
  176.         iPos = min(rdp.max,iPos);
  177.         SetWindowText(hdlg,rdp.lpCaption);
  178.         SetScrollRange(GetDlgItem(hdlg,ID_SCROLL),SB_CTL,
  179.                         (int)rdp.min,(int)rdp.max,TRUE);
  180.         SetScrollPos  (GetDlgItem(hdlg,ID_SCROLL),SB_CTL,iPos,TRUE);
  181.         SetDlgItemInt (hdlg,ID_TEXT,iPos,TRUE);
  182.         return TRUE;
  183.     }
  184.     return FALSE;
  185. }
  186.  
  187. /*---------------------------------------------------------------------*\
  188. |   fnResizeDlg( hDlg, uiMessage, wParam, lParam )                       |
  189. |                                                                       |
  190. |   Arguments:                                                          |
  191. |       hDlg            window handle of about dialog window            |
  192. |       uiMessage       message number                                  |
  193. |       wParam          message-dependent                               |
  194. |       lParam          message-dependent                               |
  195. |                                                                       |
  196. |   Returns:                                                            |
  197. |       TRUE if message has been processed, else FALSE                  |
  198. |                                                                       |
  199. \*---------------------------------------------------------------------*/
  200.  
  201. BOOL EXPORT fnResizeDlg(HWND hdlg, short msg, WORD wParam, LONG lParam)
  202. {
  203.     char ach[80];
  204.     int  i;
  205.     BITMAPINFOHEADER bi;
  206.  
  207.     switch (msg)
  208.     {
  209.     case WM_COMMAND:
  210.         switch (wParam)
  211.         {
  212.         case IDOK:
  213.                     i = GetScrollPos(GetDlgItem(hdlg,ID_SCROLL),SB_CTL);
  214.                     EndDialog(hdlg,i);
  215.             break;
  216.  
  217.         case IDCANCEL:
  218.                     EndDialog(hdlg,100);
  219.             break;
  220.         }
  221.         break;
  222.  
  223.     case WM_HSCROLL:
  224.             i = GetScrollPos(HIWORD(lParam),SB_CTL);
  225.  
  226.         switch (wParam)
  227.         {
  228.                 case SB_LINEDOWN:      i += 1; break;
  229.                 case SB_LINEUP:        i -= 1; break;
  230.                 case SB_PAGEDOWN:      i += 10; break;
  231.                 case SB_PAGEUP:        i -= 10; break;
  232.         case SB_THUMBTRACK:
  233.                 case SB_THUMBPOSITION: i = LOWORD(lParam); break;
  234.         default:
  235.             return TRUE;
  236.         }
  237.  
  238.             SetScrollPos(HIWORD(lParam),SB_CTL,i,TRUE);
  239.  
  240.             DibInfo(FrameDib(0), &bi);
  241.             wsprintf(ach, "%d%%: %dx%d", i,
  242.                 (int)(bi.biWidth * i / 100),
  243.                 (int)(bi.biHeight * i / 100));
  244.  
  245.             SetDlgItemText(hdlg,ID_TEXT,ach);
  246.         return TRUE;
  247.  
  248.     case WM_INITDIALOG:
  249.             SetWindowText(hdlg,"Resize");
  250.             SetScrollRange(GetDlgItem(hdlg,ID_SCROLL),SB_CTL,0,500,TRUE);
  251.             PostMessage(hdlg,WM_HSCROLL,SB_THUMBPOSITION, MAKELONG(100,GetDlgItem(hdlg,ID_SCROLL)));
  252.         return TRUE;
  253.     }
  254.     return FALSE;
  255. }
  256.  
  257. /*----------------------------------------------------------------------------*\
  258. |   ErrMsg - Opens a Message box with a error message in it.  The user can     |
  259. |            select the OK button to continue                                  |
  260. \*----------------------------------------------------------------------------*/
  261. int ErrMsg (LPSTR sz,...)
  262. {
  263.     char ach[128];
  264.  
  265.     wvsprintf (ach,sz,(LPSTR)(&sz+1));    /* Format the string */
  266.     MessageBeep(MB_ICONEXCLAMATION);
  267.     MessageBox(NULL,ach,NULL,MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
  268.     return FALSE;
  269. }
  270.  
  271. /*----------------------------------------------------------------------------*\
  272. |   AppAbout( hDlg, uiMessage, wParam, lParam )                                |
  273. |                                                                              |
  274. |   Description:                                                               |
  275. |       This function handles messages belonging to the "About" dialog box.    |
  276. |       The only message that it looks for is WM_COMMAND, indicating the use   |
  277. |       has pressed the "OK" button.  When this happens, it takes down         |
  278. |       the dialog box.                                                        |
  279. |                                                                              |
  280. |   Arguments:                                                                 |
  281. |       hDlg            window handle of about dialog window                   |
  282. |       uiMessage       message number                                         |
  283. |       wParam          message-dependent                                      |
  284. |       lParam          message-dependent                                      |
  285. |                                                                              |
  286. |   Returns:                                                                   |
  287. |       TRUE if message has been processed, else FALSE                         |
  288. |                                                                              |
  289. \*----------------------------------------------------------------------------*/
  290. BOOL EXPORT AppAbout(HWND hdlg, short msg, WORD wParam, LONG lParam)
  291. {
  292.     switch (msg)
  293.     {
  294.     case WM_COMMAND:
  295.         if (wParam == IDOK)
  296.         EndDialog(hdlg,TRUE);
  297.         break;
  298.  
  299.     case WM_INITDIALOG:
  300.         return TRUE;
  301.     }
  302.     return FALSE;
  303. }
  304.