  '----------------------------------------------------------------------------
  ' thinBasic tutorial
  '----------------------------------------------------------------------------
  '[] Authors: many generous users
  '[] Version: 2.0.0
  '----------------------------------------------------------------------------
  '[todo] <Something to do here>
  '----------------------------------------------------------------------------
  
  '------
  '---Requisites
  #minversion 1.7.10.0
 
  '---Used modules
  Uses "UI"
  Uses "UIAdv"
  Uses "FILE"
  Uses "Registry"
  Uses "INI"

  '------
  '---Constants
  Begin ControlID
    '---Controls
      %IDC_V_SPLIT
      %IDC_MenuTREE
      %IDC_VIEWPORT
      %IDC_TOOLBAR
      %IDC_STATUSBAR
      %IDC_General_WEB
      %IDC_MainTimer
      
      %IDC_Tutorial_H_SPLIT
      %IDC_Tutorial_WEB
      %IDC_Tutorial_TXTDescription
    
    '---Menu
      %MNU_Area_Welcome
      %MNU_Area_WhatIs
      %MNU_Area_HowTo
      %MNU_Area_HelpMaterial
      %MNU_Area_AddDown
      %MNU_Area_Tutorials
      %MNU_Area_SampleScripts
      %MNU_Area_Support
      
      %MNU_FILE_EXIT
      %MNU_UTILS_EXECUTE
      %MNU_HELP_HELP
      %MNU_HELP_ABOUT
  End ControlID


  '---Application Ini config setup
  $SetUp_Ini_Name         = "Tutorial_Intro.ini"
  $SetUp_Ini_FullPath     = app_sourcepath & $SetUp_Ini_Name
    $SetUp_Ini_Section_General  = "General"
      $SetUp_Ini_Section_General_x  = "X"
      $SetUp_Ini_Section_General_y  = "Y"
      $SetUp_Ini_Section_General_w  = "Width"
      $SetUp_Ini_Section_General_h  = "Height"
      $SetUp_Ini_Section_General_IsMaximized  = "IsMaximized"

  
  '----------------------------------------------------------------------------
  '---Global variables
  dim hViewPort             as long
  dim hGeneralDialog        as long
  dim hTutorialsDialog       as long
  
  '---TreeView handlers
  dim htWelcome             as long
  dim htWhatIs              as long
  dim htHowTo               as long
  dim htHelpMaterial        as long
  dim htAdditionalDown      as long  
  dim htSampleScripts       as long
  dim htTutorials           as long
  dim htSupport             as long

  '---Determine thinBasic installation path
  global thinBasic_InstallPath As String
  thinBasic_InstallPath = Registry_GetValue("HKEYLM", "Software\thinBasic", "InstallPath")
  if right$(thinBasic_InstallPath, 1) <> "\" then thinBasic_InstallPath += "\"


  '---Path to web pages
  $PagePath_Welcome               = "file://" & app_sourcepath & "html/Welcome.htm"
  $PagePath_WhatIs                = "file://" & app_sourcepath & "html/WhatIs.htm"
  $PagePath_HowTo                 = "file://" & app_sourcepath & "html/HowToStart.htm"
  $PagePath_HelpMaterial          = "file://" & app_sourcepath & "html/HelpMaterial.htm"
  $PagePath_AdditionalDownloads   = "file://" & app_sourcepath & "html/AdditionalDownloads.htm"
  $PagePath_SampleScripts         = iif$(thinBasic_InstallPath = "", "", "file://" & thinBasic_InstallPath & "SampleScripts/")
  $PagePath_Support               = "file://" & app_sourcepath & "html/Support.htm"
  $PagePath_Tutorials             = "file://" & app_sourcepath & "html/Tutorials.htm"
  
  '---Tutorial INI and base config
  $Tutorial_BasePath              = "html/Tutorials/"
  $Tutorial_IniFile               = "info.ini"
  $Tutorial_MainDefaultPage       = "index.htm"

  $Tutorial_SectionTutorial              = "Tutorial"
  $Tutorial_SectionTutorial_sKeyName     = "Name"
  $Tutorial_SectionTutorial_sKeyDesc     = "Description"
  $Tutorial_SectionTutorial_sKeyAuthor   = "Author"
  $Tutorial_SectionTutorial_sKeyLevel    = "Level"
  $Tutorial_SectionTutorial_sKeyVersion  = "Version"
  $Tutorial_SectionTutorial_sKeyDate     = "DateLastModified"


  
  global cPink              as long = rgb(255, 0, 255)  '---Color for image transparency

  '---Create and load image list
  global iList              as long = ImageList_New(icon, 16, 16, 32)
  Global Icon_Welcome_d     As Long = ImageList_Add Masked  , iList, APP_SourcePath & "Icons\Welcome16_d.bmp", cPink 
  Global Icon_Welcome_h     As Long = ImageList_Add Masked  , iList, "Welcome16_h.bmp"
  Global Icon_WhatIs_h      As Long = ImageList_Add Masked  , iList, "WhatIs16_h.bmp"
  Global Icon_WhatIs_d      As Long = ImageList_Add Masked  , iList, "WhatIs16_d.bmp"
  Global Icon_HowTo_h       As Long = ImageList_Add Masked  , iList, "HowTo16_h.bmp"
  Global Icon_HowTo_d       As Long = ImageList_Add Masked  , iList, "HowTo16_d.bmp"
  Global Icon_Help_h        As Long = ImageList_Add Masked  , iList, "Help16_h.bmp"
  Global Icon_Help_d        As Long = ImageList_Add Masked  , iList, "Help16_d.bmp" 
  Global Icon_AddDown_h     As Long = ImageList_Add Masked  , iList, "Download16_h.bmp"
  Global Icon_AddDown_d     As Long = ImageList_Add Masked  , iList, "Download16_d.bmp"

  Global Icon_Scripts_h     As Long = ImageList_Add Masked  , iList, "Scripts16_h.bmp"
  Global Icon_Scripts_d     As Long = ImageList_Add Masked  , iList, "Scripts16_d.bmp"

  global Icon_Tutorials_h     as long = ImageList_Add masked, iList, "Tutorials16_h.bmp"
  global Icon_Tutorials_d     as long = ImageList_Add masked, iList, "Tutorials16_d.bmp"
  global Icon_TutorialStart_h as long = ImageList_Add masked, iList, "TutorialStart16_h.bmp"
  Global Icon_TutorialStart_d As Long = ImageList_Add Masked, iList, "TutorialStart16_d.bmp"

  Global Icon_Support_h     As Long = ImageList_Add Masked  , iList, "support16b_h.bmp"
  Global Icon_Support_d     As Long = ImageList_Add Masked  , iList, "support16b_d.bmp"



  '---Create and load image list
    global iToolList    as long = ImageList_New(icon, 24, 24, 32)
    global iToolList_d  as long = ImageList_New(icon, 24, 24, 32)
    global iToolList_h  as long = ImageList_New(icon, 24, 24, 32)
    
      '---Welcome
        ImageList_Add masked, iToolList   , "Welcome24.bmp"
        ImageList_Add masked, iToolList_d , "Welcome24_d.bmp"
        ImageList_Add masked, iToolList_h , "Welcome24_h.bmp"
      '---WhatIs
        ImageList_Add Masked, iToolList   , "WhatIs24.bmp" 
        ImageList_Add Masked, iToolList_d , "WhatIs24_d.bmp" 
        ImageList_Add Masked, iToolList_h , "WhatIs24_h.bmp" 
      '---HowTo
        ImageList_Add Masked, iToolList   , "HowTo24.bmp" 
        ImageList_Add masked, iToolList_d , "HowTo24_d.bmp"
        ImageList_Add masked, iToolList_h , "HowTo24_h.bmp"
      '---HelpMaterial
        ImageList_Add masked, iToolList   , "Help24.bmp"
        ImageList_Add masked, iToolList_d , "Help24_d.bmp"
        ImageList_Add masked, iToolList_h , "Help24_h.bmp"
      '---AdditionalDownloads
        ImageList_Add masked, iToolList   , "Download24.bmp"
        ImageList_Add masked, iToolList_d , "Download24_d.bmp"
        ImageList_Add masked, iToolList_h , "Download24_h.bmp"
      '---Scripts
        ImageList_Add masked, iToolList   , "Scripts24.bmp"
        ImageList_Add masked, iToolList_d , "Scripts24_d.bmp"
        ImageList_Add masked, iToolList_h , "Scripts24_h.bmp"
      '---Customer
        ImageList_Add masked, iToolList   , "support24b.bmp"
        ImageList_Add masked, iToolList_d , "support24b_d.bmp"
        ImageList_Add masked, iToolList_h , "support24b_h.bmp"
      '---Tutorials
        ImageList_Add masked, iToolList   , "Tutorials24.bmp"
        ImageList_Add masked, iToolList_d , "Tutorials24_d.bmp"
        ImageList_Add Masked, iToolList_h , "Tutorials24_h.bmp"


  global hMainDlg    AS LONG
  
  type tTutorial
    TVId          as long           '---TreeViewID
    sPath         as asciiz *  255
    sMainPage     as asciiz *  255
    sName         as asciiz *  255
    sDescription  as asciiz * 1024    
    sAuthor       as asciiz *  255
    sLevel        as asciiz *   64
    sVersion      As ASCIIZ *   32 
    sDate         As ASCIIZ *  255 'added by Mark 11-22-09
  end type 
  global Tutorials()  as tTutorial
  
  '----------------------------------------------------------------------------
  FUNCTION TBMAIN()
  '----------------------------------------------------------------------------
    local Count as long
    local x, y, w, h  as long

    '---Load config values
    x = INI_GetKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_x, "-1")
    y = INI_GetKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_y, "-1")
    w = INI_GetKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_w, "800")
    h = INI_GetKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_h, "600")

    Dialog New Pixels, %HWND_DESKTOP, "thinTutorial - thinBasic Programming Language", x, y, w, h, _
                                        %WS_MAXIMIZEBOX   | _
                                        %WS_MINIMIZEBOX   | _
                                        %WS_SYSMENU       | _
                                        %WS_THICKFRAME    | _
                                        %WS_CLIPCHILDREN  | _
                                        %WS_CLIPSIBLINGS    _
                                        To hMainDlg

    'dialog set color hMainDlg, 0, rgb(50,50,50)


    local hMenu       as long
    local hPopupFile  as long
    local hPopupUtils as long
    local hPopupHelp  as long

    '--- First create a top-level menu:
    MENU NEW BAR TO hMenu

    '---File menu
    MENU NEW POPUP TO hPopupFile
    MENU ADD POPUP,  hMenu, "&File", hPopupFile, %MF_ENABLED
    MENU ADD STRING, hPopupFile, "&Exit"         , %MNU_FILE_EXIT  , %MF_ENABLED

    '---Utils menu
    MENU NEW POPUP TO hPopupUtils
    MENU ADD POPUP,  hMenu, "&Utils", hPopupUtils, %MF_ENABLED
    MENU ADD STRING, hPopupUtils, "&Execute"         , %MNU_UTILS_EXECUTE  , %MF_ENABLED

    '---Help menu
    MENU NEW POPUP TO hPopupHelp
    MENU ADD POPUP,  hMenu, "&Help", hPopupHelp, %MF_ENABLED
    MENU ADD STRING, hPopupHelp, "&Help"         , %MNU_HELP_HELP  , %MF_ENABLED
    MENU ADD STRING, hPopupHelp, "-"             , 0               , 0
    MENU ADD STRING, hPopupHelp, "&About"        , %MNU_HELP_ABOUT , %MF_ENABLED

    '---Attach menu to dialog          
    MENU ATTACH hMenu, hMainDlg


    control add toolbar hMainDlg, %IDC_TOOLBAR, "", , , , , '%WS_VISIBLE OR %WS_TABSTOP OR %CCS_TOP OR %TBSTYLE_FLAT
        ToolBar_SetImageList hMainDlg, %IDC_TOOLBAR, iToolList    , 0
        ToolBar_SetImageList hMainDlg, %IDC_TOOLBAR, iToolList_d  , 1
        ToolBar_SetImageList hMainDlg, %IDC_TOOLBAR, iToolList_h  , 2

        toolbar_AddSeparator  hMainDlg, %IDC_TOOLBAR, 1
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 1, %MNU_Area_Welcome        , %TBSTYLE_BUTTON, "Welcome"
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 2, %MNU_Area_WhatIs         , %TBSTYLE_BUTTON, "What is"
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 3, %MNU_Area_HowTo          , %TBSTYLE_BUTTON, "How to"
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 4, %MNU_Area_HelpMaterial   , %TBSTYLE_BUTTON, "Help files"
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 5, %MNU_Area_AddDown        , %TBSTYLE_BUTTON, "Downloads"
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 6, %MNU_Area_SampleScripts  , %TBSTYLE_BUTTON, "Scripts"
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 7, %MNU_Area_Support        , %TBSTYLE_BUTTON, "Support"
        toolbar_AddSeparator  hMainDlg, %IDC_TOOLBAR, 1
        toolbar_AddButton     hMainDlg, %IDC_TOOLBAR, 8, %MNU_Area_Tutorials      , %TBSTYLE_BUTTON, "Tutorials"

    DIALOG SHOW modAL hMainDlg, call cbDialog_Main
    'DIALOG SHOW modeless hMainDlg, call cbDialog_Main
    'Do
    '  Dialog DoEvents 0 To Count
    'Loop While Count

  end function
  
  '----------------------------------------------------------------------------
  callback function cbDialog_Main() as long
  '----------------------------------------------------------------------------
    local hItem             AS LONG
    local cWidth            as long
    local cHeight           as long

    static TimeSpent        as long
    static lState           as long    
    static nIndex           as long
    static Counter1         as long
    static Counter2         as long
    static nDirs1           as long
    static nDirs2           as long
    static sDirs1()         As String
    static sDirs2()         As String
    static TV_Parent        as long
    static Path_Parent      as string
    
    SELECT CASE cbMsg
      case %WM_INITDIALOG

        lState = INI_GetKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_IsMaximized, "0")
        if lState = 1 then
          dialog show state cbhndl, %SW_MAXIMIZE
        end if

        DIALOG GET CLIENT cbhndl TO cWidth, cHeight
        
        CONTROL ADD TreeView, cbhndl, %IDC_MenuTREE, "", 0, 0, 0, 0, _
                                                    %WS_CHILD           | _
                                                    %WS_VISIBLE         | _
                                                    %TVS_HASBUTTONS     | _
                                                    %TVS_HASLINES       | _
                                                    %TVS_LINESATROOT    | _
                                                    %TVS_SHOWSELALWAYS  ,  _
                                                    %WS_EX_CLIENTEDGE, call cbTreeView

        hViewPort = control add VIEWPORT, cbhndl, %IDC_VIEWPORT, "", 0, 0, 0, 0

        Control Add statusbar, cbhndl, %IDC_STATUSBAR, "", , , , , %SBARS_SIZEGRIP
        StatusBar_SetParts cbhndl, %IDC_STATUSBAR, 80, 160, -1

        Splitter_Create         cbhndl, %IDC_V_SPLIT, %SWS_VERTICAL, 0, 51, cWidth, cHeight - 51 - 25
        Splitter_SetPanes       cbhndl, %IDC_V_SPLIT, %IDC_MenuTREE, %IDC_VIEWPORT
        Splitter_SetSplitPos    cbhndl, %IDC_V_SPLIT, 180
        Splitter_SetBarSize     cbhndl, %IDC_V_SPLIT, 3
        Splitter_SetPANEMINSize cbhndl, %IDC_V_SPLIT, 1
        Splitter_SetBackColor   cbhndl, %IDC_V_SPLIT, rgb(223,229,252)
        control set resize cbhndl, %IDC_V_SPLIT, 1, 1, 1, 1
        
        treeview_setindent cbhndl, %IDC_MenuTREE, 20
        treeview_setBKColor cbhndl, %IDC_MenuTREE, rgb(214, 223, 247)'rgb(250, 250, 250)
        treeview_setTextColor cbhndl, %IDC_MenuTREE, rgb(0, 0, 0) 'rgb(75, 118, 223)
        treeview_setLineColor cbhndl, %IDC_MenuTREE, rgb(255, 255, 0)
        Treeview_SetImagelist cbhndl, %IDC_MenuTREE, iList

          htWelcome         = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, 0, %TVI_FIRST, Icon_Welcome_h, Icon_Welcome_h, "Welcome"
   
            htWhatIs          = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, htWelcome, %TVI_LAST, Icon_WhatIs_h   , Icon_WhatIs_h   , "What is thinBasic"
            htHowTo           = TreeView_InsertItem CBHNDL, %IDC_MenuTREE, htWelcome, %TVI_LAST, Icon_HowTo_h    , Icon_HowTo_h    , "How to start"
            htHelpMaterial    = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, htWelcome, %TVI_LAST, Icon_Help_h     , Icon_Help_h     , "Help material"
            htAdditionalDown  = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, htWelcome, %TVI_LAST, Icon_AddDown_h  , Icon_AddDown_h  , "Additional downloads"

          htSampleScripts   = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, 0, %TVI_LAST, Icon_Scripts_h , Icon_Scripts_h , "thinBasic sample scripts"
          htSupport         = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, 0, %TVI_LAST, Icon_Support_h  , Icon_Support_h  , "thinBasic support"

          htTutorials       = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, 0, %TVI_LAST, Icon_Tutorials_h, Icon_Tutorials_h, "Tutorials", %TRUE
            nDirs1 = DIR_ListArray(sDirs1, app_sourcepath & $Tutorial_BasePath, "", %FILE_SUBDIR)
            nIndex = 0
            for Counter1 = 1 to nDirs1
              if left$(sDirs1(Counter1), 1) <> "_" then
                incr nIndex
                redim preserve Tutorials(nIndex)
                Tutorials(nIndex).sPath         = app_sourcepath & $Tutorial_BasePath & sDirs1(Counter1) & "\"
                Tutorial_GetData(Tutorials(nIndex))
                TV_Parent                       = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, htTutorials, %TVI_LAST, Icon_TutorialStart_h, Icon_TutorialStart_h, Tutorials(nIndex).sName
                Tutorials(nIndex).TVId          = TV_Parent
                Treeview_Setuser cbhndl, %IDC_MenuTREE, Tutorials(nIndex).TVId, nIndex

                Path_Parent = Tutorials(nIndex).sPath
                nDirs2 = DIR_ListArray(sDirs2, Path_Parent, "", %FILE_SUBDIR)
                if nDirs2 then
                  for Counter2 = 1 to nDirs2
                    if left$(sDirs2(Counter2), 1) <> "_" then
                      incr nIndex
                      redim preserve Tutorials(nIndex)
                      Tutorials(nIndex).sPath         = Path_Parent & sDirs2(Counter2) & "\"
                      Tutorial_GetData(Tutorials(nIndex))
                      Tutorials(nIndex).TVId          = TREEVIEW_INSERTITEM cbhndl, %IDC_MenuTREE, TV_Parent, %TVI_LAST, Icon_TutorialStart_h, Icon_TutorialStart_h, Tutorials(nIndex).sName
                      Treeview_Setuser cbhndl, %IDC_MenuTREE, Tutorials(nIndex).TVId, nIndex
                    end if  
                  next
                  Treeview_SetExpanded cbhndl, %IDC_MenuTREE, TV_Parent, %TRUE
                end if
                
              end if
            next
          Treeview_SetExpanded cbhndl, %IDC_MenuTREE, htTutorials, %TRUE
            

          Treeview_SetExpanded cbhndl, %IDC_MenuTREE, htWelcome, %TRUE
          Treeview_Select cbhndl, %IDC_MenuTREE, htWelcome

        dialog set timer cbhndl, %IDC_MainTimer, 1000

      case %WM_SIZE
        DIALOG GET size cbhndl TO cWidth, cHeight
        StatusBar_SetText cbhndl, %IDC_STATUSBAR, cWidth & "x" & cHeight, 2

      case %WM_TIMER
        select case cbctl
          case %IDC_MainTimer
            '---Add 1 seconds
            TimeSpent += 1
            StatusBar_SetText cbhndl, %IDC_STATUSBAR, "Seconds: " & TimeSpent, 1
        end select
      case %WM_COMMAND
        select case cbctl
            
          case %MNU_FILE_EXIT
            dialog end cbhndl

          case %MNU_HELP_HELP
            msgbox cbhndl, "Help goes here"

          case %MNU_HELP_ABOUT
            msgbox cbhndl, "About goes here"

          case %MNU_Area_Welcome
            treeview_select hMainDlg, %IDC_MenuTREE, htWelcome

          case %MNU_Area_WhatIs
            treeview_select hMainDlg, %IDC_MenuTREE, htWhatIs

          case %MNU_Area_HowTo
            treeview_select hMainDlg, %IDC_MenuTREE, htHowTo

          case %MNU_Area_HelpMaterial
            treeview_select hMainDlg, %IDC_MenuTREE, htHelpMaterial

          case %MNU_Area_AddDown
            treeview_select hMainDlg, %IDC_MenuTREE, htAdditionalDown

          case %MNU_Area_Tutorials
            treeview_select hMainDlg, %IDC_MenuTREE, htTutorials

          case %MNU_Area_SampleScripts
            treeview_select hMainDlg, %IDC_MenuTREE, htSampleScripts
            
          case %MNU_Area_Support  
            treeview_select hMainDlg, %IDC_MenuTREE, htSupport
            

        end select
      
 
      case %WM_DESTROY
        ImageList_Kill(iList)

        '---Save config values
          Dialog_Main_SaveSetUp(cbhndl)
        
    end select

  END FUNCTION

  '----------------------------------------------------------------------------
  function Dialog_Main_SaveSetUp(hDlg as long)
  '----------------------------------------------------------------------------
    static x, y, w, h as long
    static lState as long

    '---Save Maximized state
    lState = Win_IsZoomed(hDlg)
    INI_SetKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_IsMaximized, iif(lState, "1", "0"))

    '---If window is maximized, do not save position and size but just maximized flag
    if lState = %FALSE then
      dialog get loc hDlg to x, y
      dialog get client hDlg to w, h
      INI_setKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_x, x)
      INI_setKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_y, y)
      INI_setKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_w, w)
      INI_setKey($SetUp_Ini_FullPath, $SetUp_Ini_Section_General, $SetUp_Ini_Section_General_h, h)
    end if
  end function

  '----------------------------------------------------------------------------
  FUNCTION Dialog_General_Create_InViewPort()
  '----------------------------------------------------------------------------
    LOCAL hDlg    AS LONG

    DIALOG NEW pixels, hViewPort, "", 0, 0, 0, 0, %WS_CHILD or %WS_CLIPCHILDREN TO hDlg
    viewport_SetChild(hViewPort, hDlg, %TRUE )
    DIALOG SHOW modeless hDlg, call cbDialog_General
    function = hDlg

  end function

  '----------------------------------------------------------------------------
  CallBack Function cbDialog_General() As Long
  '----------------------------------------------------------------------------    
    static lWidth, lHeight as long

    select case cbmsg

      case %WM_INITDIALOG
        dialog get client cbhndl to lWidth, lHeight
        
        WebBrowser_Create cbhndl, %IDC_General_WEB, "", 0, 0, -1, -1, %WS_CHILD Or %WS_VISIBLE, 0
        Dialog_General_SetPage cbhndl, $PagePath_Welcome
                 
      case %WM_SIZE
        dialog get client cbhndl to lWidth, lHeight
        control set size cbhndl, %IDC_General_WEB, lWidth, lHeight 
        control set focus cbhndl, %IDC_General_WEB

    end select
    
  end function

  '----------------------------------------------------------------------------
  function Dialog_General_SetPage(byval hDlg as long, byval sPagePath as string) as long
  '----------------------------------------------------------------------------    
      WebBrowser_Navigate2 hDlg, %IDC_General_WEB, sPagePath

  end function

  '----------------------------------------------------------------------------
  FUNCTION Dialog_Tutorials_Create_InViewPort()
  '----------------------------------------------------------------------------
    LOCAL hDlg    AS LONG

    DIALOG NEW pixels, hViewPort, "", 0, 0, 0, 0, %WS_CHILD or %WS_CLIPCHILDREN TO hDlg
    viewport_SetChild(hViewPort, hDlg, %TRUE )
    DIALOG SHOW modeless hDlg, call cbDialog_Tutorials
    
    function = hDlg
  end function

  '----------------------------------------------------------------------------
  callback function cbDialog_Tutorials() as long
  '----------------------------------------------------------------------------
    static lWidth, lHeight  as long
    local sBuffer           as string
            
    select case cbmsg

      case %WM_INITDIALOG
        dialog get client cbhndl to lWidth, lHeight

        CONTROL ADD rtf_GetClass, cbhndl, %IDC_Tutorial_TXTDescription, "",_
                                          0, 0, lWidth, 50, _
                                          %WS_CHILD           OR _
                                          %WS_CLIPCHILDREN    OR _
                                          %WS_VISIBLE         OR _
                                          %ES_MULTILINE       OR _
                                          %WS_VSCROLL         OR _
                                          %ES_AUTOVSCROLL     OR _
                                          %ES_AUTOHSCROLL     OR _
                                          %ES_WANTRETURN      , _
                                          %WS_EX_CLIENTEDGE
                                          '%WS_HSCROLL         OR _

        '---Set event mask so we'll get EN_SELCHANGE and %ENM_MOUSEEVENTS notifications
          CONTROL SEND cbhndl, %IDC_Tutorial_TXTDescription, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE OR %ENM_MOUSEEVENTS
          '---Set some options
          CONTROL SEND cbhndl, %IDC_Tutorial_TXTDescription, %EM_SETOPTIONS, %ECOOP_OR, %ECO_SELECTIONBAR
          '---Allow 1 meg files
          control send cbhndl, %IDC_Tutorial_TXTDescription, %EM_LIMITTEXT, 1000000, 0

          '---Set automatic url detection to true. The following link are usable: http: file: mailto: ftp: https: gopher: nntp: prospero: telnet: news: wais:
          'control send hDlg, %ID_EDITOR, %EM_AUTOURLDETECT, %TRUE, 0
          RTF_setText(cbhndl, %IDC_Tutorial_TXTDescription, "", %SF_TEXT)
          RTF_appendText(cbhndl, %IDC_Tutorial_TXTDescription, "[b]Please select a tutorial from the list.[/b]", %RTF_UBB)

        '---Return window handle to richedit text
          'CONTROL HANDLE hDlg, %IDC_TXTDescription_Tutorials TO hEdit

        WebBrowser_Create cbhndl, %IDC_Tutorial_WEB, "", 0, 50, -1, -1, %WS_CHILD Or %WS_VISIBLE, 0
        WebBrowser_Navigate2 cbhndl, %IDC_Tutorial_WEB, $PagePath_Tutorials

        'control add button, cbhndl, 123, "Check", lWidth - 90, 0, 80, 50
        
      'case %WM_COMMAND
      '  select case cbctl
      '    case 123
      '      msgbox 0, WebBrowser_Doc2_GetTitle cbhndl, %IDC_Tutorial_WEB
      '      'sBuffer = inputbox$( "prompt", "title", WebBrowser_Doc2_GetElementInnerHtmlById cbhndl, %IDC_Tutorial_WEB, "Code1")
      '      'WebBrowser_Doc2_SetElementInnerHtmlById cbhndl, %IDC_Tutorial_WEB, "Code1", sBuffer
      '  end select
      case %WM_SIZE
        dialog get client cbhndl to lWidth, lHeight
        control set size cbhndl, %IDC_Tutorial_TXTDescription, lWidth, 50 
        control set size cbhndl, %IDC_Tutorial_WEB, lWidth, lHeight - 50 
        control set focus cbhndl, %IDC_Tutorial_WEB


    end select

  end function

  '----------------------------------------------------------------------------
  function Tutorial_GetData(lTutorial as ttutorial)
  '----------------------------------------------------------------------------
  ' Function assumes that lTutorial.sPath is already populated with the correct
  ' path from which to load tutorial
  '----------------------------------------------------------------------------

    local sIniFile    as string
    
    sIniFile = lTutorial.sPath & $Tutorial_IniFile
    
    lTutorial.sName         = INI_GetKey(sIniFile, $Tutorial_SectionTutorial, $Tutorial_SectionTutorial_sKeyName)
    lTutorial.sDescription  = INI_GetKey(sIniFile, $Tutorial_SectionTutorial, $Tutorial_SectionTutorial_sKeyDesc)
    lTutorial.sAuthor       = INI_GetKey(sIniFile, $Tutorial_SectionTutorial, $Tutorial_SectionTutorial_sKeyAuthor)
    lTutorial.sLevel        = INI_GetKey(sIniFile, $Tutorial_SectionTutorial, $Tutorial_SectionTutorial_sKeyLevel)
    lTutorial.sVersion      = INI_GetKey(sIniFile, $Tutorial_SectionTutorial, $Tutorial_SectionTutorial_sKeyVersion)
    lTutorial.sDate         = INI_GetKey(sIniFile, $Tutorial_SectionTutorial, $Tutorial_SectionTutorial_sKeyDate) 'added by Mark 11-22-09
    


