home *** CD-ROM | disk | FTP | other *** search
/ Desktop Works 1995 - 1996 / desktopworks1995-1996.iso / animator / frame.c < prev    next >
C/C++ Source or Header  |  1996-01-01  |  12KB  |  380 lines

  1. #include "animator.h"
  2.  
  3. /* btw: WM_NCCREATE and WM_CREATE return BOOLs. 
  4.    Any message that needs *DefWndProc should call it
  5.    explicitly in its function. */
  6.  
  7. BOOL NEAR PASCAL Frame_OnCreate (HWND,LPCREATESTRUCT);
  8. VOID NEAR PASCAL Frame_OnInitMenu (HWND,HMENU);
  9. VOID NEAR PASCAL Frame_OnCommand (HWND,UINT,HWND,UINT);
  10. VOID NEAR PASCAL Frame_OnSize (HWND,UINT,short,short);
  11. LONG NEAR PASCAL Frame_OnDestroy (HWND);
  12. VOID NEAR PASCAL Frame_OnClose (HWND);
  13.  
  14.  
  15.  
  16.  
  17. //////////////////////////////////////////////////////////////////////////
  18. // FrameProc() - good example of how Message Crackers may be used.
  19. // Intercepts messages, handles the ones we hande, and DefWndProc()'s
  20. // the rest.
  21. //////////////////////////////////////////////////////////////////////////
  22.  
  23. LRESULT _export CALLBACK FrameProc (WNDPROC_PARAMS)
  24. {
  25.     switch (uMsg) 
  26.     {
  27.         HANDLE_MSG (hWnd, WM_CREATE,          Frame_OnCreate); 
  28.         HANDLE_MSG (hWnd, WM_INITMENU,        Frame_OnInitMenu);
  29.         HANDLE_MSG (hWnd, WM_COMMAND,         Frame_OnCommand);
  30.         HANDLE_MSG (hWnd, WM_SIZE,            Frame_OnSize);
  31.         HANDLE_MSG (hWnd, WM_CLOSE,           Frame_OnClose);
  32.         HANDLE_MSG (hWnd, WM_DESTROY,         Frame_OnDestroy);
  33.     }
  34.  
  35.     return (LRESULT)DefFrameProc(hWnd, _hwndClient, uMsg, wParam, lParam);
  36. }
  37.  
  38.  
  39.  
  40. //////////////////////////////////////////////////////////////////////////
  41. // BroadcastProc - This is simply the enumeration function for all of 
  42. // the child MDI windows.  It broadcasts a message to all alive MDI
  43. // children.  In our case, we just use it to broadcast the WM_CLOSE
  44. // message to everybody when the user wants to terminate session.
  45. //////////////////////////////////////////////////////////////////////////
  46.  
  47. BOOL _export CALLBACK BroadcastProc(HWND  hwnd,
  48.                   LONG  lParam)
  49. {
  50.     if (GetWindow(hwnd, GW_OWNER))
  51.     {
  52.         return TRUE;
  53.     }
  54.  
  55.     if (lParam == WM_CLOSE)
  56.     {
  57.         if (SendMessage(hwnd, WM_QUERYENDSESSION, 0, 0L))
  58.         {
  59.             MDI_Destroy (_hwndClient, hwnd);
  60.         }
  61.         else
  62.         {
  63.             return FALSE;
  64.         }
  65.     }
  66.     else
  67.     {
  68.         SendMessage(hwnd, (UINT)LOWORD(lParam), (WPARAM)0, 0L);
  69.     }
  70.  
  71.     return TRUE;
  72. }
  73.     
  74.  
  75.  
  76. //////////////////////////////////////////////////////////////////////////
  77. // Frame_OnCreate() - Restores position if there was anything in the
  78. // WIN.INI, then creates the client and status children.
  79. //////////////////////////////////////////////////////////////////////////
  80.  
  81. BOOL NEAR PASCAL Frame_OnCreate (HWND hwnd, CREATESTRUCT FAR* lpCS)
  82. {
  83.     CLIENTCREATESTRUCT  clicr;
  84.  
  85.     clicr.hWindowMenu = _hmenuChildWindow;
  86.     clicr.idFirstChild = IDM_FIRSTCHILD;
  87.  
  88.     _hwndClient = CreateWindow("MDICLIENT", NULL,
  89.                 WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
  90.                 0, 0, 0, 0, hwnd, ID_CLIENT, _hInst, (LPSTR)&clicr);
  91.  
  92.     if (!IsWindow(_hwndClient)) return FALSE;
  93.     
  94.     // we find out the y-extent of the status bar based on the
  95.     // height of the ansi-variable font.
  96.  
  97.     _nStatBarDY = GetANSITextHeight() + 7; // the '7' is the dead space
  98.  
  99.     _hwndStatus = CreateWindow (_szStatBarClass,NULL,
  100.                            WS_CHILD | WS_VISIBLE,
  101.                            0,0,0,0,
  102.                            hwnd,ID_STATBAR, _hInst, NULL);
  103.  
  104.     if (!IsWindow(_hwndStatus)) 
  105.     {
  106.         return FALSE;
  107.     }
  108.     
  109.     if (!SetTimer (hwnd, ID_TIMER, MINTIME, _lpfnTimer))
  110.     {
  111.         MESSAGE (IDS_TimerFail);
  112.         return FALSE;
  113.     }
  114.  
  115.     // Set up the Notify callback so we know when a task starts or dies...
  116.  
  117.     if (!NotifyRegister ((HTASK)GetWindowTask(hwnd), 
  118.         (LPFNNOTIFYCALLBACK)_lpfnNotify, NF_NORMAL))
  119.     {
  120.         MESSAGE (IDS_NotifyFail);
  121.         return FALSE;
  122.     }
  123.     
  124.     return TRUE;
  125. }
  126.  
  127.  
  128.  
  129. //////////////////////////////////////////////////////////////////////////
  130. // Frame_OnInitMenu() - Grays out menu items if needed, depending
  131. // on if something is currently animating, etc.
  132. //////////////////////////////////////////////////////////////////////////
  133.  
  134. VOID NEAR PASCAL Frame_OnInitMenu(HWND hwnd, HMENU hMenu)
  135. {   
  136.     HWND hwndChild = MDI_GetActive (_hwndClient);            
  137.  
  138.     if (IsWindow(hwndChild)) 
  139.     {
  140.         short    sChild = WINDOWNUM(hwndChild);
  141.         BOOL     b;
  142.         
  143.         b = (BOOL)(ISANIMATING(sChild) && SZEXELINK(sChild)[0] && TIMEINT(sChild));
  144.         EnableMenuItem (hMenu, IDM_STOP,        b ? MF_ENABLED : MF_GRAYED);
  145.         EnableMenuItem (hMenu, IDM_GO,          b ? MF_GRAYED : MF_ENABLED);
  146.         EnableMenuItem (hMenu, IDM_SETTINGS,    b ? MF_GRAYED : MF_ENABLED);
  147.         EnableMenuItem (hMenu, IDM_INSERTICON,  b ? MF_GRAYED : MF_ENABLED);
  148.         EnableMenuItem (hMenu, IDM_ADDICON,     b ? MF_GRAYED : MF_ENABLED);
  149.         EnableMenuItem (hMenu, IDM_DELETEICON,  b ? MF_GRAYED : MF_ENABLED);
  150.     }
  151.  
  152.     DefFrameProc(hwnd, _hwndClient, WM_INITMENU, (WPARAM)hMenu, 0L);
  153. }
  154.  
  155.  
  156.  
  157. //////////////////////////////////////////////////////////////////////////
  158. // Frame_OnCommand() - This is what handles file | new and file | open,
  159. // task exit/entry notification, and other things that logically need
  160. // to be handles in the Frame proc.
  161. //////////////////////////////////////////////////////////////////////////
  162.  
  163. VOID NEAR PASCAL Frame_OnCommand (HWND hwnd, UINT uMsg, HWND hChild, UINT uExtra) 
  164. {
  165.     short               sChild;
  166.     MDICREATESTRUCT     mdicr;
  167.     char                szBuff[32];
  168.     char                szFileName [MAX_FILE_SIZE];
  169.     HWND                hwndChild;
  170.  
  171.     switch (uMsg) 
  172.     {
  173.         case IDM_ABOUT:
  174.         {
  175.             DialogBox (_hInst, ABOUT, hwnd, _lpfnAbout);
  176.             break;
  177.         }
  178.         case IDM_NEW:
  179.         {
  180.             for (sChild = 0 ;
  181.                  _lPageFlags & (1 << sChild) ;
  182.                  ++sChild) ;
  183.  
  184.             if (sChild >= MAXANIMATIONS)
  185.             {
  186.                 MESSAGE (IDS_MaxAnimations);
  187.                 break;
  188.             }
  189.  
  190.             _lPageFlags |= 1 << sChild;
  191.  
  192.             wsprintf((LPSTR)szBuff,(LPSTR)"%s%d",
  193.                 (LPSTR)_szUntitled, sChild+1);
  194.  
  195.             mdicr.szClass   = (LPSTR)_szChildClass;
  196.             mdicr.szTitle   = (LPSTR)szBuff;
  197.             mdicr.hOwner    = _hInst;
  198.             mdicr.x         = CW_USEDEFAULT;
  199.             mdicr.y         = CW_USEDEFAULT;
  200.             mdicr.cx        = CW_USEDEFAULT;
  201.             mdicr.cy        = CW_USEDEFAULT;
  202.             mdicr.style     = 0;
  203.             mdicr.lParam    = (LPARAM)sChild;
  204.  
  205.             MDI_Create (_hwndClient, &mdicr);
  206.  
  207.             break;
  208.         }        
  209.  
  210.         case IDM_OPEN:
  211.             szFileName[0] = '\0';
  212.             OpenIconsInFile(szFileName) ;
  213.             // no break, because we need to refresh animations anyways...
  214.         case IDN_NEWTASK:   
  215.             RefreshAnimations ();
  216.             break;
  217.  
  218.         case IDN_EXITTASK:
  219.         {
  220.             short i;
  221.  
  222.             for (i=0 ; i<MAXANIMATIONS ; i++)
  223.             {
  224.                 if (IsWindow (HWNDANIM(i)) && !IsWindow(HWNDTARGET(i)))
  225.                 {
  226.                     SET_EXELOADED (i, FALSE);
  227.                     SET_HWNDTARGET (i, NULL);
  228.                     SET_HPREVICON (i, NULL);
  229.                 }
  230.             }
  231.  
  232.             break;
  233.         }
  234.  
  235.         case IDM_CLOSE:
  236.         {
  237.             if (hwndChild = MDI_GetActive (_hwndClient))
  238.             {
  239.                 FORWARD_WM_CLOSE (hwndChild, SendMessage); 
  240.             }
  241.             break;
  242.         }
  243.         case IDM_CLOSEALL:
  244.         {
  245.             if (_lPageFlags)
  246.             {
  247.                 EnumChildWindows(_hwndClient,(FARPROC)_lpfnBroadcast, 
  248.                     (LONG)WM_CLOSE);
  249.             }
  250.             break;
  251.         }
  252.         case IDM_EXIT:
  253.         {
  254.             SendMessage (hwnd, WM_CLOSE, 0, 0L);
  255.             break;
  256.         }
  257.         case WM_MDITILE:
  258.         case WM_MDICASCADE:
  259.         case WM_MDIICONARRANGE:
  260.         {
  261.             SendMessage(_hwndClient, uMsg, 0, 0L);
  262.             break;
  263.         }
  264.