home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / recurs1a / domtable.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-27  |  25.2 KB  |  686 lines

  1. VERSION 5.00
  2. Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "SHDOCVW.DLL"
  3. Begin VB.Form frmDOMTable 
  4.    Caption         =   "DOM Demo"
  5.    ClientHeight    =   3885
  6.    ClientLeft      =   60
  7.    ClientTop       =   630
  8.    ClientWidth     =   5940
  9.    LinkTopic       =   "Form1"
  10.    MDIChild        =   -1  'True
  11.    ScaleHeight     =   3885
  12.    ScaleWidth      =   5940
  13.    WindowState     =   2  'Maximized
  14.    Begin SHDocVwCtl.WebBrowser wbr 
  15.       Height          =   3675
  16.       Left            =   120
  17.       TabIndex        =   0
  18.       Top             =   120
  19.       Width           =   5715
  20.       ExtentX         =   10081
  21.       ExtentY         =   6482
  22.       ViewMode        =   1
  23.       Offline         =   0
  24.       Silent          =   0
  25.       RegisterAsBrowser=   0
  26.       RegisterAsDropTarget=   1
  27.       AutoArrange     =   -1  'True
  28.       NoClientEdge    =   0   'False
  29.       AlignLeft       =   0   'False
  30.       ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
  31.       Location        =   ""
  32.    End
  33.    Begin VB.Menu mnuFileMenu 
  34.       Caption         =   "&File"
  35.       Begin VB.Menu mnuFile 
  36.          Caption         =   "&HTML"
  37.          Index           =   0
  38.       End
  39.       Begin VB.Menu mnuFile 
  40.          Caption         =   "&Recurse"
  41.          Index           =   1
  42.       End
  43.       Begin VB.Menu mnuFile 
  44.          Caption         =   "S&tructure"
  45.          Index           =   2
  46.       End
  47.       Begin VB.Menu mnuFile 
  48.          Caption         =   "St&yle"
  49.          Index           =   3
  50.       End
  51.       Begin VB.Menu mnuFile 
  52.          Caption         =   "-"
  53.          Index           =   4
  54.       End
  55.       Begin VB.Menu mnuFile 
  56.          Caption         =   "Save &As..."
  57.          Index           =   5
  58.       End
  59.       Begin VB.Menu mnuFile 
  60.          Caption         =   "-"
  61.          Index           =   6
  62.       End
  63.       Begin VB.Menu mnuFile 
  64.          Caption         =   "Page Set&up..."
  65.          Index           =   7
  66.       End
  67.       Begin VB.Menu mnuFile 
  68.          Caption         =   "&Print..."
  69.          Index           =   8
  70.       End
  71.       Begin VB.Menu mnuFile 
  72.          Caption         =   "-"
  73.          Index           =   9
  74.       End
  75.       Begin VB.Menu mnuFile 
  76.          Caption         =   "&Close"
  77.          Index           =   10
  78.       End
  79.    End
  80.    Begin VB.Menu mnuDemoMenu 
  81.       Caption         =   "Demo"
  82.       Begin VB.Menu mnuDemo 
  83.          Caption         =   "Progress Display"
  84.          Index           =   0
  85.       End
  86.       Begin VB.Menu mnuDemo 
  87.          Caption         =   "Load Table"
  88.          Enabled         =   0   'False
  89.          Index           =   1
  90.       End
  91.       Begin VB.Menu mnuDemo 
  92.          Caption         =   "Show Table"
  93.          Enabled         =   0   'False
  94.          Index           =   2
  95.       End
  96.       Begin VB.Menu mnuDemo 
  97.          Caption         =   "Format"
  98.          Enabled         =   0   'False
  99.          Index           =   3
  100.       End
  101.       Begin VB.Menu mnuDemo 
  102.          Caption         =   "-"
  103.          Index           =   4
  104.       End
  105.       Begin VB.Menu mnuDemo 
  106.          Caption         =   "All"
  107.          Index           =   5
  108.       End
  109.    End
  110.    Begin VB.Menu mnuOptMenu 
  111.       Caption         =   "&Options"
  112.       Begin VB.Menu mnuOpt 
  113.          Caption         =   "&Format"
  114.          Index           =   0
  115.       End
  116.       Begin VB.Menu mnuOpt 
  117.          Caption         =   "&Background"
  118.          Index           =   1
  119.          Begin VB.Menu mnuBGround 
  120.             Caption         =   "&Blue binder"
  121.             Index           =   1
  122.          End
  123.          Begin VB.Menu mnuBGround 
  124.             Caption         =   "&Green binder"
  125.             Index           =   2
  126.          End
  127.       End
  128.       Begin VB.Menu mnuOpt 
  129.          Caption         =   "&Caption"
  130.          Index           =   2
  131.       End
  132.       Begin VB.Menu mnuOpt 
  133.          Caption         =   "-"
  134.          Index           =   3
  135.       End
  136.       Begin VB.Menu mnuOpt 
  137.          Caption         =   "Scroll Bar"
  138.          Index           =   4
  139.       End
  140.       Begin VB.Menu mnuOpt 
  141.          Caption         =   "-"
  142.          Index           =   5
  143.       End
  144.       Begin VB.Menu mnuOpt 
  145.          Caption         =   "Context Menu"
  146.          Index           =   6
  147.          Begin VB.Menu mnuContext 
  148.             Caption         =   "&Default"
  149.             Checked         =   -1  'True
  150.             Index           =   0
  151.          End
  152.          Begin VB.Menu mnuContext 
  153.             Caption         =   "&File"
  154.             Index           =   1
  155.          End
  156.          Begin VB.Menu mnuContext 
  157.             Caption         =   "&Options"
  158.             Index           =   2
  159.          End
  160.       End
  161.    End
  162. Attribute VB_Name = "frmDOMTable"
  163. Attribute VB_GlobalNameSpace = False
  164. Attribute VB_Creatable = False
  165. Attribute VB_PredeclaredId = True
  166. Attribute VB_Exposed = False
  167. Option Explicit
  168. ' DOMTable.frm  July 1999   contact markb@orionstudios.com
  169. ' Demonstrates DOM manipulation from Vb6 including
  170. '   build document in empty WebBrowser Control
  171. '   build DIV element as progress display
  172. '   build a Stylesheet
  173. '   convert tab-deliited text to HTML Table with
  174. '       Header, Footer, Caption, Column definitions
  175. '   enable/disable formatting
  176. '   replace standard context (right-click) popup menu
  177. '   set document title, table caption
  178. '   saving constructed document as HTML
  179. ' Requires Project/References entry for
  180. '   Microsoft HTML Object Library (MSHTML.tlb)
  181. '====================================================================================
  182. ' Module-level VARIABLES
  183. Private mDefaultPath As String      ' set in Form_Load
  184. Private mDataFileSpec As String     ' Name of tab-delimited data file
  185. Private mvarMDIParent As MDIForm    ' useful to access parent form - see StatusText
  186. Private mDemoDoc As MSHTML.HTMLDocument ' = wbr.document (see wbr_DocumentComplete)
  187. Private mDemoBody As MSHTML.HTMLBody    ' = wbr.document.body
  188. Private mTable As MSHTML.HTMLTable      ' returned from mListToHTML.FileToDOM
  189. Private mStyleSheet As MSHTML.HTMLStyleSheet    ' returned from BuildStyleSheet
  190. Private WithEvents mHTMLDocEvents As MSHTML.HTMLDocument    ' captures right-click
  191. Attribute mHTMLDocEvents.VB_VarHelpID = -1
  192. Private WithEvents mListToHTML As ListToHTML    ' converts mDataFileSpec to HTML
  193. Attribute mListToHTML.VB_VarHelpID = -1
  194. Private mContextOption As Long  ' current context menu selection
  195. ' Module-level variables for Progress Display
  196. Private mProgressDisplay As MSHTML.HTMLDivElement
  197. Private mProgressRow As MSHTML.IHTMLDOMTextNode
  198. Private mProgressBarStyle As MSHTML.HTMLStyle
  199. Private WithEvents mProgressCancel As MSHTML.HTMLButtonElement ' Life cycle = mListToHTML
  200. Attribute mProgressCancel.VB_VarHelpID = -1
  201. Private mTotalRows As Long  ' helps calculate percentage for progress Bar
  202. ' Module-level CONSTANTS
  203. Private Const START_HTML = "<BODY style=overflow:auto></BODY>"
  204. ' File Menu Constants
  205. Private Const FILE_HTML = 0
  206. Private Const FILE_RECURSE = 1
  207. Private Const FILE_STRUCTURE = 2
  208. Private Const FILE_STYLE = 3
  209. Private Const FILE_SAVEAS = 5
  210. Private Const FILE_PAGESETUP = 7
  211. Private Const FILE_PRINT = 8
  212. Private Const FILE_CLOSE = 10
  213. ' Demo menu constants
  214. Private Const DEMO_PROGRESS = 0
  215. Private Const DEMO_LOAD = 1
  216. Private Const DEMO_SHOW = 2
  217. Private Const DEMO_FORMAT = 3
  218. Private Const DEMO_ALL = 5
  219. ' Option menu constants
  220. Private Const OPT_FORMAT = 0
  221. Private Const OPT_BGROUND = 1
  222. Private Const OPT_CAPTION = 2
  223. Private Const OPT_SCROLL = 4
  224. ' Context menu constants
  225. Private Const CTX_DEFAULT = 0
  226. Private Const CTX_FILE = 1
  227. Private Const CTX_OPT = 2
  228. ' Background menu constants
  229. Private Const BG_BLUEBINDER = 1
  230. Private Const BG_GREENBINDER = 2
  231. ' Module-level Constants
  232. ' Relevant nodeType constants
  233. Private Const ELEMENT_NODE = 1
  234. Private Const TEXT_NODE = 3
  235. ' Browser navigation constants
  236. Private Const navNoHistory = 2
  237. Public Property Let DataFileSpec(ByVal vData As String)
  238.     mDataFileSpec = vData
  239. End Property
  240. Public Property Set MDIParent(vData As MDIForm) ' optional
  241.    Set mvarMDIParent = vData
  242. End Property
  243. Private Property Let StatusText(ByVal vData As String)
  244.     On Error Resume Next
  245.     If Not (mvarMDIParent Is Nothing) Then  ' property is optional
  246.         mvarMDIParent.StatusText = vData
  247.     End If
  248. End Property
  249. Private Sub Form_Load()
  250.     mDefaultPath = App.Path & "\"
  251.     mnuDemoMenu.Visible = False
  252.     mnuOptMenu.Visible = False
  253.     mnuOptMenu = False
  254.     wbr.Navigate URL:="about:" & START_HTML, Flags:=navNoHistory
  255. End Sub
  256. Private Sub Form_Resize()
  257.     On Error Resume Next
  258.     wbr.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
  259. End Sub
  260. Private Sub mnuFileMenu_Click()
  261.     Dim WbrDoc As MSHTML.HTMLDocument
  262.     Set WbrDoc = wbr.Document
  263.     mnuFile(FILE_STYLE) = WbrDoc.styleSheets.length
  264. End Sub
  265. Private Sub mnuFile_Click(Index As Integer)
  266.     On Error Resume Next    ' Some 'ExecWB' generate error for 'Cancel'
  267.     Dim strFileSpec As String
  268.     Dim WbrDoc As MSHTML.HTMLDocument
  269.     Set WbrDoc = wbr.Document   ' needed by most menu items
  270.     Select Case Index
  271.         
  272.         Case FILE_HTML
  273.         
  274.             With New frmDOMHTML
  275.                 .Show
  276.                 DoEvents
  277.                 .DisplayHTML HTMLDoc:=WbrDoc
  278.             End With
  279.             
  280.         Case FILE_RECURSE
  281.         
  282.             With New frmDOMRecurse
  283.                 .Show
  284.                 DoEvents
  285.                 .Recurse StartFromNode:=WbrDoc.getElementsByTagName("HTML")(0)
  286.             End With
  287.             
  288.         Case FILE_STRUCTURE
  289.             With New frmDOMTree
  290.                 Set .MDIParent = mvarMDIParent
  291.                 .Show
  292.                 DoEvents
  293.                 .DisplayDOMInfo HTMLDoc:=WbrDoc, InfoType:=domiTree
  294.             End With
  295.         
  296.         Case FILE_STYLE
  297.         
  298.             With New frmDOMTree
  299.                 Set .MDIParent = mvarMDIParent
  300.                 .Show
  301.                 DoEvents
  302.                 .DisplayDOMInfo HTMLDoc:=WbrDoc, InfoType:=domiStyle
  303.             End With
  304.             
  305.         
  306.         Case FILE_SAVEAS
  307.         
  308.             If SetDocTitle(HTMLDoc:=WbrDoc) Then    ' makes Title mandatory
  309.                 strFileSpec = FileSaveAs(HTMLDoc:=WbrDoc, OwnerHwnd:=Me.hWnd)
  310.                 If Len(strFileSpec) Then
  311.                     StatusText = "Document saved. Loading " & strFileSpec
  312.                     wbr.Navigate strFileSpec, navNoHistory
  313.                 End If
  314.             End If
  315.                 
  316.         Case FILE_PAGESETUP
  317.         
  318.             wbr.ExecWB _
  319.                 cmdid:=OLECMDID_PAGESETUP, _
  320.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  321.                 
  322.         Case FILE_PRINT
  323.         
  324.             wbr.ExecWB _
  325.                 cmdid:=OLECMDID_PRINT, _
  326.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  327.                
  328.         Case FILE_CLOSE
  329.         
  330.             Unload Me
  331.             
  332.     End Select
  333. End Sub
  334. Private Sub mnuDemo_Click(Index As Integer)
  335.     On Error GoTo mnuDemo_Error
  336.     StatusText = "mnuDemo(" & Index & ") - " & mnuDemo(Index).Caption
  337.     Select Case Index
  338.         Case DEMO_PROGRESS  ' Build Progress Display; note elements used in DEMO_LOAD
  339.         
  340.             Set mProgressDisplay = BuildProgressDisplay(HTMLDoc:=mDemoDoc)
  341.             mDemoBody.appendChild mProgressDisplay
  342.             With mDemoDoc
  343.                 Set mProgressRow = .getElementById("idRow").firstChild
  344.                 Set mProgressBarStyle = .getElementById("idBar").runtimeStyle
  345.             End With
  346.             mProgressDisplay.runtimeStyle.visibility = "visible"
  347.             
  348.         Case DEMO_LOAD  ' Load Table from DataFileSpec
  349.         
  350.             Set mListToHTML = New ListToHTML
  351.             Set mProgressCancel = mDemoDoc.getElementById("idCancel")
  352.             With mListToHTML
  353.                 .ProgressInterval = 10  ' default 5 - set low to test Cancel Button
  354.                 Set mTable = mListToHTML.FileToDOM( _
  355.                                 InFileName:=mDataFileSpec, _
  356.                                 HTMLDoc:=mDemoDoc, _
  357.                                 GetTotalRows:=True)
  358.             End With
  359.             Set mProgressCancel = Nothing   ' "de-activate" the cancel button
  360.             Set mListToHTML = Nothing
  361.             
  362.         Case DEMO_SHOW  ' Show Table in place of Progress Display
  363.         
  364.             mProgressDisplay.replaceNode replacement:=mTable
  365.             Set mProgressDisplay = Nothing
  366.         
  367.          Case DEMO_FORMAT  ' Create Stylesheet programmatically
  368.         
  369.             Set mStyleSheet = BuildStyleSheet(HTMLDoc:=mDemoDoc)
  370.             mnuOptMenu = Not (mStyleSheet Is Nothing)
  371.             mnuDemoMenu = Not mnuOptMenu
  372.             If mnuOptMenu Then
  373.                 mnuOpt_Click OPT_FORMAT
  374.                 StatusText = " Ready"
  375.             End If
  376.             
  377.        Case DEMO_ALL  ' All of the above
  378.         
  379.             AutoDemo
  380.         
  381.     End Select
  382. mnuDemo_Exit:
  383. ' Manipulate demo sequence
  384.     mnuDemo(Index) = False
  385.     If Index < DEMO_ALL Then
  386.         mnuDemo(Index + 1) = True
  387.     End If
  388.     mnuDemo(DEMO_ALL) = False
  389.     Exit Sub
  390. mnuDemo_Error:
  391.     MsgBox Err.Number & " - " & Err.Description, vbCritical, "ERROR in Demo Menu"
  392.     mnuDemoMenu = False ' bale out
  393. End Sub
  394. Private Sub mnuOptMenu_Click()
  395.     If Not (mTable.Caption Is Nothing) Then
  396.         mnuOpt(OPT_CAPTION).Checked = mTable.Caption.runtimeStyle.display = "inline"
  397.     End If
  398.     mnuOpt(OPT_BGROUND) = mnuOpt(OPT_FORMAT).Checked
  399. End Sub
  400. Private Sub mnuOpt_Click(Index As Integer)
  401.     On Error Resume Next
  402.     Select Case Index
  403.         Case OPT_FORMAT ' toggle application of stylesheet rules
  404.         
  405.             With mnuOpt(OPT_FORMAT)
  406.                 .Checked = Not .Checked
  407.                 mStyleSheet.disabled = Not .Checked
  408.             End With
  409.             
  410.         Case OPT_CAPTION    ' toggle display of table caption
  411.         
  412.             With mnuOpt(OPT_CAPTION)
  413.                 If mTable.Caption Is Nothing Then   'one chance only for demo
  414.                    .Checked = SetTableCaption(DOMTable:=mTable)
  415.                 Else
  416.                     .Checked = Not .Checked
  417.                     mTable.Caption.runtimeStyle.display = IIf(.Checked, "inline", "none")
  418.                 End If
  419.             End With
  420.             
  421.         Case OPT_SCROLL ' Show/Hide scrollbar (how to detect on/off when 'auto'??)
  422.         
  423.             With mnuOpt(OPT_SCROLL)
  424.                 .Checked = Not .Checked
  425.                 mDemoBody.runtimeStyle.overflow = IIf(.Checked, "auto", "visible")
  426.             End With
  427.             
  428.     End Select
  429. End Sub
  430. Private Sub mnuBGround_Click(Index As Integer)
  431.     mnuBGround(BG_BLUEBINDER).Checked = Index = BG_BLUEBINDER
  432.     mnuBGround(BG_GREENBINDER).Checked = Index = BG_GREENBINDER
  433.     mDemoBody.className = Choose(Index, "BlueBinder", "GreenBinder")
  434. End Sub
  435. Private Sub mnuContext_Click(Index As Integer)
  436. ' Monitor document for right-click if required (see mHTMLDocEvents_oncontextmenu)
  437.     mnuContext(CTX_DEFAULT).Checked = Index = CTX_DEFAULT
  438.     mnuContext(CTX_FILE).Checked = Index = CTX_FILE
  439.     mnuContext(CTX_OPT).Checked = Index = CTX_OPT
  440.     mContextOption = Index
  441.     Set mHTMLDocEvents = IIf(Index = CTX_DEFAULT, Nothing, mDemoDoc)
  442. End Sub
  443. Private Function BuildProgressDisplay( _
  444.             HTMLDoc As MSHTML.HTMLDocument) As MSHTML.HTMLDivElement
  445. ' This kind of thing would normally be specified within an HTML Template.
  446. ' It is coded here only to demonstrate the functions involved
  447. ' in programmatically adding objects to a document.
  448. ' NOTE: To demonstrate the difference between "xRuntimeStyle" and "xStyle"
  449. '       interchange them using ("x" prefix to prevent comment from changing)
  450. '           Edit/Replace (Current Procedure, Find Whole Word Only)
  451. '       and view results after "Demo/Progress Display" using the "File/HTML"
  452.     On Error GoTo BuildProgressDisplay_Error
  453.     Dim Result As MSHTML.HTMLDivElement    ' default function result = Nothing
  454.     Dim oCenterDIV As MSHTML.HTMLDivElement
  455.     Dim oIdSPAN As MSHTML.HTMLSpanElement   ' used for cloning
  456. ' Create node for cloning (TextNode has no ID property)
  457.     Set oIdSPAN = HTMLDoc.createElement("SPAN")
  458.     oIdSPAN.appendChild HTMLDoc.createTextNode("?")
  459. ' Create primary container for progress display (returned as function result)
  460.     Set oCenterDIV = HTMLDoc.createElement("DIV")
  461.     With oCenterDIV.runtimeStyle
  462.         .TextAlign = "center"
  463.         .visibility = "hidden"
  464.     End With
  465. ' Text Display
  466.     With oCenterDIV.appendChild(HTMLDoc.createElement("DIV"))
  467.         With .runtimeStyle
  468.             .Font = "16pt serif"
  469.             .Color = "black"
  470.         End With
  471.         .appendChild HTMLDoc.createTextNode("Converting row ")
  472.         With .appendChild(oIdSPAN.cloneNode(True))
  473.             .id = "idRow"
  474.             With .runtimeStyle
  475.                 .Color = "blue"
  476.                 .textDecorationUnderline = True
  477.             End With
  478.         End With
  479.         .appendChild HTMLDoc.createTextNode(" of ")
  480.         .appendChild(oIdSPAN.cloneNode(True)).id = "idRows"
  481.         .appendChild HTMLDoc.createTextNode(" rows ( ")
  482.         .appendChild(oIdSPAN.cloneNode(True)).id = "idCols"
  483.         .appendChild HTMLDoc.createTextNode(" columns )")
  484.     End With
  485.     oCenterDIV.appendChild HTMLDoc.createElement("BR")
  486. ' Progress Bar
  487.     With oCenterDIV.appendChild(HTMLDoc.createElement("DIV"))
  488.         With .runtimeStyle
  489.             .Width = "80%"
  490.             .TextAlign = "left"
  491.             .border = "3px outset"
  492.         End With
  493.         With .appendChild(HTMLDoc.createElement("SPAN"))
  494.             .id = "idBar"
  495.             With .runtimeStyle
  496.                 .Width = "1px"
  497.                 .backgroundColor = "blue"
  498.             End With
  499.         End With
  500.     End With
  501.     oCenterDIV.appendChild HTMLDoc.createElement("BR")
  502. ' Cancel Button
  503.     With oCenterDIV.appendChild(HTMLDoc.createElement("BUTTON"))
  504.         .id = "idCancel"
  505.         .Value = " Cancel "
  506.         With .runtimeStyle
  507.             .backgroundColor = "red"
  508.             .Color = "white"
  509.             .fontWeight = "bold"
  510.             .border = "3px outset"
  511.         End With
  512.     End With
  513.     Set Result = oCenterDIV
  514. BuildProgressDisplay_Exit:
  515.     Set BuildProgressDisplay = Result
  516.     Exit Function
  517. BuildProgressDisplay_Error:
  518.     Set oCenterDIV = Nothing
  519.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, "BuildProgressDisplay"
  520.     Resume BuildProgressDisplay_Exit
  521. End Function
  522. Private Function BuildStyleSheet( _
  523.             HTMLDoc As MSHTML.HTMLDocument) As MSHTML.HTMLStyleSheet
  524.             
  525. ' A StyleSheet would normally be specified within an HTML Template.
  526. '   It is coded here only to demonstrate the functions involved
  527. '   in programmatically adding CSS rules to a document.
  528.     On Error GoTo BuildStyleSheet_Error
  529.     Dim Result As MSHTML.HTMLStyleSheet ' default function result = Nothing
  530.     Dim strImgPath As String
  531.     strImgPath = mDefaultPath & "Images\"
  532.     Set Result = HTMLDoc.createStyleSheet
  533.     With Result
  534.         .disabled = True
  535.         .addRule "BODY", "font:68% verdana,sans-serif;" _
  536.                     & "color:black;" _
  537.                     & "background-color:white;" _
  538.                     & "margin:4;"
  539.         .addRule "BODY.BlueBinder", "margin-left:80; " _
  540.                     & "background-image:url(" & strImgPath & "BlueBinder.gif);"
  541.         .addRule "BODY.GreenBinder", "margin-left:48;" _
  542.                     & "background-image:url(" & strImgPath & "GreenBinder.gif);"
  543.         .addRule "TABLE", "table-layout:auto"
  544.         .addRule "CAPTION", "font:180% 'Comic Sans MS'; color:red"
  545.         .addRule "COL.clText", "text-align:left"
  546.         .addRule "COL.clNum", "text-align:right"
  547.         .addRule "TR", "font-size:68%;vertical-align: text-top;" _
  548.                     & "color:#003498; background-color:#F0ECF0"
  549.         .addRule "TD", "padding:2 8"
  550.         .addRule "THEAD TR", "font:bold small-caps; background-color:#98CCFF"
  551.         .addRule "TFOOT TD", "background-color:#98CCFF; text-align:center"
  552.         .addRule "TD.clNumNeg", "color:red"
  553.     End With
  554. BuildStyleSheet_Exit:
  555.     Set BuildStyleSheet = Result
  556.     Exit Function
  557. BuildStyleSheet_Error:
  558.     Set Result = Nothing
  559.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, "BuildStyleSheet"
  560.     Resume BuildStyleSheet_Exit
  561. End Function
  562. Private Sub AutoDemo()
  563.     On Error GoTo AutoDemo_Exit
  564.     mnuDemoMenu = False
  565.     mnuDemo_Click DEMO_PROGRESS
  566.     mnuDemo_Click DEMO_LOAD
  567.     mnuDemo_Click DEMO_SHOW
  568.     mnuDemo_Click DEMO_FORMAT
  569. AutoDemo_Exit:
  570. End Sub
  571. Private Function SetTableCaption(DOMTable As MSHTML.HTMLTable) As Boolean
  572.     On Error GoTo SetTableCaption_Error
  573.     Dim strCaption As String
  574.     strCaption = InputBox( _
  575.             prompt:="Please enter a Heading for the Table.", _
  576.             Title:="HTML table heading?", _
  577.             Default:="(DOM Demo)")
  578.     If Len(strCaption) Then
  579.         With DOMTable.createCaption
  580.             .appendChild DOMTable.Document.createTextNode(strCaption)
  581.             .runtimeStyle.display = "inline"
  582.         End With
  583.     End If
  584. SetTableCaption_Exit:
  585.     SetTableCaption = Not (DOMTable.Caption Is Nothing)
  586.     Exit Function
  587. SetTableCaption_Error:
  588.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, "SetTableCaption"
  589.     Resume SetTableCaption_Exit
  590. End Function
  591. Private Function SetDocTitle(HTMLDoc As MSHTML.HTMLDocument) As Boolean
  592.     On Error GoTo SetDocTitle_Exit
  593.     Dim strTitle As String
  594.     strTitle = HTMLDoc.Title
  595.     If Len(strTitle) = 0 Then
  596.         strTitle = InputBox(prompt:="Please enter a Title for your HTML page.", _
  597.                 Title:="HTML page title?", _
  598.                 Default:=strTitle)
  599.         If Len(strTitle) Then
  600.             HTMLDoc.Title = strTitle
  601.         End If
  602.     End If
  603.     SetDocTitle = CBool(Len(strTitle))
  604. SetDocTitle_Exit:
  605. End Function
  606. Private Function FileSaveAs(HTMLDoc As MSHTML.HTMLDocument, _
  607.                             OwnerHwnd As Long) As String
  608. ' Returns full path of saved file. Uses FileDlg.cls.
  609.     On Error GoTo FileSaveAs_Error
  610.     Dim Result As String    ' default function result = ""
  611.     Dim strFileName As String
  612.     Dim oHTML  As MSHTML.HTMLHtmlElement
  613.     With New FileDlg
  614.         .DefaultDir = mDefaultPath & "Work"
  615.         .Owner = OwnerHwnd
  616.         .AddFilter "HTML Documents (*.htm,*html):*.htm;*html"
  617.         .DefaultFileExt = "htm"
  618.         If .Show(DlgType:=SaveAsDialog) Then
  619.             strFileName = .PathFile
  620.         End If
  621.     End With
  622.     DoEvents
  623.     If Len(strFileName) Then
  624.         With HTMLDoc.body  ' fudge on location of background images
  625.             If InStr(1, .className, "binder", vbTextCompare) Then
  626.                 .Style.backgroundImage = "url(..\Images\" & .className & ".gif)"
  627.             End If
  628.         End With
  629.         
  630.         Set oHTML = HTMLDoc.getElementsByTagName("HTML")(0)
  631.         With New Scripting.FileSystemObject
  632.             With .CreateTextFile(FileName:=strFileName)
  633.                 .Write oHTML.outerHTML
  634.                 .Close
  635.             End With
  636.         End With
  637.         
  638.     End If
  639.     Result = strFileName
  640. FileSaveAs_Exit:
  641.     FileSaveAs = Result
  642.     Exit Function
  643. FileSaveAs_Error:
  644.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, "FileSaveAs"
  645.     Resume FileSaveAs_Exit
  646. End Function
  647. '   === Events ===
  648. Private Sub wbr_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  649.     If pDisp Is wbr.object Then
  650.         If InStr(1, URL, "about:", vbTextCompare) Then
  651.             Set mDemoDoc = wbr.Document
  652.             Set mDemoBody = mDemoDoc.body
  653.             mnuDemoMenu.Visible = True
  654.             mnuOptMenu.Visible = True
  655.         Else
  656.             mnuDemoMenu.Visible = False
  657.             mnuOptMenu.Visible = False
  658.             Me.Caption = wbr.Document.Title
  659.             StatusText = URL
  660.         End If
  661.     End If
  662. End Sub
  663. Private Function mHTMLDocEvents_oncontextmenu() As Boolean
  664. ' See mnuContext_Click. This Event Function is inactive (never called) while
  665. '                       (mHTMLDocEvents is Nothing) and (mContextOption = 0)
  666.     mHTMLDocEvents_oncontextmenu = False    ' cancel the default context menu
  667.     Me.PopupMenu Choose(mContextOption, mnuFileMenu, mnuOptMenu)
  668. End Function
  669. Private Sub mListToHTML_RowsCols(NumRows As Long, NumCols As Long) ' Once only
  670.     On Error Resume Next
  671.     With mDemoDoc
  672.         .getElementById("idRows").firstChild.nodeValue = NumRows
  673.         .getElementById("idCols").firstChild.nodeValue = NumCols
  674.     End With
  675.     mTotalRows = NumRows    ' keep to calculate percentage for progress Bar
  676. End Sub
  677. Private Sub mListToHTML_RowProgress(RowNum As Long) ' Frequency is ProgressInterval
  678.     On Error Resume Next
  679.     mProgressRow.Data = RowNum
  680.     mProgressBarStyle.Width = FormatPercent(RowNum / mTotalRows, 0)
  681.     DoEvents
  682. End Sub
  683. Private Function mProgressCancel_onclick() As Boolean
  684.     mListToHTML.Cancel = True   ' can be detected by ListToHTML instance
  685. End Function
  686.