'  type tTutorial
'    TVId          as long           '---TreeViewID
'    sPath         as asciiz *  255
'    sMainPage     as asciiz *  255
'  end type 


  end function

  '----------------------------------------------------------------------------
  function Tutorial_SetDialogData(byval lIndex as long)
  '----------------------------------------------------------------------------
    static sBuffer as string
    'msgbox 0, Tutorials(lIndex).sPath
    RTF_setText(hTutorialsDialog, %IDC_Tutorial_TXTDescription, "", %SF_TEXT)
        
        'added by Mark (I changed the next few lines) 11-21-09
    'If lIndex Then
     ' sBuffer = "[COLOR=255,0,51][b]" & Tutorials(lIndex).sDescription & "[/b][COLOR=0,0,0]" & _
      '          $CRLF & "Author: [b]" & Tutorials(lIndex).sAuthor & "[/b]   Level: [b]" & Tutorials(lIndex).sLevel & "[/b]   Version: [b]" & Tutorials(lIndex).sVersion & "[/b]" &  _
       '         ""
    
    
    If lIndex Then
      sBuffer = "[COLOR=255,0,51][b]" & Tutorials(lIndex).sDescription & "[/b][COLOR=0,0,0]" & _
                $CRLF & "Level: [b]" & Tutorials(lIndex).sLevel & "[/b]   Date Modified: [b]"  & Tutorials(lIndex).sDate &  ""
      RTF_AppendText(hTutorialsDialog, %IDC_Tutorial_TXTDescription, sBuffer, %RTF_UBB)

      WebBrowser_Navigate2 hTutorialsDialog, %IDC_Tutorial_WEB, "file://" & Tutorials(lIndex).sPath & $Tutorial_MainDefaultPage
    else
      sBuffer = "[COLOR=0,0,0][b]Please select a tutorial from the list.[/b]"
      RTF_appendText(hTutorialsDialog, %IDC_Tutorial_TXTDescription, sBuffer, %RTF_UBB)

      WebBrowser_Navigate2 hTutorialsDialog, %IDC_Tutorial_WEB, $PagePath_Tutorials
    end if
    
  end function
  
 
  '----------------------------------------------------------------------------
  callback function cbTreeView() as long
  '----------------------------------------------------------------------------
    local nmTV        as NM_TREEVIEW ptr
    local hTreeItem   as long
    local Counter     as long
        
    select case CBMSG
      case %WM_NOTIFY

        '---Get the pointer of treeview notification structure
        nmTV = cbnmhdr
        
        '---Check what happen
        SELECT CASE nmTV.hdr.Code 
          CASE %TVN_SELCHANGED
            hTreeItem = nmTV.ItemNew.hItem
            
            select case hTreeItem
              
              case htWelcome
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_Welcome
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if
                
              case htWhatIs
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_WhatIs
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if

              case htHowTo
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_HowTo
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if

              case htHelpMaterial
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_HelpMaterial
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if
                
              case htAdditionalDown
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_AdditionalDownloads
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if

              case htTutorials
                if hTutorialsDialog then
                  viewport_SetChild(hViewPort, hTutorialsDialog, %TRUE )
                  Tutorial_SetDialogData(0)
                else
                  hTutorialsDialog = Dialog_Tutorials_Create_InViewPort
                end if

              case htSampleScripts
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_SampleScripts
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if

              case htSupport
                if hGeneralDialog then
                  Dialog_General_SetPage hGeneralDialog, $PagePath_Support
                  viewport_SetChild(hViewPort, hGeneralDialog, %TRUE )
                else
                  hGeneralDialog = Dialog_General_Create_InViewPort
                end if
                
              case else
                Counter =  Treeview_Getuser(cbhndl, %IDC_MenuTREE, hTreeItem)
                if Counter then
                  'msgbox 0, Tutorials(Counter).sPath
                  if hTutorialsDialog then
                    viewport_SetChild(hViewPort, hTutorialsDialog, %TRUE )
                  else
                    hTutorialsDialog = Dialog_Tutorials_Create_InViewPort
                  end if
                  Tutorial_SetDialogData(Counter)
                end if

            end select
             

        end select
    end select

  end function
  

