home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / memsz331.zip / Source.zip / PROFILE.CPP < prev    next >
Text File  |  1996-10-30  |  29KB  |  632 lines

  1. /**************************************************************** PROFILE.CPP
  2.  *                                                                          *
  3.  *                     Profile (INI) File Object Class                      *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <string.h>
  12.  
  13. #include "Debug.h"
  14. #include "Config.h"
  15. #include "MemSize.h"
  16. #include "Support.h"
  17.  
  18. #include "Profile.h"
  19.  
  20.  
  21. /****************************************************************************
  22.  *                                                                          *
  23.  *                     Definitions & Declarations                           *
  24.  *                                                                          *
  25.  ****************************************************************************/
  26.  
  27.   // Constants
  28.  
  29. enum { ENTRY, ERRCODE } ;
  30.  
  31.  
  32.   // Type Definitions
  33.  
  34. typedef struct {
  35.   SHORT   id ;
  36.   HWND    hwndHelp ;
  37.   PBYTE   Path ;
  38.   int     PathSize ;
  39. } PROFILE_PARMS, *PPROFILE_PARMS ;
  40.  
  41.  
  42.   // Function Prototypes
  43.  
  44. static FNWP ProfileProcessor ;
  45.  
  46. static FNWP InitDlg ;
  47. static FNWP Command ;
  48. static FNWP OK ;
  49. static FNWP Cancel ;
  50.  
  51.  
  52. /****************************************************************************
  53.  *                                                                          *
  54.  *      Profile Class Constructor                                           *
  55.  *                                                                          *
  56.  ****************************************************************************/
  57.  
  58. Profile::Profile
  59. (
  60.   PSZ     name,
  61.   HAB     Anchor,
  62.   HMODULE Library,
  63.   int     DialogID,
  64.   HWND    HelpInstance,
  65.   BOOL    ResetFlag
  66. ) {
  67.  
  68.   /**************************************************************************
  69.    * Save the names.                                                        *
  70.    **************************************************************************/
  71.  
  72.    Name = new BYTE [ strlen(PCHAR(name)) + 1 ] ;
  73.    strcpy ( PCHAR(Name), PCHAR(name) ) ;
  74.  
  75.   /**************************************************************************
  76.    * If resetting the profile, clear the system profile information now.    *
  77.    **************************************************************************/
  78.  
  79.    if ( ResetFlag ) {
  80.       PrfWriteProfileData ( HINI_USERPROFILE, Name, PSZ(NULL), PSZ(NULL), 0 ) ;
  81.    }
  82.  
  83.   /**************************************************************************
  84.    * Query the system INI for the profile file's path.                      *
  85.    **************************************************************************/
  86.  
  87.    PSZ ProfilePath = PSZ(NULL) ;
  88.    ULONG Size ;
  89.  
  90.    if ( PrfQueryProfileSize ( HINI_USERPROFILE, Name, PSZ("INIPATH"), &Size ) ) {
  91.  
  92.       // The info exists.  Fetch it.
  93.       ProfilePath = new BYTE [ Size ] ;
  94.       PrfQueryProfileData ( HINI_USERPROFILE, Name,
  95.          PSZ("INIPATH"), ProfilePath, &Size ) ;
  96.  
  97.       // Build the profile file name.
  98.       BYTE FullPath [_MAX_PATH] ;
  99.       strcpy ( PCHAR(FullPath), PCHAR(ProfilePath) ) ;
  100.       strcat ( PCHAR(FullPath), "\\" ) ;
  101.       strcat ( PCHAR(FullPath), PCHAR(Name) ) ;
  102.       strcat ( PCHAR(FullPath), ".INI" ) ;
  103.  
  104.       // Clean the name up and expand it to a full path.
  105.       BYTE Path [256] ;
  106.       DosQueryPathInfo ( FullPath, FIL_QUERYFULLNAME, Path, sizeof(Path) ) ;
  107.  
  108.       // Does the file exist?  If not, discard the name.
  109.       FILESTATUS3 Status ;
  110.       if ( DosQueryPathInfo ( Path, FIL_STANDARD, &Status, sizeof(Status) ) ) {
  111.          delete [] ProfilePath ;
  112.          ProfilePath = PSZ(NULL) ;
  113.       }
  114.    }
  115.  
  116.   /**************************************************************************
  117.    * If the profile file couldn't be found, ask the user for a path.        *
  118.    **************************************************************************/
  119.  
  120.    if ( ProfilePath == NULL ) {
  121.       // Set the default path.
  122.       BYTE Path [256] ;
  123.       DosQueryPathInfo ( PSZ("."), FIL_QUERYFULLNAME, Path, sizeof(Path) ) ;
  124.  
  125.       // Call up the entry dialog.
  126.       PROFILE_PARMS Parms ;
  127.       Parms.id = short ( DialogID ) ;
  128.       Parms.hwndHelp = HelpInstance ;
  129.       Parms.Path = Path ;
  130.       Parms.PathSize = sizeof(Path) ;
  131.       if ( WinDlgBox ( HWND_DESKTOP, HWND_DESKTOP, PFNWP(ProfileProcessor), Library, DialogID, &Parms ) ) {
  132.          // If OK, save the approved path in the system profile.
  133.          ProfilePath = new BYTE [ strlen(PCHAR(Path)) + 1 ] ;
  134.          strcpy ( PCHAR(ProfilePath), PCHAR(Path) ) ;
  135.  
  136.          PrfWriteProfileData ( HINI_USERPROFILE, Name, PSZ("INIPATH"),
  137.             ProfilePath, strlen(PCHAR(ProfilePath))+1 ) ;
  138.       }
  139.    }
  140.  
  141.   /**************************************************************************
  142.    * Reset profile handle.  If the path could be determined . . .           *
  143.    **************************************************************************/
  144.  
  145.    Handle = 0 ;
  146.  
  147.    if ( ProfilePath ) {
  148.  
  149.      /***********************************************************************
  150.       * Build the full profile file name.                                   *
  151.       ***********************************************************************/
  152.  
  153.       BYTE ProfileName [_MAX_PATH] ;
  154.       strcpy ( PCHAR(ProfileName), PCHAR(ProfilePath) ) ;
  155.       strcat ( PCHAR(ProfileName), "\\"  ) ;
  156.       strcat ( PCHAR(ProfileName), PCHAR(Name) ) ;
  157.       strcat ( PCHAR(ProfileName), ".INI" ) ;
  158.  
  159.      /***********************************************************************
  160.       * Release the memory previously allocated to store the path.          *
  161.       ***********************************************************************/
  162.  
  163.       if ( ProfilePath ) {
  164.          delete [] ProfilePath ;
  165.       }
  166.  
  167.      /***********************************************************************
  168.       * Open/Create the profile file and return the resultant handle.       *
  169.       ***********************************************************************/
  170.  
  171.       Handle = PrfOpenProfile ( Anchor, ProfileName ) ;
  172.  
  173.      /***********************************************************************
  174.       * If resetting, then clean this profile out.                          *
  175.       ***********************************************************************/
  176.  
  177.       if ( ResetFlag ) {
  178.          PrfWriteProfileData ( Handle, Name, 0, 0, 0 ) ;
  179.       }
  180.    }
  181. }
  182.  
  183. /****************************************************************************
  184.  *                                                                          *
  185.  *      Profile Class Destructor                                            *
  186.  *                                                                          *
  187.  ****************************************************************************/
  188.  
  189. Profile::~Profile ( ) {
  190.  
  191.  /***************************************************************************
  192.   * Release allocated memory.                                               *
  193.   ***************************************************************************/
  194.  
  195.   delete [] Name ;
  196.  
  197.  /***************************************************************************
  198.   * Close the profile.                                                      *
  199.   ***************************************************************************/
  200.  
  201.   if ( Handle )
  202.      PrfCloseProfile ( Handle ) ;
  203. }
  204.  
  205. /****************************************************************************
  206.  *                                                                          *
  207.  *      Dialog Message Processor                                            *
  208.  *                                                                          *
  209.  ****************************************************************************/
  210.  
  211. extern MRESULT EXPENTRY ProfileProcessor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  212.  
  213.  /***************************************************************************
  214.   * Dispatch the message according to the method table and return the       *
  215.   *   result.  Any messages not defined above get handled by the system     *
  216.   *   default dialog processor.                                             *
  217.   ***************************************************************************/
  218.  
  219.   static METHOD Methods [] = {
  220.     { WM_INITDLG, InitDlg },
  221.     { WM_COMMAND, Command }
  222.   } ;
  223.  
  224.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  225. }
  226.  
  227. /****************************************************************************
  228.  *                                                                          *
  229.  *      Initialize Dialog                                                   *
  230.  *                                                                          *
  231.  ****************************************************************************/
  232.  
  233. static MRESULT APIENTRY InitDlg ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  234.  
  235.  /***************************************************************************
  236.   * Get parameters from initialization message.                             *
  237.   ***************************************************************************/
  238.  
  239.   PPROFILE_PARMS Parms = (PPROFILE_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  240.  
  241.   WinSetWindowPtr ( hwnd, QWL_USER, Parms ) ;
  242.  
  243.  /***************************************************************************
  244.   * Set the dialog help instance.                                           *
  245.   ***************************************************************************/
  246.  
  247.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  248.   if ( Parms->hwndHelp ) {
  249.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  250.   }
  251.  
  252.  /***************************************************************************
  253.   * Set the entry field contents.                                           *
  254.   ***************************************************************************/
  255.  
  256.   WinSetDlgItemText ( hwnd, Parms->id+ENTRY, Parms->Path ) ;
  257.  
  258.  /***************************************************************************
  259.   * Return no error.                                                        *
  260.   ***************************************************************************/
  261.  
  262.   return ( MRFROMSHORT ( FALSE ) ) ;
  263. }
  264.  
  265. /****************************************************************************
  266.  *                                                                          *
  267.  *      Process commands received by the dialog.                            *
  268.  *                                                                          *
  269.  ****************************************************************************/
  270.  
  271. static MRESULT APIENTRY Command ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  272.  
  273.  /***************************************************************************
  274.   * Dispatch the message without a default message processor.               *
  275.   ***************************************************************************/
  276.  
  277.   static METHOD Methods [] = {
  278.     { DID_OK,     OK     },
  279.     { DID_CANCEL, Cancel },
  280.   } ;
  281.  
  282.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), 0 ) ) ;
  283. }
  284.  
  285. /****************************************************************************
  286.  *                                                                          *
  287.  *      Process the dialog's OK button being pressed.                       *
  288.  *                                                                          *
  289.  ****************************************************************************/
  290.  
  291. static MRESULT APIENTRY OK ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  292.  
  293.  /***************************************************************************
  294.   * Find the instance data.                                                 *
  295.   ***************************************************************************/
  296.  
  297.   PPROFILE_PARMS Parms = PPROFILE_PARMS ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  298.  
  299.  /***************************************************************************
  300.   * Verify the entered path.                                                *
  301.   ***************************************************************************/
  302.  
  303.   BYTE Name [256] ;
  304.   WinQueryDlgItemText ( hwnd, Parms->id+ENTRY, sizeof(Name), Name ) ;
  305.  
  306.   BYTE FullPath [256] ;
  307.   if ( DosQueryPathInfo ( Name, FIL_QUERYFULLNAME, FullPath, sizeof(FullPath) ) ) {
  308.     PSZ Message = PSZ ( "ERROR: Not a valid path." ) ;
  309.     WinSetDlgItemText ( hwnd, Parms->id+ERRCODE, Message ) ;
  310.     WinAlarm ( HWND_DESKTOP, WA_ERROR ) ;
  311.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, Parms->id+ENTRY ) ) ;
  312.     return ( 0 ) ;
  313.   }
  314.  
  315.   FILESTATUS3 Status ;
  316.   if ( DosQueryPathInfo ( FullPath, FIL_STANDARD, &Status, sizeof(Status) ) ) {
  317.     PSZ Message = PSZ ( "ERROR: Path does not exist." ) ;
  318.     WinSetDlgItemText ( hwnd, Parms->id+ERRCODE, Message ) ;
  319.     WinAlarm ( HWND_DESKTOP, WA_ERROR ) ;
  320.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, Parms->id+ENTRY ) ) ;
  321.     return ( 0 ) ;
  322.   }
  323.  
  324.   if ( ! ( Status.attrFile & FILE_DIRECTORY ) ) {
  325.     PSZ Message = PSZ ( "ERROR: Specified path is not a directory." ) ;
  326.     WinSetDlgItemText ( hwnd, Parms->id+ERRCODE, Message ) ;
  327.     WinAlarm ( HWND_DESKTOP, WA_ERROR ) ;
  328.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, Parms->id+ENTRY ) ) ;
  329.     return ( 0 ) ;
  330.   }
  331.  
  332.  /***************************************************************************
  333.   * Return the full path to the caller.                                     *
  334.   ***************************************************************************/
  335.  
  336.   strncpy ( PCHAR(Parms->Path), PCHAR(FullPath), Parms->PathSize ) ;
  337.  
  338.  /***************************************************************************
  339.   * Dismiss the dialog with a TRUE status.                                  *
  340.   ***************************************************************************/
  341.  
  342.   WinDismissDlg ( hwnd, TRUE ) ;
  343.  
  344.   return ( 0 ) ;
  345. }
  346.  
  347. /****************************************************************************
  348.  *                                                                          *
  349.  *      Process the dialog's being cancelled.                               *
  350.  *                                                                          *
  351.  ****************************************************************************/
  352.  
  353. static MRESULT APIENTRY Cancel ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  354.  
  355.  /***************************************************************************
  356.   * Dismiss the dialog with a TRUE status.                                  *
  357.   ***************************************************************************/
  358.  
  359.   WinDismissDlg ( hwnd, FALSE ) ;
  360.  
  361.   return ( 0 ) ;
  362. }
  363.  
  364.  
  365. /****************************************************************************
  366.  *                                                                          *
  367.  *                        Get Basic INI Information                         *
  368.  *                                                                          *
  369.  ****************************************************************************/
  370.  
  371. #define OFF(type, var)    ((int) &((*(type *) 0).var))
  372. #define SIZE(type, var)   sizeof((*(type *) 0).var)
  373.  
  374. struct {
  375.    char *Name ;
  376.    int Offset ;
  377.    int Size ;
  378. } ProfileItems [] = {
  379.  
  380.    { "AnchorCorner",        OFF(INIDATA,AnchorCorner),          SIZE(INIDATA,AnchorCorner)          },
  381.    { "fAnchorCorner",       OFF(INIDATA,AnchorCorner),          SIZE(INIDATA,fAnchorCorner)         },
  382.    { "Animate",             OFF(INIDATA,Animate),               SIZE(INIDATA,Animate)               },
  383.    { "fAnimate",            OFF(INIDATA,fAnimate),              SIZE(INIDATA,fAnimate)              },
  384.    { "BackgroundColor",     OFF(INIDATA,BackColor),             SIZE(INIDATA,BackColor)             },
  385.    { "fBackgroundColor",    OFF(INIDATA,fBackColor),            SIZE(INIDATA,fBackColor)            },
  386.    { "Chime",               OFF(INIDATA,Chime),                 SIZE(INIDATA,Chime)                 },
  387.    { "fChime",              OFF(INIDATA,fChime),                SIZE(INIDATA,fChime)                },
  388.    { "ErrorBackground",     OFF(INIDATA,ErrorBackground),       SIZE(INIDATA,ErrorBackground)       },
  389.    { "fErrorBackground",    OFF(INIDATA,fErrorBackground),      SIZE(INIDATA,fErrorBackground)      },
  390.    { "ErrorForeground",     OFF(INIDATA,ErrorForeground),       SIZE(INIDATA,ErrorForeground)       },
  391.    { "fErrorForeground",    OFF(INIDATA,fErrorForeground),      SIZE(INIDATA,fErrorForeground)      },
  392.    { "Float",               OFF(INIDATA,Float),                 SIZE(INIDATA,Float)                 },
  393.    { "fFloat",              OFF(INIDATA,fFloat),                SIZE(INIDATA,fFloat)                },
  394.    { "FontNameSize",        OFF(INIDATA,FontNameSize),          SIZE(INIDATA,FontNameSize)          },
  395.    { "fFontNameSize",       OFF(INIDATA,fFontNameSize),         SIZE(INIDATA,fFontNameSize)         },
  396.    { "ForegroundColor",     OFF(INIDATA,TextColor),             SIZE(INIDATA,TextColor)             },
  397.    { "fForegroundColor",    OFF(INIDATA,fTextColor),            SIZE(INIDATA,fTextColor)            },
  398.    { "HideControls",        OFF(INIDATA,HideControls),          SIZE(INIDATA,HideControls)          },
  399.    { "fHideControls",       OFF(INIDATA,fHideControls),         SIZE(INIDATA,fHideControls)         },
  400.    { "Hour24",              OFF(INIDATA,Hour24),                SIZE(INIDATA,Hour24)                },
  401.    { "fHour24",             OFF(INIDATA,fHour24),               SIZE(INIDATA,fHour24)               },
  402.    { "MonitorPriority",     OFF(INIDATA,MonitorPriority),       SIZE(INIDATA,MonitorPriority)       },
  403.    { "fMonitorPriority",    OFF(INIDATA,fMonitorPriority),      SIZE(INIDATA,fMonitorPriority)      },
  404.    { "ShowDiskLabels",      OFF(INIDATA,ShowDiskLabels),        SIZE(INIDATA,ShowDiskLabels),       },
  405.    { "fShowDiskLabels",     OFF(INIDATA,fShowDiskLabels),       SIZE(INIDATA,fShowDiskLabels),      },
  406.    { "ShowFileSystemNames", OFF(INIDATA,ShowFileSystemNames),   SIZE(INIDATA,ShowFileSystemNames)   },
  407.    { "fShowFileSystemNames",OFF(INIDATA,fShowFileSystemNames),  SIZE(INIDATA,fShowFileSystemNames)  },
  408.    { "ShowRemoteDrives",    OFF(INIDATA,ShowRemoteDrives),      SIZE(INIDATA,ShowRemoteDrives)      },
  409.    { "fShowRemoteDrives",   OFF(INIDATA,fShowRemoteDrives),     SIZE(INIDATA,fShowRemoteDrives)     },
  410.    { "ShowSeconds",         OFF(INIDATA,ShowSeconds),           SIZE(INIDATA,ShowSeconds)           },
  411.    { "fShowSeconds",        OFF(INIDATA,fShowSeconds),          SIZE(INIDATA,fShowSeconds)          },
  412.    { "ShowK",               OFF(INIDATA,ShowK),                 SIZE(INIDATA,ShowK)                 },
  413.    { "fShowK",              OFF(INIDATA,fShowK),                SIZE(INIDATA,fShowK)                },
  414.    { "ShowM",               OFF(INIDATA,ShowM),                 SIZE(INIDATA,ShowM)                 },
  415.    { "fShowM",              OFF(INIDATA,fShowM),                SIZE(INIDATA,fShowM)                },
  416.    { "ShowTrueK",           OFF(INIDATA,ShowTrueK),             SIZE(INIDATA,ShowTrueK)             },
  417.    { "fShowTrueK",          OFF(INIDATA,fShowTrueK),            SIZE(INIDATA,fShowTrueK)            },
  418.    { "TableFormat",         OFF(INIDATA,TableFormat),           SIZE(INIDATA,TableFormat)           },
  419.    { "fTableFormat",        OFF(INIDATA,fTableFormat),          SIZE(INIDATA,fTableFormat)          },
  420.    { "TimerInterval",       OFF(INIDATA,TimerInterval),         SIZE(INIDATA,TimerInterval)         },
  421.    { "fTimerInterval",      OFF(INIDATA,fTimerInterval),        SIZE(INIDATA,fTimerInterval)        },
  422.    { "WarningBackground",   OFF(INIDATA,WarningBackground),     SIZE(INIDATA,WarningBackground)     },
  423.    { "fWarningBackground",  OFF(INIDATA,fWarningBackground),    SIZE(INIDATA,fWarningBackground)    },
  424.    { "WarningForeground",   OFF(INIDATA,WarningForeground),     SIZE(INIDATA,WarningForeground)     },
  425.    { "fWarningForeground",  OFF(INIDATA,fWarningForeground),    SIZE(INIDATA,fWarningForeground)    },
  426. } ;
  427.  
  428. extern int GetIniData ( HINI IniHandle, PINIDATA IniData ) {
  429.  
  430.  /***************************************************************************
  431.   * Get the window's current size and position.                             *
  432.   ***************************************************************************/
  433.  
  434.   ULONG Size ;
  435.   memset ( &IniData->Position, 0, sizeof(IniData->Position) ) ;
  436.   IniData->fPosition = FALSE ;
  437.   if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"), &Size ) 
  438.      AND ( Size == sizeof(IniData->Position) )
  439.      AND PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"), &IniData->Position, &Size ) ) {
  440.  
  441.      IniData->fPosition = TRUE ;
  442.  
  443.   // If unsuccessful, clear the position and anchor corner data, if present.
  444.   } else {
  445.      PrfWriteProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"), 0, 0 ) ;
  446.      PrfWriteProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("AnchorCorner"), 0, 0 ) ;
  447.      PrfWriteProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("fAnchorCorner"), 0, 0 ) ;
  448.  
  449.   } /* endif */
  450.  
  451.  /***************************************************************************
  452.   * If unable to get position, and profile was in system area, then         *
  453.   *   return TRUE, indicating profile fetch error.                          *
  454.   ***************************************************************************/
  455.  
  456.   if ( NOT IniData->fPosition ) 
  457.      if ( IniHandle == HINI_USERPROFILE ) 
  458.         return ( 1 ) ;
  459.  
  460.  /***************************************************************************
  461.   * Get country information.                                                *
  462.   ***************************************************************************/
  463.  
  464.   COUNTRYCODE CountryCode = { 0, 0 } ;
  465.   ULONG Count ;
  466.   ULONG Status = DosGetCtryInfo ( sizeof(IniData->CountryInfo), &CountryCode,
  467.     &IniData->CountryInfo, &Count ) ;
  468.   if ( Status ) {
  469.     IniData->CountryInfo.fsDateFmt = DATEFMT_MM_DD_YY ;
  470.     IniData->CountryInfo.fsTimeFmt = 0 ;
  471.     IniData->CountryInfo.szDateSeparator[0] = '/' ;
  472.     IniData->CountryInfo.szDateSeparator[1] = 0 ;
  473.     IniData->CountryInfo.szTimeSeparator[0] = ':' ;
  474.     IniData->CountryInfo.szTimeSeparator[1] = 0 ;
  475.     IniData->CountryInfo.szThousandsSeparator[0] = ',' ;
  476.     IniData->CountryInfo.szThousandsSeparator[1] = 0 ;
  477.   }
  478.  
  479.   char Text [10] ;
  480.   Size = 10 ;
  481.   if ( PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("iDate"), Text, &Size ) )
  482.      IniData->CountryInfo.fsDateFmt = atoi ( Text ) ;
  483.  
  484.   Size = 10 ;
  485.   if ( PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("iTime"), Text, &Size ) )
  486.      IniData->CountryInfo.fsTimeFmt = UCHAR ( atoi ( Text ) ) ;
  487.  
  488.   Size = 10 ;
  489.   if ( PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("iCountry"), Text, &Size ) )
  490.      IniData->idCountry = atoi ( Text ) ;
  491.  
  492.   Size = 2 ;
  493.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("sDate"), IniData->CountryInfo.szDateSeparator, &Size ) ;
  494.  
  495.   Size = 2 ;
  496.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("sTime"), IniData->CountryInfo.szTimeSeparator, &Size ) ;
  497.  
  498.   Size = 8 ;
  499.   strcpy ( IniData->szAm, "am" ) ;
  500.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("s1159"), IniData->szAm, &Size ) ;
  501.  
  502.   Size = 8 ;
  503.   strcpy ( IniData->szPm, "pm" ) ;
  504.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("s2359"), IniData->szPm, &Size ) ;
  505.  
  506.   Size = 2 ;
  507.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("sThousand"), IniData->CountryInfo.szThousandsSeparator, &Size ) ;
  508.  
  509.  /***************************************************************************
  510.   * Set the default profile.                                                *
  511.   ***************************************************************************/
  512.  
  513.   IniData->AnchorCorner = CORNER_BL ;
  514.   IniData->fAnchorCorner = FALSE ;
  515.  
  516.   IniData->Animate = FALSE ;
  517.   IniData->fAnimate = FALSE ;
  518.  
  519.   IniData->BackColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_WINDOW, 0 ) ;
  520.   IniData->fBackColor = FALSE ;
  521.  
  522.   IniData->Chime = FALSE ;
  523.   IniData->fChime = FALSE ;
  524.  
  525.   IniData->ErrorBackground = 0xFF0000 ;
  526.   IniData->fErrorBackground = FALSE ;
  527.  
  528.   IniData->ErrorForeground = 0xFFFFFF ;
  529.   IniData->fErrorForeground = FALSE ;
  530.  
  531.   IniData->Float = FALSE ;
  532.   IniData->fFloat = FALSE ;
  533.  
  534.   strcpy ( PCHAR(IniData->FontNameSize), "" ) ;
  535.   IniData->fFontNameSize = FALSE ;
  536.  
  537.   IniData->HideControls = FALSE ;
  538.   IniData->fHideControls = FALSE ;
  539.  
  540.   IniData->Hour24 = IniData->CountryInfo.fsTimeFmt ;
  541.   IniData->fHour24 = FALSE ;
  542.  
  543.   IniData->MonitorPriority = PRTYD_MAXIMUM ;
  544.   IniData->fMonitorPriority = FALSE ;
  545.  
  546.   IniData->ShowDiskLabels = TRUE ;
  547.   IniData->fShowDiskLabels = FALSE ;
  548.  
  549.   IniData->ShowFileSystemNames = TRUE ;
  550.   IniData->fShowFileSystemNames = FALSE ;
  551.  
  552.   IniData->ShowRemoteDrives = TRUE ;
  553.   IniData->fShowRemoteDrives = FALSE ;
  554.  
  555.   IniData->ShowSeconds = FALSE ;
  556.   IniData->fShowSeconds = FALSE ;
  557.  
  558.   IniData->ShowK = SHOWK_ABOVE512 ;
  559.   IniData->fShowK = FALSE ;
  560.  
  561.   IniData->ShowTrueK = TRUE ;
  562.   IniData->fShowTrueK = FALSE ;
  563.  
  564.   IniData->ShowM = TRUE ;
  565.   IniData->fShowM = FALSE ;
  566.  
  567.   IniData->TextColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_OUTPUTTEXT, 0 ) ;
  568.   IniData->fTextColor = FALSE ;
  569.  
  570.   IniData->TableFormat = FALSE ;
  571.   IniData->fTableFormat = FALSE ;
  572.  
  573.   IniData->TimerInterval = 1000 ;
  574.   IniData->fTimerInterval = FALSE ;
  575.  
  576.   IniData->WarningBackground = 0xFFFF00 ;
  577.   IniData->fWarningBackground = FALSE ;
  578.  
  579.   IniData->WarningForeground = 0x000000 ;
  580.   IniData->fWarningForeground = FALSE ;
  581.  
  582.  /***************************************************************************
  583.   * Go get the saved values for the above, if they are to be found.         *
  584.   ***************************************************************************/
  585.  
  586.   for ( int i=0; i<sizeof(ProfileItems)/sizeof(ProfileItems[0]); i++ ) {
  587.      if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ(ProfileItems[i].Name), &Size )
  588.         AND ( Size == ProfileItems[i].Size )
  589.         AND PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ(ProfileItems[i].Name), PBYTE(IniData)+ProfileItems[i].Offset, &Size ) ) {
  590.  
  591.      } /* endif */
  592.   } /* endif */
  593.  
  594.   if ( IniData->FontNameSize[0] )
  595.      IniData->fFontNameSize = TRUE ;
  596.  
  597.   return ( 0 ) ;
  598. }
  599.  
  600. /****************************************************************************
  601.  *                                                                          *
  602.  *                           Save INI Information                           *
  603.  *                                                                          *
  604.  ****************************************************************************/
  605.  
  606. extern void PutIniData ( HINI IniHandle, PINIDATA IniData ) {
  607.  
  608.   /**************************************************************************
  609.    * Save the window's current size and position.                           *
  610.    **************************************************************************/
  611.  
  612.    PrfWriteProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"),
  613.       &IniData->Position, sizeof(IniData->Position) ) ;
  614.  
  615.   /**************************************************************************
  616.    * Save the new profile.                                                  *
  617.    **************************************************************************/
  618.  
  619.    for ( int i=0; i<sizeof(ProfileItems)/sizeof(ProfileItems[0]); i++ )
  620.       PrfWriteProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ(ProfileItems[i].Name),
  621.          ((PBYTE)IniData)+ProfileItems[i].Offset, ProfileItems[i].Size ) ;
  622.  
  623.   /**************************************************************************
  624.    * Save the item options.                                                 *
  625.    **************************************************************************/
  626.  
  627.    for ( i=0; i<IniData->ItemCount; i++ ) 
  628.       IniData->Items[i]->PutProfile ( IniHandle ) ;
  629.  
  630. }
  631.  
  632.