String String String String String String String String String String String String String String

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Const MAX_SIZE = 255

Const MAX_SECTION = 2048

Declare Function aht_apiGetPrivateProfileInt Lib "kernel32" Alias


"GetPrivateProfileInt" _
(ByVal strAppName As String, ByVal strKeyName As String, ByVal intDefault
As Integer, _
ByVal strFilename As String) As Integer
Declare Function aht_apiGetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" _
(ByVal strAppName As String, ByVal strKeyName As String, ByVal strDefault
As String, _
ByVal strReturned As String, ByVal lngSize As Long, ByVal strFilename As
String) As Long
Declare Function aht_apiGetProfileString Lib "kernel32" Alias
"GetProfileStringA" _
(ByVal strAppName As String, ByVal strKeyName As String, ByVal strDefault
As String, _
ByVal strReturned As String, ByVal lngSize As Long) As Long
Declare Function aht_apiGetProfileInt Lib "kernel32" Alias "GetProfileInt"
_
(ByVal strAppName As String, ByVal strKeyName As String, ByVal intDefault
As Integer) As Integer
Declare Function aht_apiGetProfileSection Lib "kernel32" Alias
"GetProfileSectionA" _
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize
As Long) As Long
Declare Function aht_apiGetPrivateProfileSection Lib "kernel32" Alias
"GetPrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize
As Long, _
ByVal lpFileName As String) As Long
Declare Function aht_apiWritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" _
(ByVal strAppName As String, ByVal strKeyName As String, ByVal strValue As
String, _
ByVal strFilename As String) As Integer
Declare Function aht_apiWriteProfileString Lib "kernel32" Alias
"WriteProfileStringA" _
(ByVal strAppName As String, ByVal strKeyName As String, ByVal strValue As
String) As Integer

Type aht_tagDeviceRec
drDeviceName As String
drDriverName As String
drPort As String
End Type

Type aht_tagDEVMODE
dmDeviceName(1 To 32) As Byte
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName(1 To 32) As Byte
dmLogPixels As Integer
dmBitsPerPixel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
dmICMMethod As Long
dmICMIntent As Long
dmMediaType As Long
dmDitherType As Long
dmICCManufacturer As Long
dmICCModel As Long
dmDriverExtraBytes(1 To 1024) As Byte

End Type

Type aht_tagDEVMODEStr
DMStr As String * 1024
End Type

Type aht_tagDEVNAMES
dnDriverOffset As Integer
dnDeviceOffset As Integer
dnOutputOffset As Integer
dnDefault As Integer
End Type

Type aht_tagDEVNAMEStr
DNStr As String * 4
End Type

Type aht_tagMIP
xLeftMargin As Long
yTopMargin As Long
xRightMargin As Long
yBotMargin As Long
fDataOnly As Long
xFormSize As Long
yFormSize As Long
fDefaultSize As Long
cxColumns As Long
xFormSpacing As Long
yFormSpacing As Long
radItemOrder As Long
fFastPrinting As Long
fDataSheet As Long
End Type

Type aht_tagMIPSTR
MIPStr As String * 28
End Type
Function ahtFillPrinterList(ctl As Control, varID As Variant, varRow As
Variant, varCol As Variant, varCode As Variant)

Static atagDevices() As aht_tagDeviceRec


Static intCount As Integer
Dim varRetval As Variant

Select Case varCode


Case acLBInitialize
intCount = ahtGetPrinterList(atagDevices())
varRetval = True

Case acLBOpen
varRetval = Timer

Case acLBGetRowCount
varRetval = intCount

Case acLBGetColumnCount
varRetval = 1

Case acLBGetValue
varRetval = atagDevices(varRow + 1).drDeviceName & " sur " & _
atagDevices(varRow + 1).drPort

Case acLBEnd
Erase atagDevices
End Select
ahtFillPrinterList = varRetval
End Function

Function ahtGetPrinterList(atagDevices() As aht_tagDeviceRec) As Integer

Dim astrPrinters() As String


Dim intCount As Integer
Dim varPrinters As Variant

varPrinters = ahtGetProfileSection("DEVICES")

If Len(varPrinters & "") = 0 Then


ahtGetPrinterList = 0
Else
intCount = GetDevices(varPrinters, atagDevices())
End If
ahtGetPrinterList = intCount
End Function

Private Function GetDevices(ByVal strPrinters As String, atagDevices() As


aht_tagDeviceRec) As Integer

Dim intI As Integer


Dim strBuffer As String
Dim intCount As Integer

For intI = 1 To Len(strPrinters)


If Mid$(strPrinters, intI, 1) = Chr$(0) Then
intCount = intCount + 1
End If
Next intI
ReDim atagDevices(1 To intCount)

