home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / isrun01.zip / Class_WindowList.cpp next >
C/C++ Source or Header  |  1997-10-12  |  5KB  |  161 lines

  1. #define INCL_DOSMEMMGR
  2. #define INCL_DOSERRORS
  3. #define INCL_WINSWITCHLIST
  4.  
  5. #include <iostream.h>
  6. #include <os2.h>
  7.  
  8. #include "stristr.h"
  9. #include "Class_WindowList.hpp"
  10.  
  11. //------------------------------------------------------------------------
  12.  
  13. Class_WindowList::Class_WindowList( BOOL _bCompareFullString, BOOL _bCaseSensitive )
  14. {
  15.      bCaseSensitive = _bCaseSensitive;
  16.      bCompareFullString = _bCompareFullString;
  17.  
  18.      // Determine the number of items in the list,
  19.      // calculate the size of the buffer needed,
  20.      // and finally query the items in the switch list
  21.  
  22.      ULONG cbItems;// Number of items in list
  23.      HAB hab;
  24.      cbItems = WinQuerySwitchList( hab, NULL, 0 );
  25.  
  26.      ULONG ulBufSize;// Size of the buffer
  27.      ulBufSize = ( cbItems * sizeof( SWENTRY ) ) + sizeof( HSWITCH );
  28.  
  29.      // Allocate the buffer
  30.      pswblk = new SWBLOCK [ cbItems ];
  31.  
  32.     // Call WinQuerySwitchList again to fill our buffer with information
  33.      cbItems = WinQuerySwitchList( hab, pswblk, ulBufSize );
  34. }
  35.  
  36. //------------------------------------------------------------------------
  37.  
  38. Class_WindowList::~Class_WindowList()
  39. {
  40.      // Deallocate dynamic memory
  41.      delete [] pswblk;
  42. }
  43.  
  44. //------------------------------------------------------------------------
  45.  
  46. BOOL Class_WindowList::InList( PSZ pszName )
  47. {
  48.      // Determines if pszName is present in the switch list
  49.      int y;
  50.      for( int x = 0; x < pswblk->cswentry; x++ )
  51.      {
  52.           // Replace hidden characters with a space
  53.           // Necessary when the name of an object is on
  54.           // multiple lines
  55.           for( y = 0; y < strlen( pswblk->aswentry[x].swctl.szSwtitle ); y++ )
  56.                if( pswblk->aswentry[x].swctl.szSwtitle[y] < ' ' )
  57.                     pswblk->aswentry[x].swctl.szSwtitle[y] = ' ';
  58.  
  59.           if( bCaseSensitive )
  60.           {
  61.                // Case sensitive search
  62.                if( bCompareFullString )
  63.                {
  64.                     // Compare all the characters in the string
  65.                     if( !strcmp( pswblk->aswentry[x].swctl.szSwtitle, pszName ) )
  66.                          return TRUE;
  67.                }
  68.                else
  69.                {
  70.                     // Find the string in the task entry
  71.                     if( strstr( pswblk->aswentry[x].swctl.szSwtitle, pszName ) )
  72.                          return TRUE;
  73.                }
  74.           }
  75.           else
  76.           {
  77.                // Case insensitive search
  78.                if( bCompareFullString )
  79.                {
  80.                     // Compare all the characters in the string
  81.                     if( !stricmp( pswblk->aswentry[x].swctl.szSwtitle, pszName ) )
  82.                          return TRUE;
  83.                }
  84.                else
  85.                {
  86.                     // Find the string in the task entry
  87.                     if( stristr( pswblk->aswentry[x].swctl.szSwtitle, pszName ) )
  88.                          return TRUE;
  89.                }
  90.           }
  91.      }
  92.      return FALSE;
  93. }
  94.  
  95. //------------------------------------------------------------------------
  96.  
  97. SWCNTRL Class_WindowList::Get_swcntrl( PSZ pszName )
  98. {
  99.      // Retrieve the switch-list control block structure of pszName
  100.      for( int x = 0; x < pswblk->cswentry; x++ )
  101.      {
  102.           if( !strcmp( pswblk->aswentry[x].swctl.szSwtitle, pszName ) )
  103.                return pswblk->aswentry[x].swctl;
  104.      }
  105.      // The entry is not found; return nothing
  106.      swcntrl.hwnd = NULL;
  107.      swcntrl.hwndIcon = NULL;
  108.      swcntrl.hprog = NULL;
  109.      swcntrl.idProcess = 0;
  110.      swcntrl.idSession = 0;
  111.      swcntrl.uchVisibility = 0;
  112.      swcntrl.fbJump = SWL_NOTJUMPABLE;
  113.      *swcntrl.szSwtitle = '\0';
  114.      swcntrl.bProgType = 0;
  115.      return swcntrl;
  116. }
  117.  
  118. //------------------------------------------------------------------------
  119.  
  120. BOOL Class_WindowList::Enumerate( SWCNTRL &swcntrl )
  121. {
  122.      // Enumerate all the switch control entries
  123.      // In order for this to work properly, all the items must be retrieved
  124.      // i.e. the function must return FALSE
  125.      static int nPosition = 0;
  126.      if( nPosition < pswblk->cswentry )
  127.      {
  128.           // Return the current item
  129.           swcntrl = pswblk->aswentry[nPosition].swctl;
  130.           strcpy( swcntrl.szSwtitle, pswblk->aswentry[nPosition].swctl.szSwtitle );
  131.           nPosition++;
  132.           return TRUE;
  133.      }
  134.      else
  135.      {
  136.           // We've enumerated all the items
  137.           nPosition = 0;
  138.           return FALSE;
  139.      }
  140. }
  141.  
  142. //------------------------------------------------------------------------
  143.  
  144. int Class_WindowList::Get_Count()
  145. {
  146.      // Return the number of items in the switch list
  147.      return pswblk->cswentry;
  148. }
  149.  
  150. /*
  151.  
  152. //------------------------------------------------------------------------
  153.  
  154. Class_WindowList::
  155. {
  156.      //
  157. }
  158.  
  159. */
  160.  
  161.