home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol04 / 01b / macsl / mpmutil.c < prev    next >
C/C++ Source or Header  |  1988-10-04  |  5KB  |  173 lines

  1. /*-----------------------------------------------------------------*/
  2. /* MpmUtil.c                                                       */
  3. /* Miscellaneous utility functions                                 */
  4. /*-----------------------------------------------------------------*/
  5.  
  6. #include "MacPM.h"
  7.  
  8. CHAR      _szNull[1];
  9.  
  10. LONG      _alSysVal[SV_CSYSVALUES];
  11.  
  12. SHORT     _sSetFocusDepth;
  13.  
  14. HWND      _hwndObject;
  15. HWND      _hwndDesktop;
  16. HWND      _hwndActive;
  17. HWND      _hwndFocus;
  18. HWND      _hwndMenu;
  19.  
  20. PS        _ps1;
  21. PPS       _pps1;
  22. HPS       _hps1;
  23.  
  24. /*-----------------------------------------------------------------*/
  25. /* Fill *ppid with process and task ID's.  These are fake numbers! */
  26. /*-----------------------------------------------------------------*/
  27.  
  28. USHORT APIENTRY DosGetPid( ppid )
  29.     PPIDINFO    ppid;
  30. {
  31.     ppid->pid = MY_PID;
  32.     ppid->tid = MY_PID;
  33.     ppid->pidParent = 0;
  34. }
  35.  
  36. /*-----------------------------------------------------------------*/
  37. /* Find out if a rectangle is empty.                               */
  38. /*-----------------------------------------------------------------*/
  39.  
  40. BOOL APIENTRY WinIsRectEmpty( hab, prcl )
  41.     HAB         hab;
  42.     PRECTL      prcl;
  43. {
  44.     return prcl->xRight <= prcl->xLeft  ||
  45.            prcl->yTop   <= prcl->yBottom;
  46. }
  47.  
  48. /*-----------------------------------------------------------------*/
  49. /* Load a string from the resource file.                           */
  50. /*-----------------------------------------------------------------*/
  51.  
  52. SHORT APIENTRY WinLoadString( hab, hmod, id, sMax, pszBuf )
  53.     HAB         hab;
  54.     HMODULE     hmod;
  55.     USHORT      id;
  56.     SHORT       sMax;
  57.     PSZ         pszBuf;
  58. {
  59.     CHAR        szBuf[256];
  60.     SHORT       sLen;
  61.  
  62.     GetIndString( szBuf, 256, id );
  63.  
  64.     sLen = szBuf[0];  /* Pascal string length */
  65.     if( sLen > sMax-1 )
  66.       sLen = sMax - 1;
  67.  
  68.     memcpy( pszBuf, szBuf+1, sLen );
  69.     pszBuf[sLen] = '\0';
  70.  
  71.     return sLen;
  72. }
  73.  
  74. /*-----------------------------------------------------------------*/
  75. /* Set one of the SV_ system values.  We should check whether the  */
  76. /* the value is changeable, but who cares...                       */
  77. /*-----------------------------------------------------------------*/
  78.  
  79. BOOL APIENTRY WinSetSysValue( hwndDesktop, iSysValue, lValue )
  80.     HWND        hwndDesktop;
  81.     SHORT       iSysValue;
  82.     LONG        lValue;
  83. {
  84.     if( iSysValue < 0 || iSysValue >= SV_CSYSVALUES )
  85.       return FALSE;
  86.  
  87.     _alSysVal[iSysValue] = lValue;
  88.  
  89.     return TRUE;
  90. }
  91.  
  92. /*-----------------------------------------------------------------*/
  93. /* Debugging function to display an error message.  Works with     */
  94. /* any Mac debugger.                                               */
  95. /*-----------------------------------------------------------------*/
  96.  
  97. LOCAL VOID MpmErrorBox( pszMsg )
  98.     PSZ         pszMsg;
  99. {
  100.     CHAR        szMsg[80];
  101.  
  102.     strcpy( szMsg, pszMsg );
  103.     DebugStr( CtoPstr(szMsg) );
  104.     ExitToShell();
  105. }
  106.  
  107. /*-----------------------------------------------------------------*/
  108. /* Allocate a Mac memory handle (movable) and zero out the block.  */
  109. /*-----------------------------------------------------------------*/
  110.  
  111. LOCAL PVOID MpmNewHandleZ( usLen )
  112.     USHORT      usLen;
  113. {
  114.     asm
  115.     {
  116.       clr.L       D0
  117.       move.W      usLen, D0
  118.       NewHandle   CLEAR
  119.       move.L      A0, D0
  120.     }
  121. }
  122.  
  123. /*-----------------------------------------------------------------*/
  124. /* Allocate a Mac fixed memory block and zero it out.              */
  125. /*-----------------------------------------------------------------*/
  126.  
  127. LOCAL PVOID MpmNewPtrZ( usLen )
  128.     USHORT      usLen;
  129. {
  130.     asm
  131.     {
  132.       clr.L       D0
  133.       move.W      usLen, D0
  134.       NewPtr      CLEAR
  135.       move.L      A0, D0
  136.     }
  137. }
  138.  
  139. /*-----------------------------------------------------------------*/
  140. /* Make sure hwnd bears some resemblance to a valid window handle, */
  141. /* by checking its signature word.                                 */
  142. /*-----------------------------------------------------------------*/
  143.  
  144. LOCAL BOOL MpmValidateWindow( hwnd )
  145.     HWND        hwnd;
  146. {
  147.     if( MYWNDOF(hwnd).signature != WND_SIGNATURE )
  148.     {
  149.       ERROR( "Invalid window handle!" );
  150.       return FALSE;
  151.     }
  152.  
  153.     return TRUE;
  154. }
  155.  
  156. /*-----------------------------------------------------------------*/
  157. /* Same as MpmValidateWindow, but allows NULL without complaining. */
  158. /*-----------------------------------------------------------------*/
  159.  
  160. LOCAL BOOL MpmValidateWindowNull( hwnd )
  161.     HWND        hwnd;
  162. {
  163.     if( hwnd  &&  MYWNDOF(hwnd).signature != WND_SIGNATURE )
  164.     {
  165.       ERROR( "Invalid window handle!" );
  166.       return FALSE;
  167.     }
  168.  
  169.     return TRUE;
  170. }
  171.  
  172. /*-----------------------------------------------------------------*/
  173.