home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / audio / midimon / prefer.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  3KB  |  81 lines

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (C) 1993 - 1997  Microsoft Corporation.  All Rights Reserved.
  9.  * 
  10.  **************************************************************************/
  11.  
  12. /*
  13.  * prefer.c - Routines to get and set user preferences.
  14.  */
  15.  
  16. #include <windows.h>
  17. #include <mmsystem.h>
  18. #include <stdio.h>
  19. #include "midimon.h"
  20. #include "prefer.h"
  21.  
  22. /* getPreferences - Reads .INI file and gets the setup preferences.
  23.  *      Currently, the only user preferences are window location and size.
  24.  *      If the .INI file does not exist, returns default values.
  25.  *
  26.  * Params:  lpPreferences - Points to a PREFERENCES data structure that
  27.  *              is filled with the retrieved user preferences.
  28.  *
  29.  * Return:  void
  30. */
  31. void getPreferences(LPPREFERENCES lpPreferences)
  32. {
  33.     lpPreferences->iInitialX = 
  34.         GetPrivateProfileInt(INI_DISPLAYWINDOW, INI_X, DEF_X, INI_FILENAME);
  35.  
  36.     lpPreferences->iInitialY = 
  37.         GetPrivateProfileInt(INI_DISPLAYWINDOW, INI_Y, DEF_Y, INI_FILENAME);
  38.  
  39.     lpPreferences->iInitialW = 
  40.         GetPrivateProfileInt(INI_DISPLAYWINDOW, INI_W, DEF_W, INI_FILENAME);
  41.  
  42.     lpPreferences->iInitialH = 
  43.         GetPrivateProfileInt(INI_DISPLAYWINDOW, INI_H, DEF_H, INI_FILENAME);
  44. }
  45.  
  46. /* setPreferences - Writes the .INI file with the given setup preferences.
  47.  *
  48.  * Params:  lpPreferences - Points to a PREFERENCES data structure containing
  49.  *              the user preferences.
  50.  *
  51.  * Return:  void
  52.  */
  53. void setPreferences(LPPREFERENCES lpPreferences)
  54. {
  55.     char szTempString[20];
  56.  
  57.     while (1) { // This now aborts after one error.
  58.         sprintf(szTempString, "%d", lpPreferences->iInitialX);
  59.         if(WritePrivateProfileString(INI_DISPLAYWINDOW, INI_X,
  60.                                   (LPSTR) szTempString, INI_FILENAME) == 0)
  61.             break;
  62.         
  63.         sprintf(szTempString, "%d", lpPreferences->iInitialY);
  64.         if(WritePrivateProfileString(INI_DISPLAYWINDOW, INI_Y,
  65.                                   (LPSTR) szTempString, INI_FILENAME) == 0)
  66.             break;
  67.         
  68.         sprintf(szTempString, "%d", lpPreferences->iInitialW);
  69.         if(WritePrivateProfileString(INI_DISPLAYWINDOW, INI_W,
  70.                                   (LPSTR) szTempString, INI_FILENAME) == 0)
  71.             break;
  72.         
  73.         sprintf(szTempString, "%d", lpPreferences->iInitialH);
  74.         if(WritePrivateProfileString(INI_DISPLAYWINDOW, INI_H,
  75.                                   (LPSTR) szTempString, INI_FILENAME) == 0)
  76.             break;
  77.         return;
  78.     }
  79.     Error(GetStringRes(IDS_WRITEERR));
  80. }
  81.