¡®--------------------------------------------------------------
¡® Copyright ¨Ï1996-2002 VBnet, Randy Birch, All Rights Reserved.
¡® Terms of use http://www.mvps.org/vbnet/terms/pages/terms.htm
¡®--------------------------------------------------------------
Private Declare Function GetPrivateProfileString Lib ¡°Kernel32¡± _
Alias ¡°GetPrivateProfileStringA¡± _
(ByVal lpSectionName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib ¡°Kernel32¡± _
Alias ¡°WritePrivateProfileStringA¡± _
(ByVal lpSectionName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Public Sub ProfileSaveItem(lpSectionName As String, _
lpKeyName As String, _
lpValue As String, _
inifile As String)
¡®This function saves the passed value to the file,
¡®under the section and key names specified.
¡®If the ini file does not exist, it is created.
¡®If the section does not exist, it is created.
¡®If the key name does not exist, it is created.
¡®If the key name exists, it¡¯s value is replaced.
End Sub
Public Function ProfileGetItem(lpSectionName As String, _
lpKeyName As String, _
defaultValue As String, _
inifile As String) As String
¡®Retrieves a value from an ini file corresponding
¡®to the section and key name passed.
Dim success As Long
Dim nSize As Long
Dim ret As String
¡®call the API with the parameters passed.
¡®The return value is the length of the string
¡®in ret, including the terminating null. If a
¡®default value was passed, and the section or
¡®key name are not in the file, that value is
¡®returned. If no default value was passed (¡°¡±),
¡®then success will = 0 if not found.
¡®Pad a string large enough to hold the data.
ret = Space$(2048)
nSize = Len(ret)
success = GetPrivateProfileString(lpSectionName, _
lpKeyName, _
defaultValue, _
ret, _
nSize, _
inifile)
If success Then
ProfileGetItem = Left$(ret, success)
End If
End Function
Public Sub ProfileDeleteItem(lpSectionName As String, _
lpKeyName As String, _
inifile As String)
¡®this call will remove the keyname and its
¡®corresponding value from the section specified
¡®in lpSectionName. This is accomplished by passing
¡®vbNullString as the lpValue parameter. For example,
¡®assuming that an ini file had:
¡® [Colours]
¡® Colour1=Red
¡® Colour2=Blue
¡® Colour3=Green
¡®
¡®and this sub was called passing ¡°Colour2¡±
¡®as lpKeyName, the resulting ini file
¡®would contain:
¡® [Colours]
¡® Colour1=Red
¡® Colour3=Green
Public Sub ProfileDeleteSection(lpSectionName As String, _
inifile As String)
¡®this call will remove the entire section
¡®corresponding to lpSectionName. This is
¡®accomplished by passing vbNullString
¡®as both the lpKeyName and lpValue parameters.
¡®For example, assuming that an ini file had:
¡® [Colours]
¡® Colour1=Red
¡® Colour2=Blue
¡® Colour3=Green
¡®
¡®and this sub was called passing ¡°Colours¡±
¡®as lpSectionName, the resulting Colours
¡®section in the ini file would be deleted.
:
:
¡®------------------------------------------------------------
¡® GetDxDyOfHdcAndText
¡®
¡® Returns text height/width in twips given an hDC and some text
¡®------------------------------------------------------------
Public Sub GetDxDyOfHdcAndText(ctl As Control, stText As String,
ByRef dx As Long, ByRef dy As Long)
Dim nLogPixelsX As Long
Dim nLogPixelsY As Long
Dim typSize As size
Dim typTM As TEXTMETRIC
Dim wTextWidth As Integer
Dim wTextHeight As Integer
Dim strLen As Long
Dim hdc As Long
hdc = GetDC(ByVal ctl.hwnd)
¡® Get the info on pixels per logical unit
nLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX)
nLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY)
¡® ¡® We need some font info here
Call GetTextMetrics(hdc, typTM)
¡® Do the actual deed, get the info
Private Sub cmdFont_Click()
MsgBox ¡°Name: ¡° & cmdFont.Font.Name & ¡°, Size: ¡° & cmdFont.Font.size
End Sub
Private Sub optKorean_Click()
strLngIniFile = App.Path & ¡°\Font_Kor.ini¡±
cmdFont.Caption = GetStrings(¡°cmdFont¡±)
SetProperFont cmdFont.Font, 1042
ReSizeControl cmdFont, cmdFont.Width, cmdFont.Height
End Sub
Private Sub optEnglish_Click()
strLngIniFile = App.Path & ¡°\Font_Eng.ini¡±
cmdFont.Caption = GetStrings(¡°cmdFont¡±)
SetProperFont cmdFont.Font, 1033
ReSizeControl cmdFont, cmdFont.Width, cmdFont.Height
End Sub
Private Sub optDefault_Click()
Dim LCID As Integer
Dim PLangId As Integer
Dim sLangId As Integer
LCID = GetUserDefaultLCID
PLangId = (LCID And &H3FF) ¡® LCID¡¯s Primary language id
sLangId = (LCID / (2 ^ 10)) ¡® LCID¡¯s Sub language id
If PLangId = LANG_KOREAN Then
strLngIniFile = App.Path & ¡°\Font_Kor.ini¡±
Else
strLngIniFile = App.Path & ¡°\Font_Eng.ini¡±
End If
cmdFont.Caption = GetStrings(¡°cmdFont¡±)
SetProperFont cmdFont.Font, LCID
ReSizeControl cmdFont, cmdFont.Width, cmdFont.Height
End Sub
Private Function GetStrings(sKey As String) As String
GetStrings = Trim(Replace(ProfileGetItem(csModuleName, sKey, ¡°¡±,
strLngIniFile), vbNullChar, ¡°¡±))
End Function
The Korean edition of 'ZDNet' is published under license from CNET Networks, Inc., San Francisco, CA, USA. Editorial items appearing in 'ZDNet Korea' that were originally published in the US Edition of 'ZDNet', 'CNET', and 'CNET News.com' are the copyright properties of CNET Networks, Inc. or its suppliers.
Copyright ¨Ï 2008 CNET Networks, Inc. All Rights Reserved. 'ZDNet', 'CNET' and 'CNET News.com' are trademarks of CNET Networks, Inc.