home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / SHARE / os2 / edm2 / common / snippets / splitfilename.txt < prev   
Encoding:
Text File  |  1997-10-30  |  4.8 KB  |  132 lines

  1. Larry Salomon, Jr.:
  2.  
  3. (Sigh) There was only one submission this month, but unfortunately the
  4. person who sent it to me did not write it; remember, you must be the
  5. author and you must give me permission to publish your code!
  6.  
  7. Even with this setback, I cannot admit defeat, so I have once again
  8. reached down into my black hat and pulled out two useful functions.  As
  9. before, all of these are located in the file snippet.zip.
  10.  
  11.  
  12. BOOL splitFilename(PCHAR pchFile,PCHAR pchDrive,PCHAR pchPath,PCHAR
  13. pchName)
  14.  
  15. //-------------------------------------------------------------------------
  16.  
  17. // This function splits a filename into the drive, path, and name components.
  18.  
  19. // This is the functional equivalent of the MSC 6.0 function _splitpath().
  20. //
  21. // Input:  pchFile - points to the filename to split
  22. // Output:  pchDrive - if not NULL, points to the buffer which receives
  23. //                     the drive portion of the filename
  24. //          pchPath - if not NULL, points to the buffer which receives
  25. //                    the path portion of the filename
  26. //          pchName - if not NULL, points to the buffer which receives
  27. //                    the name portion of the filename
  28. // Returns:  TRUE if successful, FALSE otherwise
  29. //-------------------------------------------------------------------------
  30. {
  31.    PCHAR pchBegin;
  32.    PCHAR pchEnd;
  33.  
  34.    pchBegin=pchFile;
  35.    pchEnd=strchr(pchBegin,':');
  36.  
  37.    if (pchDrive!=NULL) {
  38.       *pchDrive=0;
  39.  
  40.       if (pchEnd!=NULL) {
  41.          strncat(pchDrive,pchBegin,pchEnd-pchBegin+1);
  42.       } /* endif */
  43.    } /* endif */
  44.  
  45.    if (pchEnd!=NULL) {
  46.       pchBegin=pchEnd+1;
  47.    } /* endif */
  48.  
  49.    pchEnd=strrchr(pchBegin,'\\');
  50.  
  51.    if (pchPath!=NULL) {
  52.       *pchPath=0;
  53.  
  54.       if (pchEnd!=NULL) {
  55.          strncat(pchPath,pchBegin,pchEnd-pchBegin+1);
  56.       } /* endif */
  57.    } /* endif */
  58.  
  59.    if (pchEnd!=NULL) {
  60.       pchBegin=pchEnd+1;
  61.    } /* endif */
  62.  
  63.    if (pchName!=NULL) {
  64.       strcpy(pchName,pchBegin);
  65.    } /* endif */
  66.  
  67.    return TRUE;
  68. }
  69.  
  70. BOOL isWindowOfClass(HWND hwndWnd,PCHAR pchClass)
  71. //-------------------------------------------------------------------------
  72. // This function determines whether or not the specified window is of
  73. // the specified class.  This will work for either private classes
  74. // (registered with WinRegisterClass) or the public classes (specified
  75. // by a WC_* constant).
  76. //
  77. // Input:  hwndWnd - specifies the window handle.
  78. //         pchClass - points to either the window class or specifies a
  79. //                    WC_* constant to compare with.
  80. // Returns:  TRUE if hwndWnd is of class pchClass, FALSE otherwise.
  81. //-------------------------------------------------------------------------
  82. {
  83.    CHAR achClass[256];
  84.    ATOM aAtom;
  85.  
  86.    //----------------------------------------------------------------------
  87.    // For the WC_* classes, WinQueryClassName returns the string
  88.    // representation of the integer atom as stored in the system atom
  89.    // table.  The string representation of *any* integer atom is expressed
  90.    // in the form "#ddddd", where 'ddddd' are the decimal digits specifying
  91.    // the value of the atom.
  92.    //
  93.    // We can check the first character of the class name returned to see
  94.    // if the window is of a predefined type.
  95.    //----------------------------------------------------------------------
  96.    WinQueryClassName(hwndWnd,sizeof(achClass),achClass);
  97.  
  98.    if (achClass[0]=='#') {
  99.       //-------------------------------------------------------------------
  100.       // We have a WC_* window, so check to see if pchClass is also a
  101.       // predefined class.  If so, the high word is 0xFFFF.
  102.       //-------------------------------------------------------------------
  103.       if (HIUSHORT(pchClass)!=(USHORT)0xFFFF) {
  104.          return FALSE;
  105.       } /* endif */
  106.  
  107.       //-------------------------------------------------------------------
  108.       // Get the integer representation of the atom and compare it
  109.       // against the low word of pchClass, which is also the integer
  110.       // representation of the class it represents.
  111.       //-------------------------------------------------------------------
  112.       aAtom=WinFindAtom(WinQuerySystemAtomTable(),achClass);
  113.       if (aAtom==LOUSHORT(pchClass)) {
  114.          return TRUE;
  115.       } /* endif */
  116.    } else {
  117.       //-------------------------------------------------------------------
  118.       // We don't have a WC_* window, so check to see if pchClass is not
  119.       // also.  If it isn't, compare the classes using strcmp().
  120.       //-------------------------------------------------------------------
  121.       if (HIUSHORT(pchClass)==(USHORT)0xFFFF) {
  122.          return FALSE;
  123.       } /* endif */
  124.  
  125.       if (strcmp(achClass,pchClass)==0) {
  126.          return TRUE;
  127.       } /* endif */
  128.    } /* endif */
  129.  
  130.    return FALSE;
  131. }
  132.