home *** CD-ROM | disk | FTP | other *** search
/ cyber.net 2 / cybernet2.ISO / qtw111 / pviewer / framewnd.c < prev    next >
C/C++ Source or Header  |  1994-01-11  |  38KB  |  1,016 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // FrameWnd.c - Picture Viewer - QuickTime for Windows
  5. //
  6. //              Version 1.0
  7. //
  8. //              (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Includes
  14. // --------
  15. #define NOMINMAX
  16. #include <Windows.H>  // Required by Windows
  17. #include <commdlg.h>  // Header file for common dlgs
  18. #include <dlgs.h>     // Header file for common dlgs ids
  19. #include <cderr.h>    // Header file for error ids
  20. #include <memory.h>   // Needed for memset() function
  21. #include <shellapi.h> // Drag and drop stuff
  22.  
  23. #include <qtole.h> // Interface to qtole dll
  24.  
  25. #include "common.h" // Interface to common.c
  26.  
  27. #include "viewer.h"  // Interface to other *.c files
  28. #include "viewer.hr" // Defines used in *.rc files
  29. #include "picture.h" // Interface to other *.c files
  30.  
  31. // Message-Persistent Data
  32. // -----------------------
  33. static struct // Hungarian notation: g
  34.   { HWND      hwndClient;      // MDI client window
  35.     WORD      wNumPictures;    // Number of picture wnds
  36.     BOOL      bUserAbortPrint; // User abort print flag
  37.     HWND      hwndCancelPrt;   // Handle of print cancel dlg
  38.     HBITMAP   hAboutBitmap;    // Temp static storage of bitmap
  39.                                // displayed in about dialogs
  40.   } g;
  41.  
  42.  
  43. // Exported callback functions
  44. // ----------------------------
  45. BOOL __export CALLBACK AboutDlgProc       (HWND, UINT, WPARAM, LPARAM);
  46. BOOL __export CALLBACK CloseEnumProc      (HWND, LPARAM);
  47. BOOL __export CALLBACK PaletteEnumProc    (HWND, LPARAM);
  48. BOOL __export CALLBACK PrintCancelDlgProc (HWND, UINT, WPARAM, LPARAM);
  49. int  __export CALLBACK PrintAbortProc     (HDC, int);
  50. UINT __export CALLBACK PrintDlgHookProc   (HWND, UINT, WPARAM, LPARAM);
  51.  
  52. // Internal Function Declarations
  53. // ------------------------------
  54. static LONG NEAR ViewerFrameCreate       (HWND);
  55. static LONG NEAR ViewerFileCommands      (HWND, WPARAM, WORD);
  56. static LONG NEAR ViewerWindowCommands    (HWND, WPARAM, WORD);
  57. static LONG NEAR ViewerHelpCommands      (HWND, WPARAM, WORD);
  58. static LONG NEAR LaunchPictureWnd        (LPSTR, LPSTR);
  59. static VOID NEAR ViewerEnableMenus       (HWND, BOOL);
  60. static VOID NEAR TellUserCommonDlgError  (DWORD);
  61. static LONG NEAR ProcessDroppedFiles     (HWND, WPARAM );
  62. static VOID NEAR DestroyHelpInstance     (HWND);
  63.  
  64. // -----------------------------------------------------------------------
  65.  
  66.  
  67. // Function: ViewerFrameWndProc - Viewer Frame Window Procedure
  68. // --------------------------------------------------------------------
  69. // Parameters: As required by Microsoft Windows
  70. //
  71. // Returns:    Via DefFrameProc
  72. // --------------------------------------------------------------------
  73. LONG __export CALLBACK ViewerFrameWndProc
  74.     (HWND hwndFrame, UINT message, WPARAM wParam, LPARAM lParam)
  75.  
  76. {
  77.     WNDENUMPROC       lpfnEnumPictures; // -> callback funcion for
  78.                                         // enumeration of pictures
  79.     HWND              hwndPicture;      // Temp handle of active picture wnd
  80.     LPQTOLE_OLEDATA   lpOleData;        // -> to OLE data
  81.  
  82.  
  83.     switch( message ) {
  84.         case WM_CREATE:
  85.             return ViewerFrameCreate( hwndFrame );
  86.  
  87.         case WM_PALETTECHANGED:
  88.             if( g.wNumPictures &&
  89.                 ( lpfnEnumPictures = (WNDENUMPROC) MakeProcInstance
  90.                 ( (FARPROC) PaletteEnumProc, ViewerQueryInstance()))) {
  91.                 StoreCurrentSystemPalette( NULL );
  92.  
  93.                 // Tell the picture wnds to repaint themselves
  94.                 EnumChildWindows( g.hwndClient, lpfnEnumPictures,
  95.                     (LPARAM) wParam);
  96.                 FreeProcInstance( (FARPROC) lpfnEnumPictures );
  97.             }
  98.  
  99.             return 0L;
  100.  
  101.         case WM_INITMENUPOPUP:
  102.             // Set check marks and enable menu items in popups
  103.             if( !(BOOL) HIWORD( lParam ) &&
  104.                 ( hwndPicture = (HWND) SendMessage
  105.                 ( g.hwndClient, WM_MDIGETACTIVE, 0, 0L )) &&
  106.                 IsWindow( hwndPicture ))
  107.                 SendMessage( hwndPicture,
  108.                 WM_VIEWER_INITPOPUPS, wParam, lParam );
  109.  
  110.             return 0L;
  111.  
  112.         case WM_COMMAND:
  113.             switch( wParam ) {
  114.                 case VIEWER_FILE_OPEN: // file menu popup
  115.                 case VIEWER_FILE_CLOSE:
  116.                 case VIEWER_FILE_PRTSETUP:
  117.                 case VIEWER_FILE_PRINT:
  118.                 case VIEWER_FILE_EXIT:
  119.                     return ViewerFileCommands
  120.                         ( hwndFrame, wParam, HIWORD (lParam));
  121.  
  122.                 case VIEWER_WINDOW_TILE: // window menu popup
  123.                 case VIEWER_WINDOW_CASCADE:
  124.                 case VIEWER_WINDOW_ARRANGE:
  125.                     return ViewerWindowCommands
  126.                         ( hwndFrame, wParam, HIWORD (lParam));
  127.  
  128.  
  129.                 case VIEWER_HELP_VIEWERHELP: // help menu popup
  130.                 case VIEWER_HELP_USINGHELP:
  131.                 case VIEWER_HELP_ABOUTVIEWER:
  132.                     return ViewerHelpCommands
  133.                         ( hwndFrame, wParam, HIWORD (lParam));
  134.  
  135.                 default:
  136.                     if( ( hwndPicture = (HWND) SendMessage
  137.                         ( g.hwndClient, WM_MDIGETACTIVE, 0, 0L )) &&
  138.                         IsWindow( hwndPicture ))
  139.                         SendMessage( hwndPicture,
  140.                         WM_COMMAND, wParam, lParam );
  141.  
  142.                     break; // break to DefFrameProc
  143.             }
  144.  
  145.             break;
  146.  
  147.         // WM_USER messages
  148.  
  149.         case WM_VIEWER_CMDLINE:
  150.             return LaunchPictureWnd( (LPSTR) lParam, NULL );
  151.  
  152.         case WM_VIEWER_PICTUREDELETED:
  153.             // Decrement picture count. This is incremented in LaunchPictureWnd
  154.             // when picture is created
  155.             if( --g.wNumPictures <= 0 )
  156.                 ViewerEnableMenus( hwndFrame, FALSE );
  157.             return 0L;
  158.  
  159.         // These next messages are posted by the ole callback function in PictUtl.c
  160.         case WM_VIEWER_OLE_OPTIONSDLG:
  161.             ViewerGetOptions( NULL, (LPQTOLE_OPTIONSPICTURE) lParam );
  162.             return 0L;
  163.  
  164.         case WM_VIEWER_OLE_PLAYOBJECT:
  165.             QTOLE_PlayObject( ViewerQueryOleData(), lParam );
  166.             return 0L;
  167.  
  168.  
  169.         // end WM_USER messages
  170.  
  171.  
  172.         // Standard drag and drop processing. Allows for multiple pictures but
  173.         // does not worry about position of drop
  174.         case WM_DROPFILES:
  175.             return ProcessDroppedFiles( hwndFrame, wParam );
  176.  
  177.         case WM_QUERYENDSESSION:
  178.         case WM_CLOSE:
  179.             if( g.wNumPictures && 
  180.                 ( lpfnEnumPictures = (WNDENUMPROC) MakeProcInstance
  181.                 ( (FARPROC) CloseEnumProc, ViewerQueryInstance()))) { // Give all pictures a chance to stop the close
  182.                 EnumChildWindows( g.hwndClient, lpfnEnumPictures, 0L );
  183.                 FreeProcInstance( (FARPROC) lpfnEnumPictures );
  184.  
  185.                 // If someone didn't want to close, don't kill the app
  186.                 if( NULL != GetWindow( g.hwndClient, GW_CHILD ))
  187.                     return 0L;
  188.             }
  189.  
  190.             // Tell qtole.dll that we are closing the server
  191.             // Don't close if QTOLE_ClosingServerWnd returns FALSE;
  192.             if( ( lpOleData = ViewerQueryOleData()) && 
  193.                 lpOleData->lpqtoleServer &&
  194.                 !QTOLE_ClosingServerWnd( lpOleData, message ))
  195.                 return 0L;
  196.  
  197.             break; // break to DefFrameProc
  198.  
  199.  
  200.         case WM_NCDESTROY:
  201.             DragAcceptFiles( hwndFrame, FALSE );
  202.  
  203.             // Destroy help instance
  204.             DestroyHelpInstance( hwndFrame );
  205.  
  206.             // NULL the global hwnds in viewmain.c
  207.             ViewerNoMoreWindow();
  208.  
  209.             PostQuitMessage( 0 );
  210.             break;
  211.  
  212.     }
  213.  
  214.     return DefFrameProc
  215.         ( hwndFrame, g.hwndClient, message, wParam, lParam );
  216. }
  217.  
  218.  
  219. // Function: ViewerFrameCreate - process WM_CREATE message
  220. // ------------------------------------------------------------------