For intI = 1 To intCount


strBuffer = ahtGetToken(strPrinters, Chr$(0), intI)
atagDevices(intI).drDeviceName = ahtGetToken(strBuffer, "=", 1)
strBuffer = ahtGetToken(strBuffer, "=", 2)
atagDevices(intI).drDriverName = ahtGetToken(strBuffer, ",", 1)
atagDevices(intI).drPort = ahtGetToken(strBuffer, ",", 2)
Next intI
GetDevices = intCount
End Function

Function ahtGetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean

Dim strBuffer As String

strBuffer = ahtGetINIString("Windows", "Device")


If Len(strBuffer) > 0 Then
With dr
.drDeviceName = ahtGetToken(strBuffer, ",", 1)
.drDriverName = ahtGetToken(strBuffer, ",", 2)
.drPort = ahtGetToken(strBuffer, ",", 3)
End With
ahtGetDefaultPrinter = True
Else
ahtGetDefaultPrinter = False
End If
End Function

Function ahtSetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean

Dim strBuffer As String

strBuffer = dr.drDeviceName & ","


strBuffer = strBuffer & dr.drDriverName & ","
strBuffer = strBuffer & dr.drPort

ahtSetDefaultPrinter = (aht_apiWriteProfileString("Windows", _
"Device", strBuffer) <> 0)
End Function

Function ahtGetToken(ByVal strValue As String, ByVal strDelimiter As


String, ByVal intPiece As Integer) As Variant

Dim intPos As Integer


Dim intLastPos As Integer
Dim intNewPos As Integer

On Error GoTo ahtGetTokenExit

strDelimiter = Left(strDelimiter, 1)

If (InStr(strValue, strDelimiter) = 0) Or (intPiece <= 0) Then


ahtGetToken = strValue
Else
intPos = 0
intLastPos = 0
Do While intPiece > 0
intLastPos = intPos
intNewPos = InStr(intPos + 1, strValue, strDelimiter)
If intNewPos > 0 Then
intPos = intNewPos
intPiece = intPiece - 1
Else
intPos = Len(strValue) + 1
Exit Do
End If
Loop
If intPiece > 1 Then
ahtGetToken = Null
Else
ahtGetToken = Mid$(strValue, intLastPos + 1, intPos - intLastPos -
1)
End If
End If

ahtGetTokenExit:
Exit Function

ahtGetTokenErr:
MsgBox "Error in ahtGetToken: " & Error & " (" & Err & ")"
Resume ahtGetTokenExit
End Function

Function ahtGetPrivateIniString(ByVal strGroup As String, ByVal strItem As


String, ByVal strFile As String) As Variant

Dim intChars As Integer


Dim strBuffer As String

strBuffer = String(MAX_SIZE, 0)
intChars = aht_apiGetPrivateProfileString(strGroup, strItem, "",
strBuffer, MAX_SIZE, strFile)
ahtGetPrivateIniString = Left(strBuffer, intChars)
End Function

Function ahtGetPrivateProfileSection(ByVal strGroup As String, ByVal


strFile As String) As Variant

Dim strBuffer As String


Dim intCount As Integer

strBuffer = Space(MAX_SECTION)
intCount = aht_apiGetPrivateProfileSection(strGroup, strBuffer,
MAX_SECTION, strFile)
ahtGetPrivateProfileSection = Left(strBuffer, intCount)
End Function

Function ahtGetProfileSection(ByVal strGroup As String) As Variant

Dim strBuffer As String


Dim intCount As Integer

strBuffer = Space(MAX_SECTION)
intCount = aht_apiGetProfileSection(strGroup, strBuffer, MAX_SECTION)
ahtGetProfileSection = Left(strBuffer, intCount)
End Function
Function ahtGetINIString(ByVal strGroup As String, ByVal strItem As String)
As Variant

Dim intChars As Integer


Dim strBuffer As String

strBuffer = String(MAX_SIZE, 0)
intChars = aht_apiGetProfileString(strGroup, strItem, "", strBuffer,
MAX_SIZE)
ahtGetINIString = Left(strBuffer, intChars)
End Function

Function ahtGetPrivateINIInt(ByVal strGroup As String, ByVal strItem As


String, ByVal strFile As String) As Variant
ahtGetPrivateINIInt = aht_apiGetPrivateProfileInt(strGroup, strItem, -1,
strFile)
End Function

Function ahtGetINIInt(ByVal strGroup As String, ByVal strItem As String) As


Variant

ahtGetINIInt = aht_apiGetProfileInt(strGroup, strItem, -1)


End Function

You might also like