home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / iwftech.zip / samples / PeterPAM / PPCNR.C < prev    next >
Text File  |  1994-06-06  |  23KB  |  688 lines

  1. /****************************************************************************/ 
  2. /*                                                                          */ 
  3. /* PROGRAM NAME: PeterPAM                                                   */ 
  4. /*                                                                          */ 
  5. /* COPYRIGHT:                                                               */ 
  6. /* ----------                                                               */ 
  7. /* Copyright (C) International Business Machines Corp., 1991,1992,1993,1994 */ 
  8. /*                                                                          */ 
  9. /* DISCLAIMER OF WARRANTIES:                                                */ 
  10. /* -------------------------                                                */ 
  11. /* The following [enclosed] code is sample code created by IBM              */ 
  12. /* Corporation.  This sample code is not part of any standard IBM product   */ 
  13. /* and is provided to you solely for the purpose of assisting you in the    */ 
  14. /* development of your applications.  The code is provided "AS IS",         */ 
  15. /* without warranty of any kind.  IBM shall not be liable for any damages   */ 
  16. /* arising out of your use of the sample code, even if they have been       */ 
  17. /* advised of the possibility of such damages.                              */ 
  18. /*                                                                          */ 
  19. /* REVISION LEVEL: 2.1                                                      */ 
  20. /* -------------------                                                      */ 
  21. /*                                                                          */ 
  22. /* This program illustrates the chaining of PAMs.                           */ 
  23. /*                                                                          */ 
  24. /*                                                                          */ 
  25. /****************************************************************************/ 
  26. /*                                                                          */ 
  27. /* NOTES:                                                                   */ 
  28. /*                                                                          */ 
  29. /****************************************************************************/ 
  30.  
  31. #pragma strings(readonly)
  32.  
  33. #define INCL_WIN
  34. #define INCL_DOS                        /* Need DOS support           */
  35. #define INCL_DOSERRORS                  /* Get error codes            */
  36. #include <os2.h>
  37.  
  38. /***********************************************************************/
  39. /*                                                                     */
  40. /*                  Include the C library header files                 */
  41. /*                                                                     */
  42. /***********************************************************************/
  43. #include <string.h>
  44. #include <stdlib.h>
  45. #include <stddef.h>
  46. #include <stdio.h>
  47.  
  48. /* #include "wkfpam.h" */
  49. #include "peterpam.h"
  50. #include "ppcnr.h"
  51. #include "wkf.h"
  52.  
  53.  
  54.  
  55.  
  56. typedef struct _USERRECORD
  57. {
  58.    MINIRECORDCORE MiniRecordCore;       /* Must be the first element */
  59.    HPOINTER       hptrIcon;
  60.    PSZ            pszExt;
  61.    PSZ            pszIconFilename;
  62. } USERRECORD;
  63.  
  64.  
  65. #define CNR_TITLE_ICON      "Icon"
  66. #define CNR_TITLE_EXT       "Extension"
  67. #define CNR_TITLE_FILENAME  "Icon Filename"
  68.  
  69.  
  70. /*
  71. ** Function prototypes
  72. */
  73. extern MRESULT EXPENTRY DlgProc( HWND hwndDlg,
  74.                                  ULONG msg,
  75.                                  MPARAM mp1,
  76.                                  MPARAM mp2 );
  77.  
  78.  
  79. static BOOL InsertRecords( HWND  hwndDlg,
  80.                            ULONG ulNumEntries, 
  81.                            EXTFILEICON *aExtFileIcon );
  82.  
  83. static BOOL InitContainer( HWND hwndDlg );
  84.  
  85. static BOOL WriteINI( PPHAM *pHAM, BOOL fDeleteLastRecord );
  86.  
  87.  
  88.  
  89. extern APIRET APIENTRY Settings( PPHAM  *pHAM,
  90.                                  PSZ     pszProjectFile,
  91.                                  HWND    hwndParent,
  92.                                  HWND    hwndOwner,
  93.                                  ULONG   cbMessage,
  94.                                  PSZ     pszMessage )
  95. {
  96.    HMODULE hmod;
  97.  
  98.    DosQueryModuleHandle( PETERPAM_DLLNAME,
  99.                         &hmod );
  100.  
  101.    WinDlgBox( hwndParent, 
  102.               hwndOwner,  
  103.              &DlgProc,
  104.               hmod,
  105.               IDD_PETERPAM,
  106.               pHAM );
  107.  
  108.    return( NO_ERROR );
  109. }
  110.  
  111.  
  112. extern MRESULT EXPENTRY DlgProc( HWND hwndDlg,
  113.                                  ULONG msg,
  114.                                  MPARAM mp1,
  115.                                  MPARAM mp2 )
  116. {
  117.    switch (msg)
  118.    {
  119.       case WM_INITDLG:
  120.       {
  121.          PPHAM   *pHAM;
  122.  
  123.          pHAM = (PPHAM*)mp2;
  124.          WinSetWindowPtr( hwndDlg, QWL_USER, PVOIDFROMMP( pHAM ));
  125.  
  126.          /*
  127.          ** Insert the chained PAM DLL name into the entry field
  128.          */
  129.          WinSendMsg( WinWindowFromID( hwndDlg, IDD_CHAINED ),
  130.                      EM_SETTEXTLIMIT,
  131.                      MPFROMSHORT( CCHMAXPATH ),
  132.                      MPFROMP( NULL ) );
  133.  
  134.          WinSetWindowText( WinWindowFromID( hwndDlg, IDD_CHAINED ), 
  135.                            pHAM->BPAM.szDLLName );
  136.  
  137.  
  138.          /*
  139.          ** Setup the container
  140.          */
  141.          InitContainer( hwndDlg );
  142.  
  143.          InsertRecords( hwndDlg, pHAM->ulNumEntries, pHAM->aExtFileIcon );
  144.  
  145.  
  146.          /*
  147.          ** Start ADD initially disabled, and delete dependent on any records existing
  148.          */
  149.          WinEnableWindow( WinWindowFromID( hwndDlg, 
  150.                                            IDD_ADD ),
  151.                           FALSE );
  152.  
  153.          if( pHAM->ulNumEntries )
  154.             /*
  155.             ** There are entries -- Enable DELETE
  156.             */
  157.             WinEnableWindow( WinWindowFromID( hwndDlg, 
  158.                                               IDD_DELETE ),
  159.                              TRUE );
  160.          else
  161.             /*
  162.             ** There are no entries -- disable DELETE
  163.             */
  164.             WinEnableWindow( WinWindowFromID( hwndDlg, 
  165.                                               IDD_DELETE ),
  166.                              FALSE );
  167.  
  168.  
  169.          return( MRFROMLONG( FALSE ));
  170.       }
  171.  
  172.  
  173.  
  174.       case WM_CONTROL:
  175.       {
  176.          switch( SHORT1FROMMP( mp1 ))
  177.          {
  178.             case IDD_FILENAME:
  179.             {
  180.                if( SHORT2FROMMP( mp1 ) == EN_CHANGE )
  181.                {
  182.                   /*
  183.                   ** Enable/Disable the add button, depending if the
  184.                   ** filename field has text in it
  185.                   */
  186.                   if (WinQueryWindowTextLength( WinWindowFromID( hwndDlg, 
  187.                                                                  IDD_FILENAME ) ) )
  188.                      /*
  189.                      ** There is text -- enable ADD
  190.                      */
  191.                      WinEnableWindow( WinWindowFromID( hwndDlg, 
  192.                                                        IDD_ADD ),
  193.                                       TRUE );
  194.                   else
  195.                      /*
  196.                      ** There is no text -- disable ADD
  197.                      */
  198.                      WinEnableWindow( WinWindowFromID( hwndDlg, 
  199.                                                        IDD_ADD ),
  200.                                       FALSE );
  201.                }
  202.             }
  203.             break;
  204.  
  205.             case IDD_CHAINED:
  206.             {
  207.                if( SHORT2FROMMP( mp1 ) == EN_KILLFOCUS )
  208.                {
  209.                   BPAM   NewPAM;
  210.                   PPHAM *pHAM;
  211.                   HINI   hINI;
  212.  
  213.                   pHAM = (PPHAM*)WinQueryWindowPtr( hwndDlg, QWL_USER );
  214.  
  215.                   /*
  216.                   ** Validate the Chained PAM information
  217.                   ** (Don't load ourselves as a chained PAM)
  218.                   */
  219.                   WinQueryWindowText( (HWND)mp2,
  220.                                       sizeof( NewPAM.szDLLName ),
  221.                                       NewPAM.szDLLName );
  222.  
  223.                   if( !stricmp( NewPAM.szDLLName, PETERPAM_DLLNAME ) ||
  224.                       LoadChainedPAM( &NewPAM ) )
  225.                   {
  226.                      /*
  227.                      ** Couldn't load the DLL - reset to BPAM
  228.                      */
  229.                      WinSetWindowText( (HWND)mp2, DEFAULT_DLLNAME );
  230.                      strcpy( NewPAM.szDLLName, DEFAULT_DLLNAME );
  231.                      WinAlarm( HWND_DESKTOP, WA_ERROR );
  232.  
  233.                      if ( NewPAM.hmod )
  234.                         DosFreeModule( NewPAM.hmod );
  235.                   }
  236.                   else
  237.                   {
  238.                      DosFreeModule( pHAM->BPAM.hmod );
  239.                      memcpy( &pHAM->BPAM, &NewPAM, sizeof( BPAM ) );
  240.  
  241.                      WinAlarm( HWND_DESKTOP, WA_NOTE );
  242.                   }
  243.  
  244.                   /*
  245.                   ** Update the INI file with the new DLL name
  246.                   */
  247.                   hINI = PrfOpenProfile( WinQueryAnchorBlock( HWND_DESKTOP ),
  248.                                          pHAM->szProjectFilename );
  249.             
  250.                   if( hINI )
  251.                   {
  252.                      PrfWriteProfileData( hINI,
  253.                                           PRF_APPNAME,
  254.                                           PRF_KEYNAME_CHAINED,
  255.                                           NewPAM.szDLLName,
  256.                                           strlen( NewPAM.szDLLName ) +1 );   /* +1 == null */
  257.             
  258.                      PrfCloseProfile( hINI );    /* All other data is saved in the USER ini file */
  259.                   }
  260.                   else
  261.                      WinAlarm( HWND_DESKTOP, WA_ERROR );
  262.  
  263.                }
  264.             }
  265.             break;
  266.  
  267.          } /* endswitch */
  268.       }
  269.       break;
  270.  
  271.  
  272.  
  273.  
  274.       case WM_COMMAND:
  275.       {
  276.          switch( SHORT1FROMMP( mp1 ))
  277.          {
  278.             case IDD_ADD:
  279.             {
  280.                PPHAM   *pHAM;
  281.                ULONG    ulNew;
  282.                CHAR     Buffer[ CCHMAXPATH ];
  283.  
  284.                pHAM = WinQueryWindowPtr( hwndDlg, QWL_USER );
  285.  
  286.                ulNew = pHAM->ulNumEntries++;
  287.  
  288.                pHAM->aExtFileIcon = realloc( pHAM->aExtFileIcon, pHAM->ulNumEntries * sizeof( EXTFILEICON ) );
  289.  
  290.                WinQueryWindowText( WinWindowFromID( hwndDlg, IDD_EXT ),
  291.                                    sizeof( Buffer ),
  292.                                    Buffer );
  293.  
  294.                pHAM->aExtFileIcon[ulNew].pszExt = strdup( Buffer );
  295.  
  296.                WinQueryWindowText( WinWindowFromID( hwndDlg, IDD_FILENAME ),
  297.                                    sizeof( Buffer ),
  298.                                    Buffer );
  299.  
  300.                pHAM->aExtFileIcon[ulNew].pszIconFilename = strdup( Buffer );
  301.  
  302.                /*
  303.                ** Load the new icon
  304.                */
  305.                pHAM->aExtFileIcon[ulNew].hptrIcon = WinLoadFileIcon( pHAM->aExtFileIcon[ulNew].pszIconFilename, 
  306.                                                                      FALSE );
  307.  
  308.                /*
  309.                ** Now update the INI file
  310.                */
  311.                if( !WriteINI( pHAM,
  312.                               FALSE ) )   /* Don't delete any records */
  313.                   WinAlarm( HWND_DESKTOP, WA_ERROR );
  314.  
  315.  
  316.                InsertRecords( hwndDlg, 1, &pHAM->aExtFileIcon[ulNew] );
  317.  
  318.  
  319.                /*
  320.                ** Finally enable the delete button
  321.                */
  322.                WinEnableWindow( WinWindowFromID( hwndDlg, 
  323.                                                  IDD_DELETE ),
  324.                                 TRUE );
  325.  
  326.             }
  327.             break;
  328.  
  329.  
  330.  
  331.             case IDD_DELETE:
  332.             {
  333.                CHAR        szMsg[ 500 ];    /* Enough for a confirmation message */
  334.                HWND        hwndCnr;
  335.                PPHAM      *pHAM;
  336.                ULONG       ulDelete;
  337.                ULONG       i;
  338.                USERRECORD *pUserRecord;
  339.  
  340.                pHAM = WinQueryWindowPtr( hwndDlg, QWL_USER );
  341.                hwndCnr = WinWindowFromID( hwndDlg, IDD_CONTAINER );
  342.  
  343.                /*
  344.                ** Find which record has been selected
  345.                */
  346.                pUserRecord = (USERRECORD*)WinSendMsg( hwndCnr,
  347.                                                       CM_QUERYRECORDEMPHASIS,
  348.                                                       MPFROMP( CMA_FIRST ),
  349.                                                       MPFROMSHORT( CRA_CURSORED ) );
  350.  
  351.                if( pUserRecord == NULL )
  352.                   return( FALSE );
  353.                
  354.  
  355.                sprintf( szMsg,
  356.                         "Do you want to delete the association between *.%s and %s?",
  357.                         pUserRecord->pszExt,
  358.                         pUserRecord->pszIconFilename );
  359.  
  360.                if ( WinMessageBox( HWND_DESKTOP,
  361.                                    hwndDlg,
  362.                                    szMsg,
  363.                                    "WorkFrame/2 - PeterPAM",
  364.                                    0,
  365.                                    MB_YESNO | 
  366.                                       MB_QUERY | 
  367.                                       MB_APPLMODAL | 
  368.                                       MB_MOVEABLE
  369.                                  ) != MBID_YES )
  370.                   return( FALSE );
  371.                
  372.  
  373.                for (i = 0; i < pHAM->ulNumEntries; i++)
  374.                {
  375.                   if (!stricmp( pUserRecord->pszExt, 
  376.                                 pHAM->aExtFileIcon[i].pszExt ) &&
  377.                       !stricmp( pUserRecord->pszIconFilename,
  378.                                 pHAM->aExtFileIcon[i].pszIconFilename ) )
  379.                      /*
  380.                      ** Found the record to delete
  381.                      */
  382.                   {
  383.                      ulDelete = i;
  384.                      break;
  385.                   }
  386.                } /* endfor */
  387.  
  388.  
  389.  
  390.                if( i == pHAM->ulNumEntries )
  391.                {
  392.                   /*
  393.                   ** Didn't find a match for some reason
  394.                   */
  395.                   WinAlarm( HWND_DESKTOP, WA_ERROR );
  396.                   return( FALSE );
  397.                }
  398.  
  399.  
  400.  
  401.                /*
  402.                ** Delete the record from the container
  403.                */
  404.                WinSendMsg( hwndCnr,
  405.                            CM_REMOVERECORD,
  406.                            MPFROMP( &pUserRecord ),
  407.                            MPFROM2SHORT( 1,           /* Delete 1 record */ 
  408.                                          CMA_FREE | CMA_INVALIDATE ) 
  409.                          );
  410.  
  411.  
  412.                /*
  413.                ** Free the data
  414.                */
  415.                free( pHAM->aExtFileIcon[ ulDelete ].pszExt );
  416.                free( pHAM->aExtFileIcon[ ulDelete ].pszIconFilename );
  417.  
  418.  
  419.                /*
  420.                ** Move the remaining entries down in the array
  421.                */
  422.                for (i = ulDelete+1; i < pHAM->ulNumEntries; i++)
  423.                {
  424.                   pHAM->aExtFileIcon[ i-1 ] = pHAM->aExtFileIcon[ i ];
  425.                } /* endfor */
  426.  
  427.                /*
  428.                ** ...and finally, shrink the array itself
  429.                */
  430.                pHAM->ulNumEntries--;
  431.  
  432.                pHAM->aExtFileIcon = realloc( pHAM->aExtFileIcon, 
  433.                                              pHAM->ulNumEntries * sizeof( EXTFILEICON ) );
  434.  
  435.                /*
  436.                ** Now update the INI file
  437.                */
  438.                if( !WriteINI( pHAM,
  439.                               TRUE ) )  /* Delete last record */
  440.                   WinAlarm( HWND_DESKTOP, WA_ERROR );
  441.  
  442.  
  443.                /*
  444.                ** optionally disable the delete button
  445.                */
  446.                if( !pHAM->ulNumEntries )
  447.                   WinEnableWindow( WinWindowFromID( hwndDlg, 
  448.                                                     IDD_DELETE ),
  449.                                    FALSE );
  450.  
  451.             }
  452.             break;
  453.  
  454.          } /* endswitch */ 
  455.  
  456.          return( FALSE );
  457.       }
  458.  
  459.    } /* endswitch */
  460.  
  461.    return( WinDefDlgProc( hwndDlg, msg, mp1, mp2 ));
  462. }
  463.  
  464.  
  465.  
  466.  
  467. static BOOL InsertRecords( HWND hwndDlg, ULONG ulNumEntries, EXTFILEICON *aExtFileIcon )
  468. {
  469.    HWND              hwndCnr;
  470.    RECORDINSERT      RecordInsert;
  471.    ULONG             i;
  472.    USERRECORD       *pFirstUserRecord;
  473.    USERRECORD       *pUserRecord;
  474.  
  475.  
  476.    hwndCnr = WinWindowFromID( hwndDlg, IDD_CONTAINER );
  477.  
  478.  
  479.    /*
  480.    ** Start to fill in the data
  481.    */
  482.    pFirstUserRecord =
  483.       pUserRecord = WinSendMsg( hwndCnr,
  484.                                 CM_ALLOCRECORD,
  485.                                 MPFROMLONG( sizeof( USERRECORD ) - sizeof( MINIRECORDCORE ) ),
  486.                                 MPFROMLONG( ulNumEntries ) );
  487.  
  488.  
  489.    for (i=0; i < ulNumEntries; i++)
  490.    {
  491.  
  492.       /*
  493.       ** These are required elements
  494.       */
  495.       pUserRecord->MiniRecordCore.cb           = sizeof( MINIRECORDCORE );
  496.       pUserRecord->MiniRecordCore.flRecordAttr = CRA_RECORDREADONLY;
  497.  
  498.       /*
  499.       ** Set the detail for each record
  500.       */
  501.       pUserRecord->hptrIcon         = aExtFileIcon[ i ].hptrIcon;
  502.       pUserRecord->pszExt           = aExtFileIcon[ i ].pszExt;
  503.       pUserRecord->pszIconFilename  = aExtFileIcon[ i ].pszIconFilename;
  504.  
  505.       pUserRecord = (USERRECORD*)pUserRecord->MiniRecordCore.preccNextRecord;
  506.  
  507.    } /* endfor */
  508.  
  509.  
  510.    RecordInsert.cb                = sizeof( RECORDINSERT );
  511.    RecordInsert.pRecordParent     = NULL;
  512.    RecordInsert.pRecordOrder      = (RECORDCORE*)CMA_END;
  513.    RecordInsert.zOrder            = CMA_TOP;
  514.    RecordInsert.cRecordsInsert    = ulNumEntries;
  515.    RecordInsert.fInvalidateRecord = TRUE;
  516.  
  517.    /*
  518.    ** Insert the records
  519.    */
  520.    WinSendMsg( hwndCnr,
  521.                CM_INSERTRECORD,
  522.                MPFROMP( pFirstUserRecord ),
  523.                MPFROMP( &RecordInsert ) );
  524.  
  525.  
  526.    return( TRUE );
  527. }
  528.  
  529.  
  530.  
  531. static BOOL InitContainer( HWND hwndDlg )
  532. {
  533.    CNRINFO           CnrInfo;
  534.    FIELDINFO        *pFieldInfo;
  535.    FIELDINFO        *pFirstFieldInfo;
  536.    FIELDINFOINSERT   FieldInfoInsert;
  537.    HWND              hwndCnr;
  538.  
  539.  
  540.    hwndCnr = WinWindowFromID( hwndDlg, IDD_CONTAINER );
  541.    /*
  542.    ** Setup the details view -- tell the
  543.    ** container what data to display, and where to get it
  544.    */
  545.  
  546.    FieldInfoInsert.cb = (sizeof(FIELDINFOINSERT));
  547.    FieldInfoInsert.pFieldInfoOrder = (FIELDINFO*)CMA_FIRST;
  548.    FieldInfoInsert.cFieldInfoInsert = 3;     /* 3 columns */
  549.    FieldInfoInsert.fInvalidateFieldInfo = TRUE;
  550.  
  551.    pFirstFieldInfo =
  552.       pFieldInfo = WinSendMsg( hwndCnr,
  553.                                CM_ALLOCDETAILFIELDINFO,
  554.                                MPFROMLONG( 3 ),  /* Number of columns */
  555.                                MPFROMP( NULL ) );
  556.  
  557.    /*
  558.    ** Now, indicate how to display each column
  559.    */
  560.  
  561.    /*
  562.    ** Column 1 - Extension
  563.    */
  564.    pFieldInfo->cb          = sizeof( FIELDINFO );
  565.    pFieldInfo->flData      = CFA_STRING |
  566.                                 CFA_SEPARATOR |
  567.                                 CFA_FIREADONLY;
  568.    pFieldInfo->flTitle     = CFA_FITITLEREADONLY;
  569.    pFieldInfo->pTitleData  = CNR_TITLE_EXT;
  570.    pFieldInfo->offStruct   = offsetof( USERRECORD, pszExt );
  571.    
  572.    /*
  573.    ** Column 2 - Icon
  574.    */
  575.    pFieldInfo = pFieldInfo->pNextFieldInfo;
  576.  
  577.    pFieldInfo->cb          = sizeof( FIELDINFO );
  578.    pFieldInfo->flData      = CFA_BITMAPORICON |
  579.                                 CFA_SEPARATOR;
  580.    pFieldInfo->flTitle     = CFA_FITITLEREADONLY;
  581.    pFieldInfo->pTitleData  = CNR_TITLE_ICON;
  582.    pFieldInfo->offStruct   = offsetof( USERRECORD, hptrIcon );
  583.  
  584.  
  585.  
  586.    /*
  587.    ** Column 3 - icon filename
  588.    */
  589.    pFieldInfo = pFieldInfo->pNextFieldInfo;
  590.  
  591.    pFieldInfo->cb          = sizeof( FIELDINFO );
  592.    pFieldInfo->flData      = CFA_STRING |
  593.                                 CFA_FIREADONLY;
  594.    pFieldInfo->flTitle     = CFA_FITITLEREADONLY;
  595.    pFieldInfo->pTitleData  = CNR_TITLE_FILENAME;
  596.    pFieldInfo->offStruct   = offsetof( USERRECORD, pszIconFilename );
  597.  
  598.    /*
  599.    ** ...and send the data to the container
  600.    */
  601.    WinSendMsg( hwndCnr,
  602.                CM_INSERTDETAILFIELDINFO,
  603.                MPFROMP( pFirstFieldInfo ),
  604.                MPFROMP( &FieldInfoInsert ) );
  605.  
  606.    /*
  607.    ** Finally, make sure the container is setup in detail view
  608.    */
  609.    CnrInfo.flWindowAttr = CV_DETAIL |
  610.                              CA_CONTAINERTITLE |
  611.                              CA_TITLESEPARATOR |
  612.                              CA_DETAILSVIEWTITLES;
  613.  
  614.    WinSendMsg( hwndCnr,
  615.                CM_SETCNRINFO,
  616.                MPFROMP( &CnrInfo ),
  617.                MPFROMLONG( CMA_FLWINDOWATTR ) );
  618.  
  619.  
  620.    return( TRUE );
  621.  
  622. }
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629. static BOOL WriteINI( PPHAM *pHAM, BOOL fDeleteLastRecord )
  630. {
  631.    ULONG i;
  632.    CHAR  Buffer[ CCHMAXPATH ];
  633.    BOOL  fOK;
  634.  
  635.    PrfWriteProfileData( HINI_USERPROFILE,
  636.                         PRF_APPNAME,
  637.                         PRF_KEYNAME_NUM,
  638.                        &pHAM->ulNumEntries,
  639.                         sizeof( pHAM->ulNumEntries ) );
  640.  
  641.  
  642.    for (i=0; i < pHAM->ulNumEntries; i++)
  643.    {
  644.       sprintf( Buffer, PRF_KEYNAME_EXT, i );
  645.  
  646.       fOK = PrfWriteProfileData( HINI_USERPROFILE,
  647.                                  PRF_APPNAME,
  648.                                  Buffer,
  649.                                  pHAM->aExtFileIcon[i].pszExt,
  650.                                  strlen( pHAM->aExtFileIcon[i].pszExt )+1 );   /* +1 == null */
  651.  
  652.       if( !fOK )
  653.          break;
  654.  
  655.       sprintf( Buffer, PRF_KEYNAME_ICON, i );
  656.  
  657.       fOK = PrfWriteProfileData( HINI_USERPROFILE,
  658.                                  PRF_APPNAME,
  659.                                  Buffer,
  660.                                  pHAM->aExtFileIcon[i].pszIconFilename,
  661.                                  strlen( pHAM->aExtFileIcon[i].pszIconFilename )+1 );  /* +1 == null */
  662.  
  663.    } /* endfor */
  664.  
  665.  
  666.    if (fDeleteLastRecord)
  667.    {
  668.       sprintf( Buffer, PRF_KEYNAME_EXT, i );
  669.  
  670.       PrfWriteProfileData( HINI_USERPROFILE,
  671.                            PRF_APPNAME,
  672.                            Buffer,
  673.                            NULL,
  674.                            0 );
  675.  
  676.  
  677.       sprintf( Buffer, PRF_KEYNAME_ICON, i );
  678.  
  679.       PrfWriteProfileData( HINI_USERPROFILE,
  680.                            PRF_APPNAME,
  681.                            Buffer,
  682.                            NULL,
  683.                            0 );
  684.    }
  685.  
  686.    return( fOK );
  687. }
  688.