home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / inites / testini.bas < prev    next >
Encoding:
BASIC Source File  |  1995-10-23  |  20.5 KB  |  197 lines

  1.     Option Explicit
  2. '*************************************************************************'
  3. '*                                                                       *'
  4. '*        Program Name: TESTINI                                          *'
  5. '*                                                                       *'
  6. '*             Created: Sept 94             By: Christophe Tricaud       *'
  7. '*                                              Compuserve N░ 100412,2653*'
  8. '*                                              Paris, France.           *'
  9. '*            Modified:              By:                                 *'
  10. '*                                                                       *'
  11. '*            Comments: This small program shows easy use of INI function*'
  12. '*                      for those who do not want to use API. Just use   *'
  13. '*                      the few functions of this program which are      *'
  14. '*                      sufficient.                                      *'
  15. '*                                                                       *'
  16. '*************************************************************************'
  17.  
  18. '                                                                                                                                                                                                                                                                       '
  19. '                                                                                                                                                                                                                                                                        '
  20. 'Global Constants declaration                                                                                                                                                                                                                                             '
  21. '                                                                                                                                                                                                                                                                          '
  22. '                                                                                                                                                                                                                                                                           '
  23.     Global Const WM_WININICHANGE = &H1A
  24.     Global Const nSize = 128
  25.     Global Const HWND_BROADCAST = &HFFFF
  26.     Global Const SPI_SETDESKPATTERN = 21
  27.     Global Const SPI_SETBORDER = 6
  28.     Global Const SPI_SETBEEP = 2
  29.     Global Const SPI_SETDESKWALLPAPER = 20
  30.     Global Const SPI_SETDOUBLECLICKTIME = 32
  31.     Global Const SPI_SETSCREENSAVEACTIVE = 17
  32.     Global Const SPI_SETSCREENSAVETIMEOUT = 15
  33.     Global Const SPIF_SENDWININICHANGE = 2
  34.     Global Const SPIF_UPDATEINIFILE = 1
  35. '                                                                                                                                                                                                                                                   '
  36. '                                                                                                                                                                                                                                                    '
  37. 'Type declarations                                                                                                                                                                                                                               '
  38. '                                                                                                                                                                                                                                                      '
  39. '                                                                                                                                                                                                                                                       '
  40.     Type RECT
  41.       Left As Integer
  42.       Top As Integer
  43.       right As Integer
  44.       Bottom As Integer
  45.     End Type
  46. '                                                                                                                                                                                                                                                                                                   '
  47. '                                                                                                                                                                                                                                                                                                    '
  48. 'API declaration                                                                                                                                                                                                                                                                                      '
  49. '                                                                                                                                                                                                                                                                                                      '
  50. '                                                                                                                                                                                                                                                                                                       '
  51.     Declare Function GetPrivateProfileString% Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName As Any, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)
  52.     Declare Function WritePrivateProfileString% Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName$)
  53.     Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  54.     Declare Function SystemParametersInfo Lib "User" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
  55.     Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Long
  56.     Declare Function PostMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Long
  57.     Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
  58.     Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer
  59.     Declare Function FillRect Lib "User" (ByVal hDC As Integer, lpRect As RECT, ByVal hBrush As Integer) As Integer
  60. '                                                                                                                                                                                                                                                   '
  61. '                                                                                                                                                                                                                                                    '
  62. 'Variables declarations                                                                                                                                                                                                                               '
  63. '                                                                                                                                                                                                                                                      '
  64. '                                                                                                                                                                                                                                                       '
  65.     Global Windir As String         'Contient le rΘpertoire de Windows'
  66.  
  67. Function DelEntry (ByVal NomApplication As String, ByVal NomSection As String, ByVal NomEntree As String) As Integer
  68. '                                                                                                                                                                                           '
  69. '                                                                                                                                                                                            '
  70. 'ProcΘdure permet de supprimer une entrΘe                                                                                                                                                     '
  71. '                                                                                                                                                                                              '
  72. '                                                                                                                                                                                               '
  73.     Dim A As Integer               'Longueur de retour                                                                                                                                                           '
  74.  
  75.     A = WritePrivateProfileString(NomSection, NomEntree, 0&, NomApplication)
  76.     DelEntry = A
  77.     
  78. End Function
  79.  
  80. Function DelSection (ByVal NomApplication As String, ByVal NomSection As String) As Integer
  81. '                                                                                                                                                                                           '
  82. '                                                                                                                                                                                            '
  83. 'ProcΘdure permet de supprimer une entrΘe                                                                                                                                                     '
  84. '                                                                                                                                                                                              '
  85. '                                                                                                                                                                                               '
  86.     Dim A As Integer               'Longueur de retour                                                                                                                                                           '
  87.  
  88.     A = WritePrivateProfileString(NomSection, 0&, "", NomApplication)
  89.     DelSection = A
  90.     
  91. End Function
  92.  
  93. Sub FondEcran (F As Form, Titre As String)
  94. '                                                                                                                                                   '
  95. '                                                                                                                                                    '
  96. 'Permet de dessiner un fond dΘgradΘ bleu                                                                                                              '
  97. '                                                                                                                                                      '
  98. '                                                                                                                                                       '
  99.     Dim I As Integer             'Boucle de lecture                       '
  100.     Dim Res As Integer           'Resultat                                '
  101.     Dim hBrush As Integer        'Handle du brush                         '
  102.     Dim Trace As RECT            'Structre du cadre α remplir             '
  103.     Dim HauteurTrace As Single   'Hauteur du rectangle                    '
  104.     Dim OldMode As Integer       '                                        '
  105.     'Calcul de la hauteur totale du rectangle                                                                                                                                                               '
  106.     HauteurTrace = F.ScaleHeight / (127)
  107.     OldMode = F.ScaleMode
  108.     F.ScaleMode = 3
  109.     F.Cls
  110.  
  111.     Trace.Left = 0
  112.     Trace.Top = 0
  113.     Trace.right = F.ScaleWidth
  114.     Trace.Bottom = HauteurTrace
  115.     'Dessin des rectangles avec brush                                                                                                                                       '
  116.      For I = 0 To 255 Step 2
  117.      hBrush = CreateSolidBrush(RGB(0, 0, 255 - I))
  118.      Res = FillRect(F.hDC, Trace, hBrush)
  119.      Res = DeleteObject(hBrush)
  120.      Trace.Top = Trace.Bottom
  121.      Trace.Bottom = HauteurTrace * (1 + (I / 2))
  122.      Next
  123.      'Dessin du titre                                                                                                                                       '
  124.      F.FontSize = 32
  125.      F.ForeColor = RGB(0, 0, 0)
  126.      F.CurrentX = F.ScaleWidth - F.TextWidth(Titre) - 20
  127.      F.CurrentY = .2 * F.TextHeight(Titre)
  128.      F.Print Titre;
  129.      F.CurrentX = F.ScaleWidth - F.TextWidth(Titre) - 25
  130.      F.CurrentY = F.CurrentY - 5
  131.      F.ForeColor = RGB(255, 255, 255)
  132.      F.Print Titre
  133.      'On remet le mode ancien                                                                                                                                       '
  134.      F.ScaleMode = OldMode
  135. End Sub
  136.  
  137. Sub GetEntries (NomApplication As String, NomSection As String, Tableau() As String)
  138. '                                                                                                                                                                                                                                                                           '
  139. '                                                                                                                                                                                                                                                                            '
  140. 'Cette procΘdure permet de rΘcupΘrer les entrΘe d'une section                                                                                                                                                                                                                 '
  141. '                                                                                                                                                                                                                                                                              '
  142. '                                                                                                                                                                                                                                                                               '
  143.     Dim Retour As String
  144.     Dim A As Integer
  145.     Dim I As Integer
  146.     Dim INull As String
  147.  
  148.     Retour = Space$(10000)
  149.     INull = Chr$(0)
  150.  
  151.     A = GetPrivateProfileString(NomSection, 0&, "", Retour, 10000, NomApplication)
  152.     '                                                                                                                                                                                                                                           '
  153.     '                                                                                                                                                                                                                                            '
  154.     'Transformation de retour en tableau                                                                                                                                                                                                          '
  155.     '                                                                                                                                                                                                                                              '
  156.     '                                                                                                                                                                                                                                               '
  157.     Retour = Left$(Retour, A)
  158.     While Len(Retour) <> 0
  159.     I = I + 1
  160.     ReDim Preserve Tableau(I)
  161.     Tableau(I) = Left$(Retour, InStr(Retour, Chr$(0)) - 1)
  162.     Retour = Right$(Retour, Len(Retour) - InStr(Retour, Chr$(0)))
  163.     Wend
  164. End Sub
  165.  
  166. Function GetIni (NomApplication As String, NomSection As String, NomEntree As String, NomDefaut As String, Taille As Integer) As String
  167. '                                                                                                                                                                                                                                                               '
  168. '                                                                                                                                                                                                                                                                '
  169. 'Cette procΘdure permet d'effectuer une lecture d'un fichier INI                                                                                                                                                                                                  '
  170. '                                                                                                                                                                                                                                                                  '
  171. '                                                                                                                                                                                                                                                                   '
  172.     Dim Retour As String           'Valeur de retour                                                                                                                                                            '
  173.     Dim A As Integer               'Longueur de retour                                                                                                                                                           '
  174.  
  175.     Retour = Space$(Taille)
  176.     A = GetPrivateProfileString(NomSection, NomEntree, NomDefaut, Retour, Taille, NomApplication)
  177.  
  178.     If A <> 0 Then
  179.     GetIni = Left$(Retour, A)
  180.     Else
  181.     GetIni = ""
  182.     End If
  183. End Function
  184.  
  185. Function WriteIni (NomApplication As String, NomSection As String, NomEntree As String, Valeur As String) As Integer
  186. '                                                                                                                                                                                                                                                               '
  187. '                                                                                                                                                                                                                                                                '
  188. 'Cette procΘdure permet d'effectuer une Θcriture sur un fichier INI                                                                                                                                                                                                  '
  189. '                                                                                                                                                                                                                                                                  '
  190. '                                                                                                                                                                                                                                                                   '
  191.     Dim A As Integer               'Longueur de retour                                                                                                                                                           '
  192.  
  193.     A = WritePrivateProfileString(NomSection, NomEntree, Valeur, NomApplication)
  194.     WriteIni = A
  195. End Function
  196.  
  197.