home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / tools / filebar / source / dll / filebar.cpp next >
Encoding:
C/C++ Source or Header  |  1994-03-10  |  7.6 KB  |  178 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:          March 10, 1994
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29.  
  30. #define INCL_PMWIN
  31. #define INCL_WINSYS
  32. #define INCL_WIN
  33. #define INCL_PM
  34. #define INCL_WINFRAMEMGR
  35. #include <string.h>
  36. #include <stdio.h>
  37. #include "filebar.h"
  38. #define DLL_NAME                 "FILEBAR"        // define the name for our DLL
  39.  
  40. //------------------------------------------------------------------------------
  41. // define data we need for our DLL
  42. //------------------------------------------------------------------------------
  43. HOOKDATA hookData;                                // define data area to store
  44.                                                   // the information we need
  45.                                                   // when we hook the system
  46. BOOL BarAtTop;                                    // is the menubar at the top
  47. BOOL intercept;                                   // should we intercept msgs?
  48. SHORT ScreenY;                                    // height of menubar
  49. SHORT ScreenHeight;                               // useful screen remaining
  50.  
  51. //------------------------------------------------------------------------------
  52. // setFileBarScreen - sets internal position and size data our DLL needs to
  53. // correctly set the maximize screen data
  54. //------------------------------------------------------------------------------
  55. VOID EXPENTRY setFileBarScreen( BOOL position, LONG y, BOOL interceptMsgs )
  56. {
  57.     intercept = interceptMsgs;
  58.     BarAtTop = position;
  59.     ScreenY = y;
  60.     ScreenHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) - y;
  61. }
  62.  
  63.  
  64. //------------------------------------------------------------------------------
  65. // FileBarHook - this is called whenever a message is sent in the system.  So,
  66. // we simply look at each message going by and if it's something dealing with
  67. // moving or maximizing, intercept and alter so that FileBar is always on top
  68. // and no maximizing covers it!
  69. //
  70. // Note:  The parameters sent to FileBarHook are defined in the SendMsg Hook
  71. //
  72. // Returns:  TRUE if the rest of the hook chain is not to be called, or FALSE
  73. //           if the rest of the hook chain should be called.
  74. //------------------------------------------------------------------------------
  75. BOOL EXPENTRY FileBarHook(HAB habAnchor,PSMHSTRUCT structurePtr,BOOL interTask)
  76. {
  77.     switch(structurePtr->msg) {
  78.         //----------------------------------------------------------------------
  79.         // if any window is moved, make sare FileBar is placed on top of it
  80.         //----------------------------------------------------------------------
  81.         case WM_MOVE: {
  82.             if (intercept)
  83.                 WinSetWindowPos( hookData.hwndApp, HWND_TOP,0,0,0,0,SWP_ZORDER);
  84.             return TRUE;
  85.             }
  86.         //----------------------------------------------------------------------
  87.         // if a window is being maximized, make it fit below or on top of the
  88.         // FileBar application window
  89.         //----------------------------------------------------------------------
  90.         case WM_WINDOWPOSCHANGED: {
  91.           FILE* optionFile;
  92.           CHAR tmp[20];
  93.  
  94.           if (!intercept)
  95.               return FALSE;
  96.  
  97.           // the way BocaSoft's WipeOut screen saver is designed, when it is
  98.           // running, FileBar is still visible.  So, when that screen saver is
  99.           // requesting a maximized screen, give it access to the full screen
  100.           WinQuerySessionTitle( habAnchor, 0, tmp, sizeof(tmp) );
  101.           if (strcmp( tmp, "BocaSoft WipeOut") == 0)
  102.               return FALSE;
  103.  
  104.           if (LONGFROMMP(structurePtr->mp2) & AWP_MAXIMIZED) {
  105.             PSWP pSwp = (PSWP)LONGFROMMP(structurePtr->mp1);
  106.             if ((pSwp->x>60000) && (pSwp->y>60000)) {
  107.                 SHORT xBorder = WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER );
  108.                 SHORT yBorder = WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER );
  109.                 if ( !BarAtTop ) {
  110.                     pSwp->x = 0 - xBorder;
  111.                     pSwp->cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) + 2*xBorder;
  112.                     pSwp->y = ScreenY - yBorder - 1;
  113.                     pSwp->cy = ScreenHeight + 2*yBorder + 1;
  114.                     WinSetWindowPos( structurePtr->hwnd, 0, pSwp->x, pSwp->y, pSwp->cx, pSwp->cy, SWP_MOVE|SWP_SIZE);
  115.                     //return TRUE;
  116.                     }
  117.                 else {
  118.                     pSwp->x = 0 - xBorder;
  119.                     pSwp->cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) + 2*xBorder;
  120.                     pSwp->y = 0 - yBorder;
  121.                     pSwp->cy = ScreenHeight + 2*yBorder;
  122.                     WinSetWindowPos( structurePtr->hwnd, 0, pSwp->x, pSwp->y, pSwp->cx, pSwp->cy, SWP_MOVE|SWP_SIZE);
  123.                     //return TRUE;
  124.                     }
  125.                 }
  126.  
  127.             }
  128.           }
  129.         //----------------------------------------------------------------------
  130.         // if it is nothing we care about, pass it onto the system
  131.         //----------------------------------------------------------------------
  132.         default:
  133.             break;
  134.         }
  135.     return FALSE;
  136. }
  137.  
  138.  
  139. //------------------------------------------------------------------------------
  140. // FileBarInit - initialize FileBar DLL.  This will load in the DLL, store the
  141. // handle to the module and set the system hook so that we intercept messages
  142. //
  143. // Returns:  TRUE if successful, FALSE otherwise
  144. //------------------------------------------------------------------------------
  145. BOOL EXPENTRY FileBarInit( HWND hwnd )
  146. {
  147.    hookData.usSzStruct=sizeof(HOOKDATA);
  148.    hookData.hwndApp=hwnd;
  149.  
  150.    if (DosQueryModuleHandle(DLL_NAME,&hookData.hmModule))
  151.       return FALSE;
  152.  
  153.    WinSetHook(WinQueryAnchorBlock(hookData.hwndApp),
  154.               NULLHANDLE,
  155.               HK_SENDMSG,
  156.               (PFN)FileBarHook,
  157.               hookData.hmModule);
  158.  
  159.    return TRUE;
  160. }
  161.  
  162.  
  163. //-------------------------------------------------------------------------
  164. // FileBarQuit - this releases the FileBar DLL
  165. // Returns:  TRUE always
  166. //-------------------------------------------------------------------------
  167. BOOL EXPENTRY FileBarQuit( VOID )
  168. {
  169.    WinReleaseHook(WinQueryAnchorBlock(hookData.hwndApp),
  170.                   NULLHANDLE,
  171.                   HK_SENDMSG,
  172.                   (PFN)FileBarHook,
  173.                   hookData.hmModule);
  174.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  175.    return TRUE;
  176. }
  177.  
  178.