home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / sub-pixel_20260610192006.psc / mCommonDialog.bas < prev    next >
BASIC Source File  |  2006-10-19  |  38KB  |  1,118 lines

  1. Attribute VB_Name = "mCommonDialog"
  2. Option Explicit
  3.  
  4. Public Enum EErrorCommonDialog
  5.     eeBaseCommonDialog = 13450  ' CommonDialog
  6. End Enum
  7.  
  8. Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
  9. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  10. Private Declare Function GlobalCompact Lib "kernel32" (ByVal dwMinFree As Long) As Long
  11. Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  12. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  13. Private Declare Function GlobalReAlloc Lib "kernel32" (ByVal hMem As Long, ByVal dwBytes As Long, ByVal wFlags As Long) As Long
  14. Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
  15. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  16. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
  17.     lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
  18. Private Declare Sub CopyMemoryStr Lib "kernel32" Alias "RtlMoveMemory" ( _
  19.     lpvDest As Any, ByVal lpvSource As String, ByVal cbCopy As Long)
  20.  
  21. Private Const MAX_PATH = 260
  22. Private Const MAX_FILE = 260
  23.  
  24. Private Type OPENFILENAME
  25.     lStructSize As Long          ' Filled with UDT size
  26.     hWndOwner As Long            ' Tied to Owner
  27.     hInstance As Long            ' Ignored (used only by templates)
  28.     lpstrFilter As String        ' Tied to Filter
  29.     lpstrCustomFilter As String  ' Ignored (exercise for reader)
  30.     nMaxCustFilter As Long       ' Ignored (exercise for reader)
  31.     nFilterIndex As Long         ' Tied to FilterIndex
  32.     lpstrFile As String          ' Tied to FileName
  33.     nMaxFile As Long             ' Handled internally
  34.     lpstrFileTitle As String     ' Tied to FileTitle
  35.     nMaxFileTitle As Long        ' Handled internally
  36.     lpstrInitialDir As String    ' Tied to InitDir
  37.     lpstrTitle As String         ' Tied to DlgTitle
  38.     flags As Long                ' Tied to Flags
  39.     nFileOffset As Integer       ' Ignored (exercise for reader)
  40.     nFileExtension As Integer    ' Ignored (exercise for reader)
  41.     lpstrDefExt As String        ' Tied to DefaultExt
  42.     lCustData As Long            ' Ignored (needed for hooks)
  43.     lpfnHook As Long             ' Ignored (good luck with hooks)
  44.     lpTemplateName As Long       ' Ignored (good luck with templates)
  45. End Type
  46.  
  47. Private Declare Function GetOpenFileName Lib "COMDLG32" _
  48.     Alias "GetOpenFileNameA" (file As OPENFILENAME) As Long
  49. Private Declare Function GetSaveFileName Lib "COMDLG32" _
  50.     Alias "GetSaveFileNameA" (file As OPENFILENAME) As Long
  51. Private Declare Function GetFileTitle Lib "COMDLG32" _
  52.     Alias "GetFileTitleA" (ByVal szFile As String, _
  53.     ByVal szTitle As String, ByVal cbBuf As Long) As Long
  54.  
  55. Public Enum EOpenFile
  56.     OFN_READONLY = &H1
  57.     OFN_OVERWRITEPROMPT = &H2
  58.     OFN_HIDEREADONLY = &H4
  59.     OFN_NOCHANGEDIR = &H8
  60.     OFN_SHOWHELP = &H10
  61.     OFN_ENABLEHOOK = &H20
  62.     OFN_ENABLETEMPLATE = &H40
  63.     OFN_ENABLETEMPLATEHANDLE = &H80
  64.     OFN_NOVALIDATE = &H100
  65.     OFN_ALLOWMULTISELECT = &H200
  66.     OFN_EXTENSIONDIFFERENT = &H400
  67.     OFN_PATHMUSTEXIST = &H800
  68.     OFN_FILEMUSTEXIST = &H1000
  69.     OFN_CREATEPROMPT = &H2000
  70.     OFN_SHAREAWARE = &H4000
  71.     OFN_NOREADONLYRETURN = &H8000
  72.     OFN_NOTESTFILECREATE = &H10000
  73.     OFN_NONETWORKBUTTON = &H20000
  74.     OFN_NOLONGNAMES = &H40000
  75.     OFN_EXPLORER = &H80000
  76.     OFN_NODEREFERENCELINKS = &H100000
  77.     OFN_LONGNAMES = &H200000
  78. End Enum
  79.  
  80. Private Type TCHOOSECOLOR
  81.     lStructSize As Long
  82.     hWndOwner As Long
  83.     hInstance As Long
  84.     rgbResult As Long
  85.     lpCustColors As Long
  86.     flags As Long
  87.     lCustData As Long
  88.     lpfnHook As Long
  89.     lpTemplateName As Long
  90. End Type
  91.  
  92. Private Declare Function ChooseColor Lib "COMDLG32.DLL" _
  93.     Alias "ChooseColorA" (Color As TCHOOSECOLOR) As Long
  94.  
  95. Public Enum EChooseColor
  96.     CC_RGBInit = &H1
  97.     CC_FullOpen = &H2
  98.     CC_PreventFullOpen = &H4
  99.     CC_ColorShowHelp = &H8
  100. ' Win95 only
  101.     CC_SolidColor = &H80
  102.     CC_AnyColor = &H100
  103. ' End Win95 only
  104.     CC_ENABLEHOOK = &H10
  105.     CC_ENABLETEMPLATE = &H20
  106.     CC_EnableTemplateHandle = &H40
  107. End Enum
  108. Private Declare Function GetSysColor Lib "USER32" (ByVal nIndex As Long) As Long
  109.  
  110. Private Type TCHOOSEFONT
  111.     lStructSize As Long         ' Filled with UDT size
  112.     hWndOwner As Long           ' Caller's window handle
  113.     hdc As Long                 ' Printer DC/IC or NULL
  114.     lpLogFont As Long           ' Pointer to LOGFONT
  115.     iPointSize As Long          ' 10 * size in points of font
  116.     flags As Long               ' Type flags
  117.     rgbColors As Long           ' Returned text color
  118.     lCustData As Long           ' Data passed to hook function
  119.     lpfnHook As Long            ' Pointer to hook function
  120.     lpTemplateName As Long      ' Custom template name
  121.     hInstance As Long           ' Instance handle for template
  122.     lpszStyle As String         ' Return style field
  123.     nFontType As Integer        ' Font type bits
  124.     iAlign As Integer           ' Filler
  125.     nSizeMin As Long            ' Minimum point size allowed
  126.     nSizeMax As Long            ' Maximum point size allowed
  127. End Type
  128. Private Declare Function ChooseFont Lib "COMDLG32" _
  129.     Alias "ChooseFontA" (chfont As TCHOOSEFONT) As Long
  130.  
  131. Private Const LF_FACESIZE = 32
  132. Private Type LOGFONT
  133.     lfHeight As Long
  134.     lfWidth As Long
  135.     lfEscapement As Long
  136.     lfOrientation As Long
  137.     lfWeight As Long
  138.     lfItalic As Byte
  139.     lfUnderline As Byte
  140.     lfStrikeOut As Byte
  141.     lfCharSet As Byte
  142.     lfOutPrecision As Byte
  143.     lfClipPrecision As Byte
  144.     lfQuality As Byte
  145.     lfPitchAndFamily As Byte
  146.     lfFaceName(LF_FACESIZE) As Byte
  147. End Type
  148.  
  149. Public Enum EChooseFont
  150.     CF_ScreenFonts = &H1
  151.     CF_PrinterFonts = &H2
  152.     CF_BOTH = &H3
  153.     CF_FontShowHelp = &H4
  154.     CF_UseStyle = &H80
  155.     CF_EFFECTS = &H100
  156.     CF_AnsiOnly = &H400
  157.     CF_NoVectorFonts = &H800
  158.     CF_NoOemFonts = CF_NoVectorFonts
  159.     CF_NoSimulations = &H1000
  160.     CF_LimitSize = &H2000
  161.     CF_FixedPitchOnly = &H4000
  162.     CF_WYSIWYG = &H8000  ' Must also have ScreenFonts And PrinterFonts
  163.     CF_ForceFontExist = &H10000
  164.     CF_ScalableOnly = &H20000
  165.     CF_TTOnly = &H40000
  166.     CF_NoFaceSel = &H80000
  167.     CF_NoStyleSel = &H100000
  168.     CF_NoSizeSel = &H200000
  169.     ' Win95 only
  170.     CF_SelectScript = &H400000
  171.     CF_NoScriptSel = &H800000
  172.     CF_NoVertFonts = &H1000000
  173.  
  174.     CF_InitToLogFontStruct = &H40
  175.     CF_Apply = &H200
  176.     CF_EnableHook = &H8
  177.     CF_EnableTemplate = &H10
  178.     CF_EnableTemplateHandle = &H20
  179.     CF_FontNotSupported = &H238
  180. End Enum
  181.  
  182. ' These are extra nFontType bits that are added to what is returned to the
  183. ' EnumFonts callback routine
  184.  
  185. Public Enum EFontType
  186.     Simulated_FontType = &H8000
  187.     Printer_FontType = &H4000
  188.     Screen_FontType = &H2000
  189.     Bold_FontType = &H100
  190.     Italic_FontType = &H200
  191.     Regular_FontType = &H400
  192. End Enum
  193.  
  194. Private Type TPRINTDLG
  195.     lStructSize As Long
  196.     hWndOwner As Long
  197.     hDevMode As Long
  198.     hDevNames As Long
  199.     hdc As Long
  200.     flags As Long
  201.     nFromPage As Integer
  202.     nToPage As Integer
  203.     nMinPage As Integer
  204.     nMaxPage As Integer
  205.     nCopies As Integer
  206.     hInstance As Long
  207.     lCustData As Long
  208.     lpfnPrintHook As Long
  209.     lpfnSetupHook As Long
  210.     lpPrintTemplateName As Long
  211.     lpSetupTemplateName As Long
  212.     hPrintTemplate As Long
  213.     hSetupTemplate As Long
  214. End Type
  215.  
  216. '  DEVMODE collation selections
  217. Private Const DMCOLLATE_FALSE = 0
  218. Private Const DMCOLLATE_TRUE = 1
  219.  
  220. Private Declare Function PrintDlg Lib "COMDLG32.DLL" _
  221.     Alias "PrintDlgA" (prtdlg As TPRINTDLG) As Integer
  222.  
  223. Public Enum EPrintDialog
  224.     PD_ALLPAGES = &H0
  225.     PD_SELECTION = &H1
  226.     PD_PAGENUMS = &H2
  227.     PD_NOSELECTION = &H4
  228.     PD_NOPAGENUMS = &H8
  229.     PD_COLLATE = &H10
  230.     PD_PRINTTOFILE = &H20
  231.     PD_PRINTSETUP = &H40
  232.     PD_NOWARNING = &H80
  233.     PD_RETURNDC = &H100
  234.     PD_RETURNIC = &H200
  235.     PD_RETURNDEFAULT = &H400
  236.     PD_SHOWHELP = &H800
  237.     PD_ENABLEPRINTHOOK = &H1000
  238.     PD_ENABLESETUPHOOK = &H2000
  239.     PD_ENABLEPRINTTEMPLATE = &H4000
  240.     PD_ENABLESETUPTEMPLATE = &H8000
  241.     PD_ENABLEPRINTTEMPLATEHANDLE = &H10000
  242.     PD_ENABLESETUPTEMPLATEHANDLE = &H20000
  243.     PD_USEDEVMODECOPIES = &H40000
  244.     PD_USEDEVMODECOPIESANDCOLLATE = &H40000
  245.     PD_DISABLEPRINTTOFILE = &H80000
  246.     PD_HIDEPRINTTOFILE = &H100000
  247.     PD_NONETWORKBUTTON = &H200000
  248. End Enum
  249.  
  250. Private Type DEVNAMES
  251.     wDriverOffset As Integer
  252.     wDeviceOffset As Integer
  253.     wOutputOffset As Integer
  254.     wDefault As Integer
  255. End Type
  256.  
  257. Private Const CCHDEVICENAME = 32
  258. Private Const CCHFORMNAME = 32
  259. Private Type DevMode
  260.     dmDeviceName As String * CCHDEVICENAME
  261.     dmSpecVersion As Integer
  262.     dmDriverVersion As Integer
  263.     dmSize As Integer
  264.     dmDriverExtra As Integer
  265.     dmFields As Long
  266.     dmOrientation As Integer
  267.     dmPaperSize As Integer
  268.     dmPaperLength As Integer
  269.     dmPaperWidth As Integer
  270.     dmScale As Integer
  271.     dmCopies As Integer
  272.     dmDefaultSource As Integer
  273.     dmPrintQuality As Integer
  274.     dmColor As Integer
  275.     dmDuplex As Integer
  276.     dmYResolution As Integer
  277.     dmTTOption As Integer
  278.     dmCollate As Integer
  279.     dmFormName As String * CCHFORMNAME
  280.     dmUnusedPadding As Integer
  281.     dmBitsPerPel As Integer
  282.     dmPelsWidth As Long
  283.     dmPelsHeight As Long
  284.     dmDisplayFlags As Long
  285.     dmDisplayFrequency As Long
  286. End Type
  287.  
  288. ' New Win95 Page Setup dialogs are up to you
  289. Private Type POINTL
  290.     x As Long
  291.     y As Long
  292. End Type
  293. Private Type RECT
  294.     Left As Long
  295.     TOp As Long
  296.     Right As Long
  297.     Bottom As Long
  298. End Type
  299.  
  300.  
  301. Private Type TPAGESETUPDLG
  302.     lStructSize                 As Long
  303.     hWndOwner                   As Long
  304.     hDevMode                    As Long
  305.     hDevNames                   As Long
  306.     flags                       As Long
  307.     ptPaperSize                 As POINTL
  308.     rtMinMargin                 As RECT
  309.     rtMargin                    As RECT
  310.     hInstance                   As Long
  311.     lCustData                   As Long
  312.     lpfnPageSetupHook           As Long
  313.     lpfnPagePaintHook           As Long
  314.     lpPageSetupTemplateName     As Long
  315.     hPageSetupTemplate          As Long
  316. End Type
  317.  
  318. ' EPaperSize constants same as vbPRPS constants
  319. Public Enum EPaperSize
  320.     epsLetter = 1          ' Letter, 8 1/2 x 11 in.
  321.     epsLetterSmall         ' Letter Small, 8 1/2 x 11 in.
  322.     epsTabloid             ' Tabloid, 11 x 17 in.
  323.     epsLedger              ' Ledger, 17 x 11 in.
  324.     epsLegal               ' Legal, 8 1/2 x 14 in.
  325.     epsStatement           ' Statement, 5 1/2 x 8 1/2 in.
  326.     epsExecutive           ' Executive, 7 1/2 x 10 1/2 in.
  327.     epsA3                  ' A3, 297 x 420 mm
  328.     epsA4                  ' A4, 210 x 297 mm
  329.     epsA4Small             ' A4 Small, 210 x 297 mm
  330.     epsA5                  ' A5, 148 x 210 mm
  331.     epsB4                  ' B4, 250 x 354 mm
  332.     epsB5                  ' B5, 182 x 257 mm
  333.     epsFolio               ' Folio, 8 1/2 x 13 in.
  334.     epsQuarto              ' Quarto, 215 x 275 mm
  335.     eps10x14               ' 10 x 14 in.
  336.     eps11x17               ' 11 x 17 in.
  337.     epsNote                ' Note, 8 1/2 x 11 in.
  338.     epsEnv9                ' Envelope #9, 3 7/8 x 8 7/8 in.
  339.     epsEnv10               ' Envelope #10, 4 1/8 x 9 1/2 in.
  340.     epsEnv11               ' Envelope #11, 4 1/2 x 10 3/8 in.
  341.     epsEnv12               ' Envelope #12, 4 1/2 x 11 in.
  342.     epsEnv14               ' Envelope #14, 5 x 11 1/2 in.
  343.     epsCSheet              ' C size sheet
  344.     epsDSheet              ' D size sheet
  345.     epsESheet              ' E size sheet
  346.     epsEnvDL               ' Envelope DL, 110 x 220 mm
  347.     epsEnvC3               ' Envelope C3, 324 x 458 mm
  348.     epsEnvC4               ' Envelope C4, 229 x 324 mm
  349.     epsEnvC5               ' Envelope C5, 162 x 229 mm
  350.     epsEnvC6               ' Envelope C6, 114 x 162 mm
  351.     epsEnvC65              ' Envelope C65, 114 x 229 mm
  352.     epsEnvB4               ' Envelope B4, 250 x 353 mm
  353.     epsEnvB5               ' Envelope B5, 176 x 250 mm
  354.     epsEnvB6               ' Envelope B6, 176 x 125 mm
  355.     epsEnvItaly            ' Envelope, 110 x 230 mm
  356.     epsenvmonarch          ' Envelope Monarch, 3 7/8 x 7 1/2 in.
  357.     epsEnvPersonal         ' Envelope, 3 5/8 x 6 1/2 in.
  358.     epsFanfoldUS           ' U.S. Standard Fanfold, 14 7/8 x 11 in.
  359.     epsFanfoldStdGerman    ' German Standard Fanfold, 8 1/2 x 12 in.
  360.     epsFanfoldLglGerman    ' German Legal Fanfold, 8 1/2 x 13 in.
  361.     epsUser = 256          ' User-defined
  362. End Enum
  363.  
  364. ' EPrintQuality constants same as vbPRPQ constants
  365. Public Enum EPrintQuality
  366.     epqDraft = -1
  367.     epqLow = -2
  368.     epqMedium = -3
  369.     epqHigh = -4
  370. End Enum
  371.  
  372. Public Enum EOrientation
  373.     eoPortrait = 1
  374.     eoLandscape
  375. End Enum
  376.  
  377. Private Declare Function PageSetupDlg Lib "COMDLG32" _
  378.     Alias "PageSetupDlgA" (lppage As TPAGESETUPDLG) As Boolean
  379.  
  380. Public Enum EPageSetup
  381.     PSD_Defaultminmargins = &H0 ' Default (printer's)
  382.     PSD_InWinIniIntlMeasure = &H0
  383.     PSD_MINMARGINS = &H1
  384.     PSD_MARGINS = &H2
  385.     PSD_INTHOUSANDTHSOFINCHES = &H4
  386.     PSD_INHUNDREDTHSOFMILLIMETERS = &H8
  387.     PSD_DISABLEMARGINS = &H10
  388.     PSD_DISABLEPRINTER = &H20
  389.     PSD_NoWarning = &H80
  390.     PSD_DISABLEORIENTATION = &H100
  391.     PSD_ReturnDefault = &H400
  392.     PSD_DISABLEPAPER = &H200
  393.     PSD_ShowHelp = &H800
  394.     PSD_EnablePageSetupHook = &H2000
  395.     PSD_EnablePageSetupTemplate = &H8000
  396.     PSD_EnablePageSetupTemplateHandle = &H20000
  397.     PSD_EnablePagePaintHook = &H40000
  398.     PSD_DisablePagePainting = &H80000
  399. End Enum
  400.  
  401. Public Enum EPageSetupUnits
  402.     epsuInches
  403.     epsuMillimeters
  404. End Enum
  405.  
  406. ' Common dialog errors
  407.  
  408. Private Declare Function CommDlgExtendedError Lib "COMDLG32" () As Long
  409.  
  410. Public Enum EDialogError
  411.     CDERR_DIALOGFAILURE = &HFFFF
  412.  
  413.     CDERR_GENERALCODES = &H0
  414.     CDERR_STRUCTSIZE = &H1
  415.     CDERR_INITIALIZATION = &H2
  416.     CDERR_NOTEMPLATE = &H3
  417.     CDERR_NOHINSTANCE = &H4
  418.     CDERR_LOADSTRFAILURE = &H5
  419.     CDERR_FINDRESFAILURE = &H6
  420.     CDERR_LOADRESFAILURE = &H7
  421.     CDERR_LOCKRESFAILURE = &H8
  422.     CDERR_MEMALLOCFAILURE = &H9
  423.     CDERR_MEMLOCKFAILURE = &HA
  424.     CDERR_NOHOOK = &HB
  425.     CDERR_REGISTERMSGFAIL = &HC
  426.  
  427.     PDERR_PRINTERCODES = &H1000
  428.     PDERR_SETUPFAILURE = &H1001
  429.     PDERR_PARSEFAILURE = &H1002
  430.     PDERR_RETDEFFAILURE = &H1003
  431.     PDERR_LOADDRVFAILURE = &H1004
  432.     PDERR_GETDEVMODEFAIL = &H1005
  433.     PDERR_INITFAILURE = &H1006
  434.     PDERR_NODEVICES = &H1007
  435.     PDERR_NODEFAULTPRN = &H1008
  436.     PDERR_DNDMMISMATCH = &H1009
  437.     PDERR_CREATEICFAILURE = &H100A
  438.     PDERR_PRINTERNOTFOUND = &H100B
  439.     PDERR_DEFAULTDIFFERENT = &H100C
  440.  
  441.     CFERR_CHOOSEFONTCODES = &H2000
  442.     CFERR_NOFONTS = &H2001
  443.     CFERR_MAXLESSTHANMIN = &H2002
  444.  
  445.     FNERR_FILENAMECODES = &H3000
  446.     FNERR_SUBCLASSFAILURE = &H3001
  447.     FNERR_INVALIDFILENAME = &H3002
  448.     FNERR_BUFFERTOOSMALL = &H3003
  449.  
  450.     CCERR_CHOOSECOLORCODES = &H5000
  451. End Enum
  452.  
  453. ' Array of custom colors lasts for life of app
  454. Private alCustom(0 To 15) As Long, fNotFirst As Boolean
  455.  
  456. Public Enum EPrintRange
  457.     eprAll
  458.     eprPageNumbers
  459.     eprSelection
  460. End Enum
  461. Private m_lApiReturn As Long
  462. Private m_lExtendedError As Long
  463. Private m_dvmode As DevMode
  464.  
  465. Public Property Get APIReturn() As Long
  466.     'return object's APIReturn property
  467.     APIReturn = m_lApiReturn
  468. End Property
  469. Public Property Get ExtendedError() As Long
  470.     'return object's ExtendedError property
  471.     ExtendedError = m_lExtendedError
  472. End Property
  473.  
  474. #If fComponent Then
  475. Private Sub Class_Initialize()
  476.     InitColors
  477. End Sub
  478. #End If
  479.  
  480. Function VBGetOpenFileName(Filename As String, _
  481.                            Optional FileTitle As String, _
  482.                            Optional FileMustExist As Boolean = True, _
  483.                            Optional MultiSelect As Boolean = False, _
  484.                            Optional ReadOnly As Boolean = False, _
  485.                            Optional HideReadOnly As Boolean = False, _
  486.                            Optional Filter As String = "All (*.*)| *.*", _
  487.                            Optional FilterIndex As Long = 1, _
  488.                            Optional InitDir As String, _
  489.                            Optional DlgTitle As String, _
  490.                            Optional DefaultExt As String, _
  491.                            Optional Owner As Long = -1, _
  492.                            Optional flags As Long = 0) As Boolean
  493.  
  494.     Dim opfile As OPENFILENAME, s As String, afFlags As Long
  495.     
  496.     m_lApiReturn = 0
  497.     m_lExtendedError = 0
  498.  
  499. With opfile
  500.     .lStructSize = Len(opfile)
  501.     
  502.     ' Add in specific flags and strip out non-VB flags
  503.     
  504.     .flags = (-FileMustExist * OFN_FILEMUSTEXIST) Or _
  505.             (-MultiSelect * OFN_ALLOWMULTISELECT) Or _
  506.              (-ReadOnly * OFN_READONLY) Or _
  507.              (-HideReadOnly * OFN_HIDEREADONLY) Or _
  508.              (flags And CLng(Not (OFN_ENABLEHOOK Or _
  509.                                   OFN_ENABLETEMPLATE)))
  510.     ' Owner can take handle of owning window
  511.     If Owner <> -1 Then .hWndOwner = Owner
  512.     ' InitDir can take initial directory string
  513.     .lpstrInitialDir = InitDir
  514.     ' DefaultExt can take default extension
  515.     .lpstrDefExt = DefaultExt
  516.     ' DlgTitle can take dialog box title
  517.     .lpstrTitle = DlgTitle
  518.     
  519.     ' To make Windows-style filter, replace | and : with nulls
  520.     Dim ch As String, i As Integer
  521.     For i = 1 To Len(Filter)
  522.         ch = Mid$(Filter, i, 1)
  523.         If ch = "|" Or ch = ":" Then
  524.             s = s & vbNullChar
  525.         Else
  526.             s = s & ch
  527.         End If
  528.     Next
  529.     ' Put double null at end
  530.     s = s & vbNullChar & vbNullChar
  531.     .lpstrFilter = s
  532.     .nFilterIndex = FilterIndex
  533.  
  534.     ' Pad file and file title buffers to maximum path
  535.     s = Filename & String$(MAX_PATH - Len(Filename), 0)
  536.     .lpstrFile = s
  537.     .nMaxFile = MAX_PATH
  538.     s = FileTitle & String$(MAX_FILE - Len(FileTitle), 0)
  539.     .lpstrFileTitle = s
  540.     .nMaxFileTitle = MAX_FILE
  541.     ' All other fields set to zero
  542.     
  543.     m_lApiReturn = GetOpenFileName(opfile)
  544.     Select Case m_lApiReturn
  545.     Case 1
  546.         ' Success
  547.         VBGetOpenFileName = True
  548.         Filename = StrZToStr(.lpstrFile)
  549.         FileTitle = StrZToStr(.lpstrFileTitle)
  550.         flags = .flags
  551.         ' Return the filter index
  552.         FilterIndex = .nFilterIndex
  553.         ' Look up the filter the user selected and return that
  554.         Filter = FilterLookup(.lpstrFilter, FilterIndex)
  555.         If (.flags And OFN_READONLY) Then ReadOnly = True
  556.     Case 0
  557.         ' Cancelled
  558.         VBGetOpenFileName = False
  559.         Filename = ""
  560.         FileTitle = ""
  561.         flags = 0
  562.         FilterIndex = -1
  563.         Filter = ""
  564.     Case Else
  565.         ' Extended error
  566.         m_lExtendedError = CommDlgExtendedError()
  567.         VBGetOpenFileName = False
  568.         Filename = ""
  569.         FileTitle = ""
  570.         flags = 0
  571.         FilterIndex = -1
  572.         Filter = ""
  573.     End Select
  574. End With
  575. End Function
  576. Private Function StrZToStr(s As String) As String
  577.     StrZToStr = Left$(s, lstrlen(s))
  578. End Function
  579.  
  580. Function VBGetSaveFileName(Filename As String, _
  581.                            Optional FileTitle As String, _
  582.                            Optional OverWritePrompt As Boolean = True, _
  583.                            Optional Filter As String = "All (*.*)| *.*", _
  584.                            Optional FilterIndex As Long = 1, _
  585.                            Optional InitDir As String, _
  586.                            Optional DlgTitle As String, _
  587.                            Optional DefaultExt As String, _
  588.                            Optional Owner As Long = -1, _
  589.                            Optional flags As Long) As Boolean
  590.             
  591.     Dim opfile As OPENFILENAME, s As String
  592.  
  593.     m_lApiReturn = 0
  594.     m_lExtendedError = 0
  595.  
  596. With opfile
  597.     .lStructSize = Len(opfile)
  598.     
  599.     ' Add in specific flags and strip out non-VB flags
  600.     .flags = (-OverWritePrompt * OFN_OVERWRITEPROMPT) Or _
  601.              OFN_HIDEREADONLY Or _
  602.              (flags And CLng(Not (OFN_ENABLEHOOK Or _
  603.                                   OFN_ENABLETEMPLATE)))
  604.     ' Owner can take handle of owning window
  605.     If Owner <> -1 Then .hWndOwner = Owner
  606.     ' InitDir can take initial directory string
  607.     .lpstrInitialDir = InitDir
  608.     ' DefaultExt can take default extension
  609.     .lpstrDefExt = DefaultExt
  610.     ' DlgTitle can take dialog box title
  611.     .lpstrTitle = DlgTitle
  612.     
  613.     ' Make new filter with bars (|) replacing nulls and double null at end
  614.     Dim ch As String, i As Integer
  615.     For i = 1 To Len(Filter)
  616.         ch = Mid$(Filter, i, 1)
  617.         If ch = "|" Or ch = ":" Then
  618.             s = s & vbNullChar
  619.         Else
  620.             s = s & ch
  621.         End If
  622.     Next
  623.     ' Put double null at end
  624.     s = s & vbNullChar & vbNullChar
  625.     .lpstrFilter = s
  626.     .nFilterIndex = FilterIndex
  627.  
  628.     ' Pad file and file title buffers to maximum path
  629.     s = Filename & String$(MAX_PATH - Len(Filename), 0)
  630.     .lpstrFile = s
  631.     .nMaxFile = MAX_PATH
  632.     s = FileTitle & String$(MAX_FILE - Len(FileTitle), 0)
  633.     .lpstrFileTitle = s
  634.     .nMaxFileTitle = MAX_FILE
  635.     ' All other fields zero
  636.     
  637.     m_lApiReturn = GetSaveFileName(opfile)
  638.     Select Case m_lApiReturn
  639.     Case 1
  640.         VBGetSaveFileName = True
  641.         Filename = StrZToStr(.lpstrFile)
  642.         FileTitle = StrZToStr(.lpstrFileTitle)
  643.         flags = .flags
  644.         ' Return the filter index
  645.         FilterIndex = .nFilterIndex
  646.         ' Look up the filter the user selected and return that
  647.         Filter = FilterLookup(.lpstrFilter, FilterIndex)
  648.     Case 0
  649.         ' Cancelled:
  650.         VBGetSaveFileName = False
  651.         Filename = ""
  652.         FileTitle = ""
  653.         flags = 0
  654.         FilterIndex = 0
  655.         Filter = ""
  656.     Case Else
  657.         ' Extended error:
  658.         VBGetSaveFileName = False
  659.         m_lExtendedError = CommDlgExtendedError()
  660.         Filename = ""
  661.         FileTitle = ""
  662.         flags = 0
  663.         FilterIndex = 0
  664.         Filter = ""
  665.     End Select
  666. End With
  667. End Function
  668.  
  669. Private Function FilterLookup(ByVal sFilters As String, ByVal iCur As Long) As String
  670.     Dim iStart As Long, iEnd As Long, s As String
  671.     iStart = 1
  672.     If sFilters = "" Then Exit Function
  673.     Do
  674.         ' Cut out both parts marked by null character
  675.         iEnd = InStr(iStart, sFilters, vbNullChar)
  676.         If iEnd = 0 Then Exit Function
  677.         iEnd = InStr(iEnd + 1, sFilters, vbNullChar)
  678.         If iEnd Then
  679.             s = Mid$(sFilters, iStart, iEnd - iStart)
  680.         Else
  681.             s = Mid$(sFilters, iStart)
  682.         End If
  683.         iStart = iEnd + 1
  684.         If iCur = 1 Then
  685.             FilterLookup = s
  686.             Exit Function
  687.         End If
  688.         iCur = iCur - 1
  689.     Loop While iCur
  690. End Function
  691.  
  692. Function VBGetFileTitle(sFile As String) As String
  693.     Dim sFileTitle As String, cFileTitle As Integer
  694.  
  695.     cFileTitle = MAX_PATH
  696.     sFileTitle = String$(MAX_PATH, 0)
  697.     cFileTitle = GetFileTitle(sFile, sFileTitle, MAX_PATH)
  698.     If cFileTitle Then
  699.         VBGetFileTitle = ""
  700.     Else
  701.         VBGetFileTitle = Left$(sFileTitle, InStr(sFileTitle, vbNullChar) - 1)
  702.     End If
  703.  
  704. End Function
  705.  
  706. ' ChooseColor wrapper
  707. Function VBChooseColor(Color As Long, _
  708.                        Optional AnyColor As Boolean = True, _
  709.                        Optional FullOpen As Boolean = False, _
  710.                        Optional DisableFullOpen As Boolean = False, _
  711.                        Optional Owner As Long = -1, _
  712.                        Optional flags As Long) As Boolean
  713.  
  714.     Dim chclr As TCHOOSECOLOR
  715.     chclr.lStructSize = Len(chclr)
  716.     
  717.     ' Color must get reference variable to receive result
  718.     ' Flags can get reference variable or constant with bit flags
  719.     ' Owner can take handle of owning window
  720.     If Owner <> -1 Then chclr.hWndOwner = Owner
  721.  
  722.     ' Assign color (default uninitialized value of zero is good default)
  723.     chclr.rgbResult = Color
  724.  
  725.     ' Mask out unwanted bits
  726.     Dim afMask As Long
  727.     afMask = CLng(Not (CC_ENABLEHOOK Or _
  728.                        CC_ENABLETEMPLATE))
  729.     ' Pass in flags
  730.     chclr.flags = afMask And (CC_RGBInit Or _
  731.                   IIf(AnyColor, CC_AnyColor, CC_SolidColor) Or _
  732.                   (-FullOpen * CC_FullOpen) Or _
  733.                   (-DisableFullOpen * CC_PreventFullOpen))
  734.  
  735.     ' If first time, initialize to white
  736.     If fNotFirst = False Then InitColors
  737.  
  738.     chclr.lpCustColors = VarPtr(alCustom(0))
  739.     ' All other fields zero
  740.     
  741.     m_lApiReturn = ChooseColor(chclr)
  742.     Select Case m_lApiReturn
  743.     Case 1
  744.         ' Success
  745.         VBChooseColor = True
  746.         Color = chclr.rgbResult
  747.     Case 0
  748.         ' Cancelled
  749.         VBChooseColor = False
  750.         Color = -1
  751.     Case Else
  752.         ' Extended error
  753.         m_lExtendedError = CommDlgExtendedError()
  754.         VBChooseColor = False
  755.         Color = -1
  756.     End Select
  757.  
  758. End Function
  759.  
  760. Private Sub InitColors()
  761.     Dim i As Integer
  762.     ' Initialize with first 16 system interface colors
  763.     For i = 0 To 15
  764.         alCustom(i) = GetSysColor(i)
  765.     Next
  766.     fNotFirst = True
  767. End Sub
  768.  
  769. ' Property to read or modify custom colors (use to save colors in registry)
  770. Public Property Get CustomColor(i As Integer) As Long
  771.     ' If first time, initialize to white
  772.     If fNotFirst = False Then InitColors
  773.     If i >= 0 And i <= 15 Then
  774.         CustomColor = alCustom(i)
  775.     Else
  776.         CustomColor = -1
  777.     End If
  778. End Property
  779.  
  780. Public Property Let CustomColor(i As Integer, iValue As Long)
  781.     ' If first time, initialize to system colors
  782.     If fNotFirst = False Then InitColors
  783.     If i >= 0 And i <= 15 Then
  784.         alCustom(i) = iValue
  785.     End If
  786. End Property
  787.  
  788. ' ChooseFont wrapper
  789. Function VBChooseFont(CurFont As Font, _
  790.                       Optional PrinterDC As Long = -1, _
  791.                       Optional Owner As Long = -1, _
  792.                       Optional Color As Long = vbBlack, _
  793.                       Optional MinSize As Long = 0, _
  794.                       Optional MaxSize As Long = 0, _
  795.                       Optional flags As Long = 0) As Boolean
  796.  
  797.     m_lApiReturn = 0
  798.     m_lExtendedError = 0
  799.  
  800.     ' Unwanted Flags bits
  801.     Const CF_FontNotSupported = CF_Apply Or CF_EnableHook Or CF_EnableTemplate
  802.     
  803.     ' Flags can get reference variable or constant with bit flags
  804.     ' PrinterDC can take printer DC
  805.     If PrinterDC = -1 Then
  806.         PrinterDC = 0
  807.         If flags And CF_PrinterFonts Then PrinterDC = Printer.hdc
  808.     Else
  809.         flags = flags Or CF_PrinterFonts
  810.     End If
  811.     ' Must have some fonts
  812.     If (flags And CF_PrinterFonts) = 0 Then flags = flags Or CF_ScreenFonts
  813.     ' Color can take initial color, receive chosen color
  814.     If Color <> vbBlack Then flags = flags Or CF_EFFECTS
  815.     ' MinSize can be minimum size accepted
  816.     If MinSize Then flags = flags Or CF_LimitSize
  817.     ' MaxSize can be maximum size accepted
  818.     If MaxSize Then flags = flags Or CF_LimitSize
  819.  
  820.     ' Put in required internal flags and remove unsupported
  821.     flags = (flags Or CF_InitToLogFontStruct) And Not CF_FontNotSupported
  822.     
  823.     ' Initialize LOGFONT variable
  824.     Dim fnt As LOGFONT
  825.     Const PointsPerTwip = 1440 / 72
  826.     fnt.lfHeight = -(CurFont.Size * (PointsPerTwip / Screen.TwipsPerPixelY))
  827.     fnt.lfWeight = CurFont.Weight
  828.     fnt.lfItalic = CurFont.Italic
  829.     fnt.lfUnderline = CurFont.Underline
  830.     fnt.lfStrikeOut = CurFont.Strikethrough
  831.     ' Other fields zero
  832.     StrToBytes fnt.lfFaceName, CurFont.Name
  833.  
  834.     ' Initialize TCHOOSEFONT variable
  835.     Dim cf As TCHOOSEFONT
  836.     cf.lStructSize = Len(cf)
  837.     If Owner <> -1 Then cf.hWndOwner = Owner
  838.     cf.hdc = PrinterDC
  839.     cf.lpLogFont = VarPtr(fnt)
  840.     cf.iPointSize = CurFont.Size * 10
  841.     cf.flags = flags
  842.     cf.rgbColors = Color
  843.     cf.nSizeMin = MinSize
  844.     cf.nSizeMax = MaxSize
  845.     
  846.     ' All other fields zero
  847.     m_lApiReturn = ChooseFont(cf)
  848.     Select Case m_lApiReturn
  849.     Case 1
  850.         ' Success
  851.         VBChooseFont = True
  852.         flags = cf.flags
  853.         Color = cf.rgbColors
  854.         CurFont.Bold = cf.nFontType And Bold_FontType
  855.         'CurFont.Italic = cf.nFontType And Italic_FontType
  856.         CurFont.Italic = fnt.lfItalic
  857.         CurFont.Strikethrough = fnt.lfStrikeOut
  858.         CurFont.Underline = fnt.lfUnderline
  859.         CurFont.Weight = fnt.lfWeight
  860.         CurFont.Size = cf.iPointSize / 10
  861.         CurFont.Name = BytesToStr(fnt.lfFaceName)
  862.     Case 0
  863.         ' Cancelled
  864.         VBChooseFont = False
  865.     Case Else
  866.         ' Extended error
  867.         m_lExtendedError = CommDlgExtendedError()
  868.         VBChooseFont = False
  869.     End Select
  870.         
  871. End Function
  872.  
  873. ' PrintDlg wrapper
  874. Function VBPrintDlg(hdc As Long, _
  875.                     Optional PrintRange As EPrintRange = eprAll, _
  876.                     Optional DisablePageNumbers As Boolean, _
  877.                     Optional FromPage As Long = 1, _
  878.                     Optional ToPage As Long = &HFFFF, _
  879.                     Optional DisableSelection As Boolean, _
  880.                     Optional Copies As Integer, _
  881.                     Optional ShowPrintToFile As Boolean, _
  882.                     Optional DisablePrintToFile As Boolean = True, _
  883.                     Optional PrintToFile As Boolean, _
  884.                     Optional Collate As Boolean, _
  885.                     Optional PreventWarning As Boolean, _
  886.                     Optional Owner As Long, _
  887.                     Optional Printer As Object, _
  888.                     Optional flags As Long) As Boolean
  889.     Dim afFlags As Long, afMask As Long
  890.     
  891.     m_lApiReturn = 0
  892.     m_lExtendedError = 0
  893.     
  894.     ' Set PRINTDLG flags
  895.     afFlags = (-DisablePageNumbers * PD_NOPAGENUMS) Or _
  896.               (-DisablePrintToFile * PD_DISABLEPRINTTOFILE) Or _
  897.               (-DisableSelection * PD_NOSELECTION) Or _
  898.               (-PrintToFile * PD_PRINTTOFILE) Or _
  899.               (-(Not ShowPrintToFile) * PD_HIDEPRINTTOFILE) Or _
  900.               (-PreventWarning * PD_NOWARNING) Or _
  901.               (-Collate * PD_COLLATE) Or _
  902.               PD_USEDEVMODECOPIESANDCOLLATE Or _
  903.               PD_RETURNDC
  904.     If PrintRange = eprPageNumbers Then
  905.         afFlags = afFlags Or PD_PAGENUMS
  906.     ElseIf PrintRange = eprSelection Then
  907.         afFlags = afFlags Or PD_SELECTION
  908.     End If
  909.     ' Mask out unwanted bits
  910.     afMask = CLng(Not (PD_ENABLEPRINTHOOK Or _
  911.                        PD_ENABLEPRINTTEMPLATE))
  912.     afMask = afMask And _
  913.              CLng(Not (PD_ENABLESETUPHOOK Or _
  914.                        PD_ENABLESETUPTEMPLATE))
  915.     
  916.     ' Fill in PRINTDLG structure
  917.     Dim pd As TPRINTDLG
  918.     pd.lStructSize = Len(pd)
  919.     pd.hWndOwner = Owner
  920.     pd.flags = afFlags And afMask
  921.     pd.nFromPage = FromPage
  922.     pd.nToPage = ToPage
  923.     pd.nMinPage = 1
  924.     pd.nMaxPage = &HFFFF
  925.     
  926.     ' Show Print dialog
  927.     m_lApiReturn = PrintDlg(pd)
  928.     Select Case m_lApiReturn
  929.     Case 1
  930.         VBPrintDlg = True
  931.         ' Return dialog values in parameters
  932.         hdc = pd.hdc
  933.         If (pd.flags And PD_PAGENUMS) Then
  934.             PrintRange = eprPageNumbers
  935.         ElseIf (pd.flags And PD_SELECTION) Then
  936.             PrintRange = eprSelection
  937.         Else
  938.             PrintRange = eprAll
  939.         End If
  940.         FromPage = pd.nFromPage
  941.         ToPage = pd.nToPage
  942.         PrintToFile = (pd.flags And PD_PRINTTOFILE)
  943.         ' Get DEVMODE structure from PRINTDLG
  944.         Dim pDevMode As Long
  945.         pDevMode = GlobalLock(pd.hDevMode)
  946.         CopyMemory m_dvmode, ByVal pDevMode, Len(m_dvmode)
  947.         Call GlobalUnlock(pd.hDevMode)
  948.         ' Get Copies and Collate settings from DEVMODE structure
  949.         Copies = m_dvmode.dmCopies
  950.         Collate = (m_dvmode.dmCollate = DMCOLLATE_TRUE)
  951.                 
  952.         ' Set default printer properties
  953.         On Error Resume Next
  954.         If Not (Printer Is Nothing) Then
  955.             Printer.Copies = Copies
  956.             Printer.Orientation = m_dvmode.dmOrientation
  957.             Printer.PaperSize = m_dvmode.dmPaperSize
  958.             Printer.PrintQuality = m_dvmode.dmPrintQuality
  959.         End If
  960.         On Error GoTo 0
  961.     Case 0
  962.         ' Cancelled
  963.         VBPrintDlg = False
  964.     Case Else
  965.         ' Extended error:
  966.         m_lExtendedError = CommDlgExtendedError()
  967.         VBPrintDlg = False
  968.     End Select
  969.     
  970. End Function
  971. Private Property Get DevMode() As DevMode
  972.     DevMode = m_dvmode
  973. End Property
  974.  
  975. ' PageSetupDlg wrapper
  976. Function VBPageSetupDlg(Optional Owner As Long, _
  977.                         Optional DisableMargins As Boolean, _
  978.                         Optional DisableOrientation As Boolean, _
  979.                         Optional DisablePaper As Boolean, _
  980.                         Optional DisablePrinter As Boolean, _
  981.                         Optional LeftMargin As Long, _
  982.                         Optional MinLeftMargin As Long, _
  983.                         Optional RightMargin As Long, _
  984.                         Optional MinRightMargin As Long, _
  985.                         Optional TopMargin As Long, _
  986.                         Optional MinTopMargin As Long, _
  987.                         Optional BottomMargin As Long, _
  988.                         Optional MinBottomMargin As Long, _
  989.                         Optional PaperSize As EPaperSize = epsLetter, _
  990.                         Optional Orientation As EOrientation = eoPortrait, _
  991.                         Optional PrintQuality As EPrintQuality = epqDraft, _
  992.                         Optional Units As EPageSetupUnits = epsuInches, _
  993.                         Optional Printer As Object, _
  994.                         Optional flags As Long) As Boolean
  995.     Dim afFlags As Long, afMask As Long
  996.         
  997.     m_lApiReturn = 0
  998.     m_lExtendedError = 0
  999.     ' Mask out unwanted bits
  1000.     afMask = Not (PSD_EnablePagePaintHook Or _
  1001.                   PSD_EnablePageSetupHook Or _
  1002.                   PSD_EnablePageSetupTemplate)
  1003.     ' Set TPAGESETUPDLG flags
  1004.     afFlags = (-DisableMargins * PSD_DISABLEMARGINS) Or _
  1005.               (-DisableOrientation * PSD_DISABLEORIENTATION) Or _
  1006.               (-DisablePaper * PSD_DISABLEPAPER) Or _
  1007.               (-DisablePrinter * PSD_DISABLEPRINTER) Or _
  1008.               PSD_MARGINS Or PSD_MINMARGINS And afMask
  1009.     Dim lUnits As Long
  1010.     If Units = epsuInches Then
  1011.         afFlags = afFlags Or PSD_INTHOUSANDTHSOFINCHES
  1012.         lUnits = 1000
  1013.     Else
  1014.         afFlags = afFlags Or PSD_INHUNDREDTHSOFMILLIMETERS
  1015.         lUnits = 100
  1016.     End If
  1017.     
  1018.     Dim psd As TPAGESETUPDLG
  1019.     ' Fill in PRINTDLG structure
  1020.     psd.lStructSize = Len(psd)
  1021.     psd.hWndOwner = Owner
  1022.     psd.rtMargin.TOp = TopMargin * lUnits
  1023.     psd.rtMargin.Left = LeftMargin * lUnits
  1024.     psd.rtMargin.Bottom = BottomMargin * lUnits
  1025.     psd.rtMargin.Right = RightMargin * lUnits
  1026.     psd.rtMinMargin.TOp = MinTopMargin * lUnits
  1027.     psd.rtMinMargin.Left = MinLeftMargin * lUnits
  1028.     psd.rtMinMargin.Bottom = MinBottomMargin * lUnits
  1029.     psd.rtMinMargin.Right = MinRightMargin * lUnits
  1030.     psd.flags = afFlags
  1031.     
  1032.     ' Show Print dialog
  1033.     If PageSetupDlg(psd) Then
  1034.         VBPageSetupDlg = True
  1035.         ' Return dialog values in parameters
  1036.         TopMargin = psd.rtMargin.TOp / lUnits
  1037.         LeftMargin = psd.rtMargin.Left / lUnits
  1038.         BottomMargin = psd.rtMargin.Bottom / lUnits
  1039.         RightMargin = psd.rtMargin.Right / lUnits
  1040.         MinTopMargin = psd.rtMinMargin.TOp / lUnits
  1041.         MinLeftMargin = psd.rtMinMargin.Left / lUnits
  1042.         MinBottomMargin = psd.rtMinMargin.Bottom / lUnits
  1043.         MinRightMargin = psd.rtMinMargin.Right / lUnits
  1044.         
  1045.         ' Get DEVMODE structure from PRINTDLG
  1046.         Dim dvmode As DevMode, pDevMode As Long
  1047.         pDevMode = GlobalLock(psd.hDevMode)
  1048.         CopyMemory dvmode, ByVal pDevMode, Len(dvmode)
  1049.         Call GlobalUnlock(psd.hDevMode)
  1050.         PaperSize = dvmode.dmPaperSize
  1051.         Orientation = dvmode.dmOrientation
  1052.         PrintQuality = dvmode.dmPrintQuality
  1053.         ' Set default printer properties
  1054.         On Error Resume Next
  1055.         If Not (Printer Is Nothing) Then
  1056.             Printer.Copies = dvmode.dmCopies
  1057.             Printer.Orientation = dvmode.dmOrientation
  1058.             Printer.PaperSize = dvmode.dmPaperSize
  1059.             Printer.PrintQuality = dvmode.dmPrintQuality
  1060.         End If
  1061.         On Error GoTo 0
  1062.     End If
  1063.  
  1064. End Function
  1065.  
  1066. #If fComponent = 0 Then
  1067. Private Sub ErrRaise(e As Long)
  1068.     Dim sText As String, sSource As String
  1069.     If e > 1000 Then
  1070.         sSource = App.EXEName & ".CommonDialog"
  1071.         Err.Raise COMError(e), sSource, sText
  1072.     Else
  1073.         ' Raise standard Visual Basic error
  1074.         sSource = App.EXEName & ".VBError"
  1075.         Err.Raise e, sSource
  1076.     End If
  1077. End Sub
  1078. #End If
  1079.  
  1080.  
  1081. Private Sub StrToBytes(ab() As Byte, s As String)
  1082.     If IsArrayEmpty(ab) Then
  1083.         ' Assign to empty array
  1084.         ab = StrConv(s, vbFromUnicode)
  1085.     Else
  1086.         Dim cab As Long
  1087.         ' Copy to existing array, padding or truncating if necessary
  1088.         cab = UBound(ab) - LBound(ab) + 1
  1089.         If Len(s) < cab Then s = s & String$(cab - Len(s), 0)
  1090.         'If UnicodeTypeLib Then
  1091.         '    Dim st As String
  1092.         '    st = StrConv(s, vbFromUnicode)
  1093.         '    CopyMemoryStr ab(LBound(ab)), st, cab
  1094.         'Else
  1095.             CopyMemoryStr ab(LBound(ab)), s, cab
  1096.         'End If
  1097.     End If
  1098. End Sub
  1099.  
  1100.  
  1101. Private Function BytesToStr(ab() As Byte) As String
  1102.     BytesToStr = StrConv(ab, vbUnicode)
  1103. End Function
  1104.  
  1105. Private Function COMError(e As Long) As Long
  1106.     COMError = e Or vbObjectError
  1107. End Function
  1108. '
  1109. Private Function IsArrayEmpty(va As Variant) As Boolean
  1110.     Dim v As Variant
  1111.     On Error Resume Next
  1112.     v = va(LBound(va))
  1113.     IsArrayEmpty = (Err <> 0)
  1114. End Function
  1115.  
  1116.  
  1117.  
  1118.