home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / PolarDraw / data1.cab / Samples / Visual_Basic / AnalizeWebSite / AnalizeWebSite.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-08-31  |  12.3 KB  |  362 lines

  1. VERSION 5.00
  2. Object = "{52DE3A21-0A3F-11D4-B9D2-008048FD54E6}#2.0#0"; "POLARDraw20.ocx"
  3. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
  4. Begin VB.Form frmAnalyseWeb 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Analyse Web"
  7.    ClientHeight    =   8760
  8.    ClientLeft      =   150
  9.    ClientTop       =   435
  10.    ClientWidth     =   10695
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   8760
  15.    ScaleWidth      =   10695
  16.    Begin ComctlLib.Slider sldZoom 
  17.       Height          =   360
  18.       Left            =   0
  19.       TabIndex        =   7
  20.       Top             =   8250
  21.       Width           =   2355
  22.       _ExtentX        =   4154
  23.       _ExtentY        =   635
  24.       _Version        =   327682
  25.       Min             =   10
  26.       Max             =   500
  27.       SelStart        =   10
  28.       TickStyle       =   3
  29.       Value           =   10
  30.    End
  31.    Begin VB.DirListBox Dir1 
  32.       Height          =   2340
  33.       Left            =   15
  34.       TabIndex        =   3
  35.       Top             =   2520
  36.       Width           =   2055
  37.    End
  38.    Begin VB.FileListBox File1 
  39.       Height          =   2820
  40.       Left            =   15
  41.       Pattern         =   "*.htm"
  42.       TabIndex        =   2
  43.       Top             =   4905
  44.       Width           =   2085
  45.    End
  46.    Begin VB.DriveListBox Drive1 
  47.       Height          =   315
  48.       Left            =   15
  49.       TabIndex        =   1
  50.       Top             =   2190
  51.       Width           =   2055
  52.    End
  53.    Begin POLARDRAW20Lib.POLARDraw POLARDraw1 
  54.       Height          =   8655
  55.       Left            =   2445
  56.       TabIndex        =   0
  57.       Top             =   30
  58.       Width           =   8205
  59.       _Version        =   131072
  60.       _ExtentX        =   14473
  61.       _ExtentY        =   15266
  62.       _StockProps     =   224
  63.       Appearance      =   1
  64.       PaperShadowColor=   0
  65.       PaperOutlinecolor=   22899756
  66.       CurrentShapeType=   10000
  67.       DrawPaper       =   0   'False
  68.       DrawPaperOutline=   -1  'True
  69.       DrawPaperShadow =   -1  'True
  70.       PaperShadowOffset=   0
  71.       ViewportOriginX =   22899756
  72.       ViewportOriginY =   22873116
  73.       PageOriginX     =   1
  74.       PageOriginY     =   82384101
  75.       HorizontalGrid  =   567
  76.       VerticalGrid    =   567
  77.       ShowVerticalRuler=   0   'False
  78.       ShowHorizontalRuler=   0   'False
  79.       SelectionCount  =   22740992
  80.       ShapeCount      =   22742704
  81.       MeasurementUnits=   2
  82.       RulerMeasurementUnits=   2
  83.       CanvasWidth     =   536873485
  84.       CanvasHeight    =   0
  85.       AllowSelect     =   0   'False
  86.       AllowRotate     =   0   'False
  87.       AllowDelete     =   0   'False
  88.       AllowResize     =   0   'False
  89.       AllowMove       =   0   'False
  90.       AllowEditPoints =   0   'False
  91.       AllowDragSelect =   0   'False
  92.       ShowSelection   =   0   'False
  93.       AllowWheel      =   0   'False
  94.    End
  95.    Begin VB.Label Label2 
  96.       Caption         =   "Click left mouse button to follow the link, or the right mouse button just to see the location to follow"
  97.       Height          =   825
  98.       Left            =   45
  99.       TabIndex        =   6
  100.       Top             =   1140
  101.       Width           =   2265
  102.    End
  103.    Begin VB.Label lblZoom 
  104.       Caption         =   "Label2"
  105.       Height          =   315
  106.       Left            =   0
  107.       TabIndex        =   5
  108.       Top             =   7875
  109.       Width           =   2220
  110.    End
  111.    Begin VB.Label Label1 
  112.       Caption         =   "Choose the HTML page. Polar Draw will show you all links this page contains."
  113.       Height          =   750
  114.       Left            =   60
  115.       TabIndex        =   4
  116.       Top             =   285
  117.       Width           =   2295
  118.    End
  119.    Begin VB.Menu mnuPopup 
  120.       Caption         =   ""
  121.       Visible         =   0   'False
  122.       Begin VB.Menu mnuAddressInfo 
  123.          Caption         =   ""
  124.       End
  125.    End
  126. Attribute VB_Name = "frmAnalyseWeb"
  127. Attribute VB_GlobalNameSpace = False
  128. Attribute VB_Creatable = False
  129. Attribute VB_PredeclaredId = True
  130. Attribute VB_Exposed = False
  131. Dim pd_shapes As POLARDRAW20Lib.Shapes
  132. Dim pd_page As POLARDRAW20Lib.Page
  133. Dim pd_shape0 As POLARDRAW20Lib.Shape
  134. Private Sub Drive1_Change()
  135.     Dir1.Path = Drive1.Drive
  136. End Sub
  137. Private Sub Dir1_Change()
  138.     File1.Path = Dir1.Path
  139. End Sub
  140. Private Sub File1_Click()
  141. 'When user chooses the file, Polar Draw dispalys that file as a shape and
  142. 'creates a diagram showing all references to other pages that this HTML
  143. 'page contains
  144.     Dim nameLink As String
  145.     nameLink = File1.FileName
  146.     POLARDraw1.EnableRendering = False
  147.     pd_shapes.Delete
  148.     Dim pd_hyper As POLARDRAW20Lib.Hyperlink
  149.     Set pd_shape0 = pd_shapes.Add(polRoundRectangle, 0, 0, 30, 8)
  150.     With pd_shape0
  151.       .Fill.Type = polSolidColor
  152.       .Fill.Color = RGB(224, 82, 56)
  153.       .Line.Color = .Fill.Color
  154.       .IsFilled = True
  155.     End With
  156.     Set pd_hyper = pd_shape0.AddHyperlink
  157.     With pd_hyper
  158.         .ShowHandCursor = True
  159.         
  160.         If Dir1.Path = "C:\" Or Dir1.Path = "c:\" Then
  161.           POLARDraw1.HyperlinkBase = Dir1.Path
  162.           .Address = Dir1.Path + File1.FileName
  163.         Else
  164.           POLARDraw1.HyperlinkBase = Dir1.Path + "\"
  165.           .Address = Dir1.Path + "\" + File1.FileName
  166.         End If
  167.     End With
  168.     Set_Font (pd_shape0.ID)
  169.     pd_shape0.Text.Plain = nameLink
  170.     List
  171.     pd_shapes.SelectAll
  172.     POLARDraw1.ActiveWindow.FitTo polFitToSelection
  173.     POLARDraw1.Zoom = 100
  174.     RefreshZoomSlider
  175.     POLARDraw1.EnableRendering = True
  176.     POLARDraw1.Render
  177.     Set pd_hyper = Nothing
  178. End Sub
  179. Private Sub Form_Load()
  180.     Set pd_shapes = POLARDraw1.ActivePage.Shapes
  181.     POLARDraw1.ActiveWindow.CenterPage
  182.     POLARDraw1.MeasurementUnits = polUnitsMilimeter
  183.     RefreshZoomSlider
  184. End Sub
  185. Private Sub Form_Unload(Cancel As Integer)
  186.     Set pd_shapes = Nothing
  187.     Set pd_page = Nothing
  188.     Set pd_shape0 = Nothing
  189. End Sub
  190. Private Sub POLARDraw1_HyperlinkClicked(ByVal lShapeID As Long, ByVal nButton As Integer, ByVal nMask As Integer)
  191.     If pd_shapes.ItemFromID(lShapeID).Hyperlink Is Nothing Then MsgBox "Error: Not a hyperlink!!!"
  192.     If pd_shapes.ItemFromID(lShapeID).IsLink = True Then Exit Sub
  193.     Select Case nButton
  194.       Case vbRightButton
  195.          'just show the location
  196.          mnuAddressInfo.Caption = POLARDraw1.HyperlinkBase + pd_shapes.ItemFromID(lShapeID).Hyperlink.Address
  197.          Me.PopupMenu mnuPopup
  198.       
  199.       Case vbLeftButton
  200.          'follow hyperlink
  201.          With pd_shapes.ItemFromID(lShapeID)
  202.             .Hyperlink.Follow
  203.             'formatting to 'visited' color
  204.             .Fill.Color = RGB(244, 155, 173)
  205.             .Line.Color = .Fill.Color
  206.          End With
  207.    End Select
  208. End Sub
  209. Private Sub List()
  210. 'This function searches through the main shape, findes
  211. 'references to other pages and displays them as shapes
  212. If pd_shape0.Hyperlink Is Nothing Then Exit Sub
  213. Dim pathHtml, newLink As String
  214. Dim tsLine As String
  215. Dim numLine, numEndAHref As Integer
  216. Dim numLink, recID As Long
  217. Dim numAHref As Variant
  218. Const endLink = ">"
  219. Const beginLink = "a href"
  220. Dim Dist As Long  'distance between shapes
  221. Dist = pd_shape0.Height / 4
  222. Dim lLeft As Long, lRight As Long, lTop As Long, lBottom As Long
  223. Dim lSgn As Integer
  224. lSgn = 1
  225. numLink = 0
  226. pathHtml = pd_shape0.Hyperlink.Address
  227. Dim fso As New FileSystemObject
  228. Dim theFile As TextStream
  229. 'creating FS object - HTML file that will be searched
  230. Set fso = CreateObject("Scripting.FileSystemObject")
  231. Set theFile = fso.OpenTextFile(pathHtml, ForReading, False)
  232. Dim lWarningsCount As Long
  233. lWarningsCount = 0
  234. 'MergeStrings flag will be used to merge previous and next line
  235. 'in case the link <a href = ".....">....</a> wasn't completed in one line
  236. Dim tempStr As String
  237. Dim MergeStrings As Boolean
  238. tempStr = ""
  239. MergeStrings = False
  240. Dim counter As Long
  241. counter = 0
  242. Do While theFile.AtEndOfStream <> True
  243. 'we are taking just one line and search through it
  244.     tsLine = theFile.ReadLine
  245.     If MergeStrings Then tsLine = tsLine + tempStr
  246.     numAHref = InStr(1, tsLine, beginLink, vbTextCompare)
  247.     While numAHref <> 0
  248.       'search through one line until any reference to another page is found
  249.       Dim posLinkStart As Long
  250.       posLinkStart = 0
  251.       posLinkStart = InStr(numAHref, tsLine, "=", vbTextCompare) + 1
  252.       
  253.       If posLinkStart < numAHref Then
  254.          posLinkStart = numAHref
  255.       End If
  256.       
  257.       numEndAHref = InStr(posLinkStart, tsLine, endLink, vbTextCompare) - 1
  258.             
  259.       If numEndAHref = -1 Then
  260.          'in case that line doesn't contain whole link
  261.          tempStr = Mid(tsLine, numAHref)
  262.          MergeStrings = True
  263.          numAHref = 0
  264.       
  265.          
  266.       Else
  267.          newLink = Mid$(tsLine, posLinkStart, numEndAHref - posLinkStart)
  268.          Dim lWidth As Long
  269.          lWidth = Calculate(newLink)
  270.          MergeStrings = False
  271.          tempStr = ""
  272.          
  273.          counter = counter + 1
  274.          lSgn = -lSgn
  275.          lLeft = pd_shape0.Right + 4 * Dist
  276.          lRight = lLeft + lWidth
  277.          lTop = pd_shape0.Top + lSgn * ((counter / 2) * (pd_shape0.Height + Dist))
  278.          lBottom = lTop + pd_shape0.Height
  279.          
  280.          Rectangle newLink, lLeft, lTop, lRight, lBottom
  281.          tsLine = Mid(tsLine, numEndAHref)
  282.          numAHref = InStr(1, tsLine, beginLink, vbTextCompare)
  283.          
  284.          lWarningsCount = lWarningsCount + 1
  285.          If lWarningsCount > 19 Then
  286.             POLARDraw1.EnableRendering = True
  287.             POLARDraw1.Render
  288.             POLARDraw1.EnableRendering = False
  289.             
  290.             If MsgBox("There are more than " + CStr(counter) + " links on this page! If you want to continue, please press OK.", vbOKCancel) = vbOK Then
  291.                lWarningsCount = 0
  292.             Else
  293.                Exit Do
  294.             End If
  295.          End If
  296.       End If
  297.     Wend
  298.  Loop
  299. End Sub
  300. Private Sub Set_Font(lShapeID As Long)
  301.    Dim fnt As POLARDRAW20Lib.Font
  302.    Set fnt = pd_shapes.ItemFromID(lShapeID).Text.Font
  303.    With fnt
  304.        .Size = 8
  305.        .Bold = False
  306.        .Underline = True
  307.        .Name = "Arial"
  308.    End With
  309.    Set fnt = Nothing
  310. End Sub
  311. Private Sub Rectangle(Link As String, Left As Long, ByVal Top As Long, Right As Long, ByVal Bottom As Long)
  312.  'This Sub creates new shapes which represent reference to other shapes
  313.    Dim pd_shape1 As POLARDRAW20Lib.Shape  'new shape
  314.    Dim pd_shape_line As POLARDRAW20Lib.Shape 'link between shape0 and others
  315.    Dim pd_hyper As POLARDRAW20Lib.Hyperlink  'hyperlink of the new shape
  316.    Set pd_shape1 = pd_shapes.Add(polRoundRectangle, Left, Top, Right, Bottom)
  317.    Set_Font (pd_shape1.ID)
  318.    pd_shape1.Text.Plain = Link
  319.    Set pd_hyper = pd_shape1.AddHyperlink
  320.    With pd_hyper
  321.         .Address = Link
  322.         .ShowHandCursor = True
  323.    End With
  324.    Select Case Link
  325.     Case ""
  326.         pd_shape1.Hyperlink.Address = Dir1.Path + "\" + Link
  327.     Case "\"
  328.         pd_shape1.Hyperlink.Address = Dir1.Path + Link
  329.     Case "http"
  330.         pd_shape1.Hyperlink.Address = Link
  331.    End Select
  332.    Set pd_shape_line = pd_shapes.AddConnection(pd_shape0.ID, pd_shape1.ID)
  333.    With pd_shape_line.Connection
  334.       
  335.       .SourceConnect pd_shape0.ID, 4
  336.       .DestinationConnect pd_shape1.ID, 8
  337.    End With
  338.       
  339.    pd_shape_line.ZOrder polSendToBack
  340.    RefreshZoomSlider
  341.    Set pd_shape1 = Nothing
  342.    Set pd_shape_line = Nothing
  343.    Set pd_hyper = Nothing
  344. End Sub
  345. Private Sub sldZoom_Scroll()
  346.     'Changing slider value affects directly to Zoom property, so changes can be visible to the user
  347.     POLARDraw1.Zoom = sldZoom.Value
  348.     lblZoom = "Zoom: " + CStr(POLARDraw1.Zoom) + "%"
  349. End Sub
  350. Private Sub RefreshZoomSlider()
  351.    sldZoom.Value = POLARDraw1.Zoom
  352.    lblZoom = "Zoom: " + CStr(POLARDraw1.Zoom) + "%"
  353. End Sub
  354. Private Function Calculate(ByRef str As String) As Long
  355. 'This function formats string that will appear in shape (link name)
  356. 'and returns width of the shape, depending on the string length
  357. '(approcsimate 2mm per character)
  358.     str = Replace(str, Chr(34), " ", 1, -1, vbTextCompare)
  359.     str = Trim(str)
  360.     Calculate = 2 * Len(str)
  361. End Function
  362.