?? common.bas
字號:
'------------------------------------------------------------
'- Language Functions...
'------------------------------------------------------------
Private Function PRIMARYLANGID(ByVal LCID As Integer) As Integer
PRIMARYLANGID = (LCID And &H3FF)
End Function
Private Function SUBLANGID(ByVal LCID As Integer) As Integer
SUBLANGID = (LCID / (2 ^ 10))
End Function
'-----------------------------------------------------------
' Function: GetUserCharset
'
' Get's the default user character set
'
' OS: Win 95 & NT 4 or newer
'-----------------------------------------------------------
Private Function GetUserCharset() As Integer
Dim ls As LOCALESIGNATURE ' local signature struct.
Dim ci As CHARSETINFO ' character set info struct.
Dim rc As Long ' return code
' get locale signature based on the USER's Default LCID.
rc = GetLocaleInfoLS(GetUserDefaultLCID, LOCALE_FONTSIGNATURE, ls, Len(ls))
If (rc > 0) Then ' if success
ls.lsCsbDefault(1) = 0 ' zero out bits
' translate charset info from locale fontsignature.
rc = TranslateCharsetInfo(ls.lsCsbDefault(0), ci, TCI_SRCFONTSIG)
If rc <> 0 Then GetUserCharset = ci.ciCharset ' return charset
End If
End Function
'-----------------------------------------------------------
' Function: IsFontSupported
'
' Validates a font name to make sure it is supported by
' on the current system.
'
' IN/OUT: [sFontName] - name of font to check, will also]
' be set to the default font name if the provided
' one is not supported.
'-----------------------------------------------------------
Private Function IsFontSupported(sFontName As String) As Boolean
Dim oFont As StdFont
On Error Resume Next
Set oFont = New StdFont
oFont.Name = sFontName
IsFontSupported = (UCase(oFont.Name) = UCase(sFontName))
sFontName = oFont.Name
End Function
'-----------------------------------------------------------
' SUB: SetMousePtr
'
' Provides a way to set the mouse pointer only when the
' pointer state changes. For every HOURGLASS call, there
' should be a corresponding DEFAULT call. Other types of
' mouse pointers are set explicitly.
'
' IN: [intMousePtr] - type of mouse pointer desired
'-----------------------------------------------------------
'
Sub SetMousePtr(intMousePtr As Integer)
Static intPtrState As Integer
Select Case intMousePtr
Case vbHourglass
intPtrState = intPtrState + 1
Case gintMOUSE_DEFAULT
intPtrState = intPtrState - 1
If intPtrState < 0 Then
intPtrState = 0
End If
Case Else
Screen.MousePointer = intMousePtr
Exit Sub
'End Case
End Select
Screen.MousePointer = IIf(intPtrState > 0, vbHourglass, gintMOUSE_DEFAULT)
End Sub
'-----------------------------------------------------------
' FUNCTION: StripTerminator
'
' Returns a string without any zero terminator. Typically,
' this was a string returned by a Windows API call.
'
' IN: [strString] - String to remove terminator from
'
' Returns: The value of the string passed in minus any
' terminating zero.
'-----------------------------------------------------------
'
Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
'-----------------------------------------------------------
' FUNCTION: GetFileVersion
'
' Returns the internal file version number for the specified
' file. This can be different than the 'display' version
' number shown in the File Manager File Properties dialog.
' It is the same number as shown in the VB5 SetupWizard's
' File Details screen. This is the number used by the
' Windows VerInstallFile API when comparing file versions.
'
' IN: [strFilename] - the file whose version # is desired
' [fIsRemoteServerSupportFile] - whether or not this file is
' a remote ActiveX component support file (.VBR)
' (Enterprise edition only). If missing, False is assumed.
'
' Returns: The Version number string if found, otherwise
' vbnullstring
'-----------------------------------------------------------
'
Function GetFileVersion(ByVal strFilename As String, Optional ByVal fIsRemoteServerSupportFile As Boolean = False) As String
Dim sVerInfo As VERINFO
Dim strVer As String
On Error GoTo GFVError
'
'Get the file version into a VERINFO struct, and then assemble a version string
'from the appropriate elements.
'
If GetFileVerStruct(strFilename, sVerInfo, fIsRemoteServerSupportFile) = True Then
strVer = Format$(sVerInfo.FileVerPart1) & gstrDECIMAL & Format$(sVerInfo.FileVerPart2) & gstrDECIMAL
strVer = strVer & Format$(sVerInfo.FileVerPart3) & gstrDECIMAL & Format$(sVerInfo.FileVerPart4)
GetFileVersion = strVer
Else
GetFileVersion = vbNullString
End If
Exit Function
GFVError:
GetFileVersion = vbNullString
Err = 0
End Function
'-----------------------------------------------------------
' FUNCTION: GetFileVerStruct
'
' Gets the file version information into a VERINFO TYPE
' variable
'
' IN: [strFilename] - name of file to get version info for
' [fIsRemoteServerSupportFile] - whether or not this file is
' a remote ActiveX component support file (.VBR)
' (Enterprise edition only). If missing, False is assumed.
' OUT: [sVerInfo] - VERINFO Type to fill with version info
'
' Returns: True if version info found, False otherwise
'-----------------------------------------------------------
'
Function GetFileVerStruct(ByVal sFile As String, sVer As VERINFO, Optional ByVal fIsRemoteServerSupportFile As Boolean = False) As Boolean
Dim lVerSize As Long, lTemp As Long, lRet As Long
Dim bInfo() As Byte
Dim lpBuffer As Long
Const sEXE As String * 1 = "\"
Dim fFoundVer As Boolean
GetFileVerStruct = False
fFoundVer = False
If fIsRemoteServerSupportFile Then
GetFileVerStruct = GetRemoteSupportFileVerStruct(sFile, sVer)
fFoundVer = True
Else
'
'Get the size of the file version info, allocate a buffer for it, and get the
'version info. Next, we query the Fixed file info portion, where the internal
'file version used by the Windows VerInstallFile API is kept. We then copy
'the fixed file info into a VERINFO structure.
'
lVerSize = GetFileVersionInfoSize(sFile, lTemp)
ReDim bInfo(lVerSize)
If lVerSize > 0 Then
lRet = GetFileVersionInfo(sFile, lTemp, lVerSize, VarPtr(bInfo(0)))
If lRet <> 0 Then
lRet = VerQueryValue(VarPtr(bInfo(0)), sEXE & vbNullChar, lpBuffer, lVerSize)
If lRet <> 0 Then
CopyMemory sVer, ByVal lpBuffer, lVerSize
fFoundVer = True
GetFileVerStruct = True
End If
End If
End If
End If
If Not fFoundVer Then
'
' We were unsuccessful in finding the version info from the file.
' One possibility is that this is a dependency file.
'
If UCase(Extension(sFile)) = gstrEXT_DEP Then
GetFileVerStruct = GetDepFileVerStruct(sFile, sVer)
End If
End If
End Function
'-----------------------------------------------------------
' FUNCTION: GetFileDescription
'
' Gets the file description information.
'
' IN: [strFilename] - name of file to get description of.
'
' Returns: Description (vbNullString if not found)
'-----------------------------------------------------------
'
Function GetFileDescription(ByVal sFile As String) As String
Dim lVerSize As Long, lTemp As Long, lRet As Long
Dim bInfo() As Byte
Dim lpBuffer As Long
Dim sDesc As String
Dim sKEY As String
Const sEXE As String = "\FileDescription"
GetFileDescription = vbNullString
'
'Get the size of the file version info, allocate a buffer for it, and get the
'version info. Next, we query the Fixed file info portion, where the internal
'file version used by the Windows VerInstallFile API is kept. We then copy
'the info into a string.
'
lVerSize = GetFileVersionInfoSize(sFile, lTemp)
ReDim bInfo(lVerSize)
If lVerSize > 0 Then
lRet = GetFileVersionInfo(sFile, lTemp, lVerSize, VarPtr(bInfo(0)))
If lRet <> 0 Then
sKEY = GetNLSKey(bInfo)
lRet = VerQueryValue(VarPtr(bInfo(0)), sKEY & sEXE, lpBuffer, lVerSize)
If lRet <> 0 Then
sDesc = Space$(lVerSize)
lstrcpyn sDesc, lpBuffer, lVerSize
GetFileDescription = sDesc
End If
End If
End If
End Function
Private Function GetNLSKey(byteVerData() As Byte) As String
Const strTRANSLATION$ = "\VarFileInfo\Translation"
Const strSTRINGFILEINFO$ = "\StringFileInfo\"
Const strDEFAULTNLSKEY$ = "040904E4"
Const LOCALE_IDEFAULTLANGUAGE& = &H9&
Const LOCALE_IDEFAULTCODEPAGE& = &HB&
Static strLANGCP As String
Dim lpBufPtr As Long
Dim strNLSKey As String
Dim fGotNLSKey As Integer
Dim intOffset As Integer
Dim lVerSize As Long
Dim ltmp As Long
Dim lBufLen As Long
Dim lLCID As Long
Dim strTmp As String
On Error GoTo GNLSKCleanup
If VerQueryValue(VarPtr(byteVerData(0)), strTRANSLATION, lpBufPtr, lVerSize) <> 0 Then ' (Pass byteVerData array via reference to first element)
If Len(strLANGCP) = 0 Then
lLCID = GetUserDefaultLCID()
If lLCID > 0 Then
strTmp = Space$(8)
GetLocaleInfoA lLCID, LOCALE_IDEFAULTCODEPAGE, strTmp, 8
strLANGCP = StripTerminator(strTmp)
While Len(strLANGCP) < 4
strLANGCP = gsZERO & strLANGCP
Wend
GetLocaleInfoA lLCID, LOCALE_IDEFAULTLANGUAGE, strTmp, 8
strLANGCP = StripTerminator(strTmp) & strLANGCP
While Len(strLANGCP) < 8
strLANGCP = gsZERO & strLANGCP
Wend
End If
End If
If VerQueryValue(VarPtr(byteVerData(0)), strLANGCP, ltmp, lBufLen) <> 0 Then
strNLSKey = strLANGCP
Else
For intOffset = 0 To lVerSize - 1 Step 4
CopyMemory ltmp, ByVal lpBufPtr + intOffset, 4
strTmp = Hex$(ltmp)
While Len(strTmp) < 8
strTmp = gsZERO & strTmp
Wend
strNLSKey = strSTRINGFILEINFO & Right$(strTmp, 4) & Left$(strTmp, 4)
If VerQueryValue(VarPtr(byteVerData(0)), strNLSKey, ltmp, lBufLen) <> 0 Then
fGotNLSKey = True
Exit For
End If
Next
If Not fGotNLSKey Then
strNLSKey = strSTRINGFILEINFO & strDEFAULTNLSKEY
If VerQueryValue(VarPtr(byteVerData(0)), strNLSKey, ltmp, lBufLen) <> 0 Then
fGotNLSKey = True
End If
End If
End If
End If
GNLSKCleanup:
If fGotNLSKey Then
GetNLSKey = strNLSKey
End If
End Function
'-----------------------------------------------------------
' FUNCTION: GetDepFileVerStruct
'
' Gets the file version information from a dependency
' file (*.dep). Such files do not have a Windows version
' stamp, but they do have an internal version stamp that
' we can look for.
'
' IN: [strFilename] - name of dep file to get version info for
' OUT: [sVerInfo] - VERINFO Type to fill with version info
'
' Returns: True if version info found, False otherwise
'-----------------------------------------------------------
'
Function GetDepFileVerStruct(ByVal strFilename As String, sVerInfo As VERINFO) As Boolean
Const strVersionKey = "Version="
Dim cchVersionKey As Integer
Dim iFile As Integer
GetDepFileVerStruct = False
cchVersionKey = Len(strVersionKey)
sVerInfo.FileVerPart1 = gintNOVERINFO
On Error GoTo Failed
iFile = FreeFil
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -