home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 February / SOFM_Feb1995.bin / pc / os2 / filebar / filebar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-24  |  8.9 KB  |  213 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //                    FileBar - Maximize/Movement Hook DLL
  4. //
  5. //         OS/2 Application Launch Facility and WPS Shell Replacement
  6. //
  7. //                         Written By Eric A. Wolf
  8. //                 Copyright (C) 1994 - All Rights Reserved
  9. //
  10. // This source code may be used for reference ONLY!  It is provided AS-IS and no
  11. // guarantees are made as to its utility, functionality or correctness.  It is
  12. // provided solely as a guide to aid aspiring OS/2 2.x Presentation Manager
  13. // programmers in developing their own PM applications.  No modifications are
  14. // to be made to this code for re-release as a same or different product.  This
  15. // code must be distributed (in its original entirety) with the executable
  16. // portion of this product.
  17. //
  18. //          -- Please register this shareware product for $10 today --
  19. //                          See documentation for details
  20. //
  21. // DLL Project Start Date:      March  5, 1994
  22. // DLL Project Completion Date: March  6, 1994
  23. //
  24. // Written using Borland C++ for OS/2, version 1.0
  25. //
  26. // File Last Modified:          July   5, 1994
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. #define INCL_PMWIN
  30. #define INCL_WINSYS
  31. #define INCL_WIN
  32. #define INCL_PM
  33. #define INCL_WINFRAMEMGR
  34. #define DLL_NAME                 "FILEBAR"        // define the name for our DLL
  35. #define POPUPMENU                9999             // msg to send to signal popup
  36.  
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <dos.h>
  40. #include "filebar.h"
  41.  
  42.  
  43. //------------------------------------------------------------------------------
  44. // define data we need for our DLL
  45. //------------------------------------------------------------------------------
  46. LONG    messageID;                                // message to popup our menu
  47. SHORT   ScreenY;                                  // height of menubar
  48. SHORT   ScreenHeight;                             // useful screen remaining
  49. HWND    hwndApp;                                  // store handle of app window
  50. HMODULE hmModule;                                 // store module data for app
  51. BOOL    BarAtTop;                                 // is the menubar at the top
  52. BOOL    intercept;                                // should we intercept msgs?
  53. BOOL    popUpMenu;                                // allow popup menu?
  54. BOOL    RunningWarp;                              // Are we running OS/2 Warp
  55.  
  56. extern unsigned char _osmajor;
  57. extern unsigned char _osminor;
  58.  
  59.  
  60. //------------------------------------------------------------------------------
  61. // setFileBarScreen - sets internal position and size data our DLL needs to
  62. // correctly set the maximize screen data
  63. //------------------------------------------------------------------------------
  64. VOID EXPENTRY setFileBarScreen( BOOL position, LONG y, BOOL interceptMsgs, BOOL popUp, LONG msgID )
  65. {
  66.     messageID    = msgID;
  67.     intercept    = interceptMsgs;
  68.     popUpMenu    = popUp;
  69.     BarAtTop     = position;
  70.     ScreenY      = (SHORT)y;
  71.     ScreenHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) - y;
  72. }
  73.  
  74.  
  75. //------------------------------------------------------------------------------
  76. // Handle all input messages - search for WM_CHORD
  77. //------------------------------------------------------------------------------
  78. BOOL EXPENTRY FileBarInputHook(HAB habAnchor,PQMSG pqmMsg,ULONG ulFlags)
  79. {
  80.     //--------------------------------------------------------------------------
  81.     //
  82.     //--------------------------------------------------------------------------
  83.     if ((pqmMsg->msg == messageID) && (popUpMenu))
  84.         return WinPostMsg( hwndApp, WM_COMMAND, MPFROMLONG(POPUPMENU), MPFROMLONG(pqmMsg->hwnd) );
  85.     return FALSE;
  86. }
  87.  
  88.  
  89. //------------------------------------------------------------------------------
  90. // check to see if the window belongs to BocaSoft's WipeOut screen saver
  91. //------------------------------------------------------------------------------
  92. BOOL isScreenSaver( HWND window )
  93. {
  94.     SWCNTRL swctl;
  95.  
  96.     WinQuerySwitchEntry( WinQuerySwitchHandle( window, 0 ), &swctl );
  97.     return (!stricmp( swctl.szSwtitle, "BocaSoft WipeOut" ));
  98. }
  99.  
  100.  
  101. //------------------------------------------------------------------------------
  102. // FileBarHook - this is called whenever a message is sent in the system.  So,
  103. // we simply look at each message going by and if it's something dealing with
  104. // moving or maximizing, intercept and alter so that FileBar is always on top
  105. // and no maximizing covers it!
  106. //
  107. // Note:  The parameters sent to FileBarHook are defined in the SendMsg Hook
  108. //
  109. // Returns:  TRUE if the rest of the hook chain is not to be called, or FALSE
  110. //           if the rest of the hook chain should be called.
  111. //------------------------------------------------------------------------------
  112. BOOL EXPENTRY FileBarHook(HAB habAnchor,PSMHSTRUCT structurePtr,BOOL interTask)
  113. {
  114.   if (intercept)
  115.      switch(structurePtr->msg) {
  116.         //----------------------------------------------------------------------
  117.         // if any window is moved, make sare FileBar is placed on top of it
  118.         //----------------------------------------------------------------------
  119.         case WM_MOVE: {
  120.             if (!isScreenSaver( structurePtr->hwnd ))
  121.                 return WinSetWindowPos( hwndApp, HWND_TOP,0,0,0,0,SWP_ZORDER);
  122.             return FALSE;
  123.             }
  124.         //----------------------------------------------------------------------
  125.         // if a window is being maximized, make it fit below or on top of the
  126.         // FileBar application window
  127.         //----------------------------------------------------------------------
  128.         case WM_WINDOWPOSCHANGED: {
  129.           // the way BocaSoft's WipeOut screen saver is designed, when it is
  130.           // running, FileBar is still visible.  So, when that screen saver is
  131.           // requesting a maximized screen, give it access to the full screen
  132.  
  133.           if (isScreenSaver( structurePtr->hwnd ))
  134.               return FALSE;
  135.  
  136.           if (LONGFROMMP(structurePtr->mp2) & AWP_MAXIMIZED) {
  137.               PSWP pSwp = (PSWP)LONGFROMMP(structurePtr->mp1);
  138.  
  139.               if (((pSwp->x>60000) && (pSwp->y>60000)) || (RunningWarp)) {
  140.                 SHORT xBorder = WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER );
  141.                 SHORT yBorder = WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER );
  142.                 pSwp->x = -xBorder;
  143.                 pSwp->cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) + 2*xBorder;
  144.                 pSwp->cy = ScreenHeight + yBorder + yBorder + 1;
  145.                 if ( BarAtTop ) {
  146.                     pSwp->y  = -yBorder;
  147.                     pSwp->cy--;
  148.                     }
  149.                 else
  150.                     pSwp->y = ScreenY - yBorder - 1;
  151.  
  152.                 return WinSetWindowPos( structurePtr->hwnd, 0, pSwp->x, pSwp->y, pSwp->cx, pSwp->cy, SWP_MOVE|SWP_SIZE);
  153.                 }
  154.             }
  155.           }
  156.         default:
  157.             break;
  158.         }
  159.     return FALSE;
  160. }
  161.  
  162.  
  163. //------------------------------------------------------------------------------
  164. // FileBarInit - initialize FileBar DLL.  This will load in the DLL, store the
  165. // handle to the module and set the system hook so that we intercept messages
  166. //
  167. // Returns:  TRUE if successful, FALSE otherwise
  168. //------------------------------------------------------------------------------
  169. BOOL EXPENTRY FileBarInit( HWND hwnd )
  170. {
  171.    hwndApp = hwnd;
  172.    RunningWarp = ((_osmajor==20) && (_osminor==30));
  173.  
  174.    if (DosQueryModuleHandle(DLL_NAME,&hmModule))
  175.       return FALSE;
  176.  
  177.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  178.    WinSetHook(WinQueryAnchorBlock(hwndApp),
  179.               NULLHANDLE,
  180.               HK_SENDMSG,
  181.               (PFN)FileBarHook,
  182.               hmModule);
  183.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  184.    WinSetHook(WinQueryAnchorBlock(hwndApp),
  185.               NULLHANDLE,
  186.               HK_INPUT,
  187.               (PFN)FileBarInputHook,
  188.               hmModule);
  189.    return WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  190. }
  191.  
  192.  
  193. //-------------------------------------------------------------------------
  194. // FileBarQuit - this releases the FileBar DLL
  195. // Returns:  TRUE always
  196. //-------------------------------------------------------------------------
  197. BOOL EXPENTRY FileBarQuit( VOID )
  198. {
  199.    WinReleaseHook(WinQueryAnchorBlock(hwndApp),
  200.                   NULLHANDLE,
  201.                   HK_SENDMSG,
  202.                   (PFN)FileBarHook,
  203.                   hmModule);
  204.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  205.    WinReleaseHook(WinQueryAnchorBlock(hwndApp),
  206.                   NULLHANDLE,
  207.                   HK_INPUT,
  208.                   (PFN)FileBarInputHook,
  209.                   hmModule);
  210.    return WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  211. }
  212.  
  213.