home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / Lookup.cpp < prev    next >
C/C++ Source or Header  |  2000-05-11  |  2KB  |  86 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : lookup.cpp                                                             //
  10. //  Description: index to string mapping                                             //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define NOCRYPT
  15. #define STRICT
  16. #define WIN32_LEAN_AND_MEAN
  17.  
  18. #include <windows.h>
  19. #include <string.h>
  20. #include <tchar.h>
  21.  
  22. #include "Lookup.h"
  23.  
  24.  
  25. bool Lookup(unsigned index, const DicItem *dic, TCHAR * szResult)
  26. {
  27.     while (dic->name!=NULL)
  28.     {
  29.         if (dic->key==index)
  30.         {
  31.             _tcscpy(szResult, dic->name);
  32.             return true;
  33.         }
  34.         dic++;            
  35.     }            
  36.     
  37.     wsprintf(szResult, TEXT("Unknown(%lx)"), index);    
  38.     
  39.     return false;
  40. }
  41.  
  42.  
  43. const TCHAR *Lookup(unsigned index, const DicItem *dic)
  44. {
  45.     static TCHAR mess_Rslt[64];
  46.     
  47.     mess_Rslt[0] = 0;
  48.     
  49.     while (dic->name!=NULL)
  50.     {
  51.         if ((index & dic->mask) == dic->key)
  52.         {
  53.             if ( dic->mask == 0xffffffff)
  54.                 return dic->name;
  55.  
  56.             if ( mess_Rslt[0] )
  57.             {
  58.                 lstrcat(mess_Rslt, _T(" | "));
  59.                 lstrcat(mess_Rslt, dic->name);
  60.             }
  61.             else
  62.                 lstrcat(mess_Rslt, dic->name);
  63.         }
  64.         
  65.         dic++;            
  66.     }            
  67.     
  68.     if ( mess_Rslt[0] == 0)
  69.         wsprintf(mess_Rslt, TEXT("0x%x /*Unknown*/"), index);    
  70.     
  71.     return mess_Rslt;    
  72. }
  73.  
  74.  
  75. unsigned Decode(const TCHAR *item, const DicItem *dic)
  76. {
  77.     while (dic->name!=NULL)
  78.     {
  79.         if (_tcscmp(item, dic->name)==0)
  80.             return dic->key;
  81.         dic++;
  82.     }
  83.     
  84.     return 0xFFFFFFFF;
  85. }
  86.