Option Explicit
Private wa As cWebArchive, WithEvents WS As cWebServer
Private wb, wbExt As VBControlExtender
Private WithEvents SC As cActiveScript
Private Sub Form_Load()
With New cIEFeatures
.FEATURE_BROWSER_EMULATION = Int(Val(.InstalledVersion)) 'elevate the Browser-Version from its default-version 7
End With
If App.LogMode = 0 Then 'as long as in IDE-Mode, we re-create the *.wac every time
Set wa = New_c.WebArchive
wa.ReadContentsFromDirectory App.Path & "\WebAppRoot"
wa.SaveContentsToArchiveFile App.Path & "\WebRoot.wac"
End If
Set wa = New_c.WebArchive(App.Path & "\WebRoot.wac") 'init the WA from the *.wac-Archive-File
Set WS = New_c.WebServer 'create an InProcess-WebServer-instance
WS.Listen App.Path & "\WebAppRoot", "127.0.0.1", 8888
InitBrowser "http://127.0.0.1:8888"
End Sub
Private Sub InitBrowser(Optional URL As String = "about
:blank")
Set wbExt = Controls.Add("Shell.Explorer.2", "wbExt") 'only after the above went through, are we allowed to create a BrowserControl
wbExt.Parent.Visible = True
wbExt.Move 0, 0, ScaleWidth, ScaleHeight
wbExt.Visible = True
Set wb = wbExt.object
wb.silent = True
wb.Navigate2 URL
Do Until wb.readyState = 4: DoEvents: Loop
End Sub
Private Sub Form_Resize()
If Not wbExt Is Nothing Then wbExt.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub WS_ProcessRequest(Request As vbRichClient5.cWebRequest)
Dim sURL As String: sURL = Request.URL
Select Case sURL
Case "", "/" 'a "naked" Root-URL-request (so we send the Start-(Home-)Page)
With New_c.ArrayList(vbString) 'let's build the html-response-string
.Add "<!DOCTYPE html>"
.Add "<html>"
.Add " <head>"
.Add " <title></title>"
.Add " </head>"
.Add " <style>"
.Add " body {text-align:center;}"
.Add " </style>"
.Add " <body bgcolor=""black"">"
.Add " <div id=""stl_cont"" style=""width:" & ScaleWidth - 30 & "px;height:" & ScaleHeight - 30 & "px;margin:0 auto;""></div>"
.Add " <script src=""stl_viewer.min.js""></script>"
.Add " <script>"
.Add " var stl_viewer=new StlViewer"
.Add " ("
.Add " document.getElementById(""stl_cont""), "
.Add " {"
.Add " models:"
.Add " [ "
.Add " {filename:""knot.stl"", display:""smooth""}"
.Add " ] "
.Add " }"
.Add " );"
.Add " </script>"
.Add " </body>"
.Add "</html>"
Request.Response.SetResponseDataBytes New_c.Crypt.VBStringToUTF8(.Join(vbLf)) 'send it to the Browser
End With
Case Else
Dim RelPath As String, B() As Byte
RelPath = Replace(IIf(Len(sURL), sURL, "index.html"), "/", "")
If Dir(Request.RootDirectory & RelPath, vbNormal) <> "" Then
Debug.Print Request.RootDirectory & RelPath
'B = wa.GetContent(RelPath) 'use the InMem-WebArchive to return the bytecontent of our Static-files
B = New_c.FSO.ReadByteContent(Request.RootDirectory & RelPath) 'alternative delivery of bytes from the FS
Request.Response.SetResponseDataBytes B
Else
Debug.Print "File not found: " & Request.RootDirectory & RelPath
End If
End Select
End Sub