'#####################################
'                                    '
' A Rich edit control editor example '
'             By Andy                '
'                                    '
'           Version 4.6              '
'           August 2020              '
'                                    '
'#####################################

$MAIN
$INCLUDE "xeditor.inc"
$USE "Comctl32.lib"

AUTODEFINE "off"

SetupTiming()				'Just for my own timing purposes - not needed.
ReadKeyWords()	 			'Read in IW keywords.
BuildWordSize() 	      		'Build key word indexes.

TYPE Undos2
     INT Pos[100000]
     INT LineNo[100000]
     INT Offset[100000]
     STRING Typed[100000]
     STRING Was[100000]
     INT Colour[100000]
     INT Press[100000]
     INT Length[100000]
ENDTYPE
DEF Undo2[6] AS Undos2

TYPE Redos2
     INT Pos[100000]
     INT LineNo[100000]
     INT Offset[100000]
     STRING Typed[100000]
     STRING Was[100000]
     INT Colour[100000]
     INT Press[100000]
     INT Length[100000]
ENDTYPE
DEF Redo2[6] AS Redos2

if openconsole then 'Test line

TYPE UndoBlockText
     INT UndoCount[1000]
     INT StartPos[1000]
     INT EndPos[1000]
     INT Length[1000]
     INT LineNo[1000]
     ISTRING BlockText[50000,1000]
ENDTYPE
DEF UndoBlock[6] AS UndoBlockText

Type RedoBlockText
     int UndoCount[1000]
     int StartPos[1000]
     int EndPos[1000]
     int Length[1000]
     int LineNo[1000]
     istring BlockText[50000,1000]
endtype
def RedoBlock[6] as RedoBlockText

int Undo2Count[6] = 0
int Redo2Count[6] = 0

int Console = 1
IF Console = 1
   OPENCONSOLE
   PRINT
   PRINT
ENDIF

INT AddToUndo = 0
INT DeleteOnce = 0
INT Typing = 0
INT RebuildCount = 0
INT ManualChange = 0
INT StartCutPos = 0
INT DoneBefore = 0
INT CtrlDown = 0
INT PasteOn = 0
INT NoNotify = 0
INT BackSpacePressed = 0
ISTRING DelStore[512] = ""
STRING TheWord = ""
STRING CharTyped = ""
STRING Line2$ = ""
STRING Line4$ = ""

LoadIncludePath()

'##############################
'                             '
' Variables you can customise '
'                             '
'##############################

IF OPENCONSOLE THEN 'Test line

'===========================================================
' Variable Ucase determines how key words appear on screen.
' Ucase values: 1 Upper case, 2 Lower case, 3 As typed.
  Ucase = 1
'===========================================================


'===========================================================
' Text background colour.
'uint ScreenColour = RGB(243,242,214)
UINT ScreenColour = RGB(211,211,211) 'Light grey
'===========================================================

'===========================================================
' Window background colour.
UINT WindowBackColour = RGB(231,222,231)
'===========================================================

'===========================================================
' Allows automatic jumping to sub routines, windows and
' automatically inserts blocks of code when selected.
' 0 = No, 1 = Yes
INT AutoJumpTo = 0
'===========================================================

'===========================================================
' Default SELECT to show CASES
STRING DefaultSelect = "@CONTROLID"
'===========================================================

'===========================================================
' Confirmation messages - 0 = No, 1 = Yes
int ConfirmMessage = 1
'===========================================================

'===========================================================
' Maximum number of program tabs - 6 is maximum
int MaxTabs = 6
'===========================================================

'===========================================================
' Save open files on program exit
int AutoSaveOnExit = 1
'===========================================================

'===========================================================
' Save a file when closing that file
int AutoSaveOnClose = 1
'===========================================================

'===========================================================
' Number of lines to scroll when mouse wheel is moved
int WheelScrollLines = 4
'===========================================================

'===========================================================
' Tooltips 1 = Yes 0 = No
int ToolTips = 1
'===========================================================

'===========================================================
' Timer speed - best left as is
INT TimerSpeed1 = 20
'===========================================================

'===========================================================
' Subs / winodows reindex speed
INT ReIndexSpeed = 120000
'===========================================================

'===========================================================
' Undo / Redo keys
INT UndoKey    = 112	'F1 Key
INT RedoKey    = 113	'F2 Key
INT UndoAllKey = 114	'F3 Key
INT RedoAllKey = 115	'F4 Key
'===========================================================

'===========================================================
' Number of spaces a TAB key press adds
INT TabSpacing = 10
'===========================================================

'===========================================================
' Auto complete key words, 1 = On, 0 = Off
INT AutoCompleteKeyWords = 1
'===========================================================

'#####################################
'                                    '
' End of Variables you can customise '
'                                    '
'#####################################

LOGFONT lf
INT AutoCompleteStore = AutoCompleteKeyWords
INT lv2Selected = 0
INT mod = 0
INT CloseDown = 0
INT NoColour = 0
INT CapsOn = 0
INT Confirm = 0
INT ProgCount = 0
INT OnTab = 0
INT PageDown = 0
INT WheelPos = 0
INT Restoring = 0
INT OnBlock = 0
INT ScrollPoint = 0
INT NoNewFile = 0
INT crtl = 0
INT Skip = 0
INT OldsRange = 0
INT StartUpAt = 1
INT WordCountEdit = 0
INT DelConfirm = 0
INT Once = 0
INT mc = 0
int ToAdd = -1
int TextJump = 1
int eventMask = 0
int TvarStart = 0
int StorecLine = 0
int MouseWheel = 0
int OldLines = 0
int CurrentLines = 0
int Modified = 0
int lvX = 0
int lvY = 0
int length2 = 0
int InsertPoint = 0
int char_index = 0
int MinMax1 = 0
int MinMax2 = 0
int TabTaken = 0
int Tab1Loaded = 0
int Tab2Loaded = 0
int Tab3Loaded = 0
int Tab4Loaded = 0
int Tab5Loaded = 0
int Tab6Loaded = 0
int EndButtons = 1297
uint BackColour = rgb(231,222,231)

file file1
istring buffer[1048576]
istring buffer1[1048576]
istring buffer2[1048576]
istring buffer3[1048576]
istring buffer4[1048576]
istring buffer5[1048576]
istring buffer6[1048576]
istring CutLine[1048576] = ""
string RecentProgs[10] = ""
string RecentName[10] = ""
STRING Col1[5000] = ""
STRING Col2[5000] = ""
STRING Col3[5000] = ""
STRING OldFirstLine = ""
STRING OldLastLine = ""
STRING StoreFirstLine = ""
STRING StoreLastLine = ""
STRING Block1 = ""
STRING Block2 = ""
STRING BlockIn = ""
STRING BlockOld = ""
STRING RealTabName = ""
STRING StoreSubName = ""
STRING BookMarkDesc = ""
STRING TextIn1,TextIn2,TextInName
STRING NewEdit = ""
STRING BackupDesc = ""
DOUBLE dOnLine = 0.00
INT OnLine = 1
INT ScrollBarVisible = 1
INT FirstVisLine = 1
INT DoingOpen = 0
INT MoveAmount = 0
INT LastUpLine = 0
INT SingleLine = 0
INT Colouring = 0
INT KeyUp = 0
INT KeyDownn = 0
INT lStart = 0
INT lStop = 0
INT crsCount = 0
INT xStart = 0
int xEnd = 0
int Fvis = 0
int ttx = 0
int kw = 0
int ReplaceNow = 0
int DelFound = 0
int CommentsOn = 0
int ColourThis = 0
int SwitchIn = 0
int Store1 = 0
int Store2 = 0
int cLine = 0
int OldLine = 0
int OldFirstLineX = 0
int StoreLine = 0
INT StoreCharPos = 0
INT MoveToPosition = 0
INT NavPos = 0
INT NavMax = 0
INT Page = 1

POINTER Chars
TYPE Charrange
     UINT cpMin 'Start position
     UINT cpMax 'End position
ENDTYPE
Chars = NEW(Charrange,5)
SETTYPE Chars,Charrange

POINTER mMouse
TYPE mouse_event
     INT dwFlags
     INT dx
     INT dy
     INT dwData
     UINT dwExtraInfo
ENDTYPE
mMouse = NEW(mouse_event,5)
SETTYPE mMouse,mouse_event
CONST ES_UPPERCASE = 0x0008
CONST ENM_MOUSEEVENTS = 0x00020000
CONST EM_SETREADONLY = 0xCF
CONST EN_CHANGE = 0x300
CONST ES_SUNKEN = 0x00004000
CONST WM_USER = 0x400
CONST WM_MOUSEWHEEL = 0x020A
CONST WM_VSCROLL = 0x115

Const LVM_FIRST  = &H1000
Const LVM_GETSELECTIONMARK  = (LVM_FIRST + 66)
Const LVM_GETNEXTITEM = (LVM_FIRST + 12)
Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)

const EDIT_1 = 10
const Check1 = 15
const TextBlock1 = 500
const TextBlock2 = 501
const TextBlock3 = 502
const TextBlock4 = 503
const ShowCode = 504
const ShowBlock1 = 505
const ShowBlock2 = 506
const ShowBlock3 = 507
const ShowBlock4 = 508
const LineStatic = 509
const CopySubButton = 510
const DeleteSubButton = 511
const CopySubBlockButton = 512
const CopyWinButton = 520
const DeleteWinButton = 521
const CopyWinBlockButton = 522
const DeleteBlockButton = 523
const CopyBlockButton = 524
const MoveSubButton = 525
const MoveWinButton = 526
const BlockJumpButton = 527
const SnapshotButton = 528
const SaveAsButton = 529
const BookDelAll = 530
const ListView8 = 540
const ListView10 = 541
const Combo8 = 542
const SelectJump = 543
const SelectEnd = 544
CONST Combo10 = 545
CONST CaseJump = 546
CONST SelectStatic = 547
CONST CaseStatic = 548
CONST Combo12 = 549
CONST EDIT_2 = 550
CONST EDIT_4 = 551
CONST Combo14 = 552
CONST CaseFind = 553
CONST Combo16 = 554
CONST CaseDelete = 555
CONST CaseFindStatic = 556
CONST LinePosEdit = 557
CONST LineCharEdit = 558
CONST nwPosEdit = 559
CONST EditPosEdit = 560
CONST LinePosStatic = 561
CONST LineCharStatic = 562
CONST nwPosStatic = 563
CONST EditPosStatic = 564
CONST InsertStatic = 565
CONST KeyWordStatic = 566
CONST KeyWordResults = 567
CONST KeyFind = 568
CONST ListViewResult = 570
CONST KeyDelete = 571
CONST CodeWordEdit1 = 572
CONST CodeWordEdit2 = 573
CONST CodeWordSearch = 574
CONST CodeWordStatic = 575
CONST CodeWordAnd = 576
CONST CodeWordOr = 577
CONST CodeWordDelete = 578
CONST CodePhraseEdit = 579
CONST CodePhraseSearch = 580
CONST CodePhraseStatic = 581
CONST CodePhraseExact = 582
CONST CodePhraseWords = 583
CONST ShowSubButton = 584
CONST ShowWindowButton = 585
CONST ShowBookMarksButton = 586
CONST ShowCasesButton = 587
CONST PhraseDeleteButton = 588
CONST NavForwardButton = 589
CONST NavBackButton = 590
CONST NavDeleteButton = 591
CONST NavButton = 592
CONST NavBackGrey = 593
CONST NavForwardGrey = 594
CONST Combo18 = 595
CONST ReplaceStatic = 596
CONST ReplaceEdit = 597
CONST ReplaceSearch = 598
CONST ReplaceWhat = 599
CONST ReplaceWith = 600
CONST MaxWordsStatic = 601
const EDIT_11 = 602
const EDIT_111 = 603
const BUTTON_44 = 604
const CloseButton = 605
const FileTab1 = 606
const FileTab2 = 607
const FileTab3 = 608
const FileTab4 = 609
const MinButton = 610
const BackupButton = 611
const NewButton = 612
const FileTab5 = 613
const FileTab6 = 614
'const Combo20 = 700
CONST CogButton = 701
CONST ClearSubs = 702
CONST ClearWins = 703
CONST ReplaceButton = 704
CONST GoReplace = 705
CONST TopButton = 706
CONST BottomButton = 707
CONST IncludeStatic = 708
CONST IncludeGo = 709
CONST ClearButton = 710
CONST BinButton = 711
CONST AutoButton = 712
CONST ExitButton = 780

POINTL pt

ISTRING line$[512] = ""
INT ScrollStart = 0
INT EndRange = 0
INT LineIsAt  = 0
INT Numlength = 0
INT Correction = 0
INT mask = 0
INT ttt = 0
INT ppos = 0
INT NoUpdate = 0
INT ToBlock = 0
INT MaxLines = 0
INT StartAt = 0
INT AcrossX = 0
INT DownY = 0
INT FirstChar = 0
int EditPos = 0
int TimerStarted = 0
int Loading = 1

const SB_VERT = 1

filter = "IWB files|*.iwb|All Files|*.*||"
GetFileName(w1,0,ProgPath,1)

OPENWINDOW w1,0,0,1350,725,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"",&main
	Setwindowcolor w1,WindowBackColour
   setcaption w1,FileNameIs

BEGINMENU w1
     MENUTITLE "&File"
     MENUTITLE "&Edit"
     MENUITEM "Cut		Ctrl + X",0,201
     MENUITEM "Copy		Ctrl + C",0,202
     MENUITEM "Paste		Ctrl + V",0,203
ENDMENU

ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("X"),201 'Cut
ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("C"),202 'Copy
ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("V"),203 'Paste

    'Intial line numbers 1 to 29
	 INT Downs = 102
	 FOR a = 1 TO 29
		  CONTROL w1,@STATIC,"",41,Downs,60,16,@CTEDITRIGHT|0x200,a+1000
		  SETFONT w1, "Courier New",10,400,0,a+1000
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
		  Downs = Downs + 16
	 NEXT a

   rHandle = GETCONTROLHANDLE(w1,1)
   Loading = 1

   CONTROL w1,@BUTTON,"Main program",70,590,100,25,@CTEDITRIGHT,ShowCode
           SETCONTROLCOLOR w1,ShowCode,RGB(255,255,255),Green
           SETFONT w1,"Arial",10,400,0,ShowCode

   CONTROL w1,@BUTTON,"1",180,590,25,25,@CTEDITRIGHT,ShowBlock1
           SETCONTROLCOLOR w1,ShowBlock1,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock1
           ENABLECONTROL w1,ShowBlock1,0

   CONTROL w1,@BUTTON,"2",210,590,25,25,@CTEDITRIGHT,ShowBlock2
           SETCONTROLCOLOR w1,ShowBlock2,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock2
           enablecontrol w1,ShowBlock2,0

   CONTROL w1,@BUTTON,"3",240,590,25,25,@CTEDITRIGHT,ShowBlock3
           SETCONTROLCOLOR w1,ShowBlock3,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock3
           enablecontrol w1,ShowBlock3,0

   CONTROL w1,@BUTTON,"4",270,590,25,25,@CTEDITRIGHT,ShowBlock4
           SETCONTROLCOLOR w1,ShowBlock4,RGB(255,255,255),BackColour
           SETFONT w1,"Arial",10,400,0,ShowBlock4
           enablecontrol w1,ShowBlock4,0

   CONTROL w1,@BUTTON,"",300,590,25,25,@CTLBTNBITMAP,CopyBlockButton
           SETCONTROLTEXT w1,CopyBlockButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

   CONTROL w1,@BUTTON,"",330,590,25,25,@CTLBTNBITMAP,DeleteBlockButton
           SETCONTROLTEXT w1,DeleteBlockButton,GETSTARTPATH() + "\\Res\\remove2.bmp"

   CONTROL w1,@EDIT,"",70,71,80,20,@CTEDITCENTER|SS_NOTIFY,4
   SHOWWINDOW w1,@SWHIDE,4

   'Save file etc
   CONTROL w1,@BUTTON,"",35,590,25,25,@CTLBTNBITMAP,CloseButton
           SETCONTROLTEXT w1,CloseButton,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@BUTTON,"",5,110,30,30,@CTLBTNBITMAP,NewButton
           SETCONTROLTEXT w1,NewButton,GETSTARTPATH() + "\\Res\\new.bmp"

   CONTROL w1,@BUTTON,"",5,150,30,30,@CTLBTNBITMAP,OpenButton
           SETCONTROLTEXT w1,OpenButton,GETSTARTPATH() + "\\Res\\Open.bmp"

   CONTROL w1,@BUTTON,"",5,190,30,30,@CTLBTNBITMAP,SaveButton
           SETCONTROLTEXT w1,SaveButton,GETSTARTPATH() + "\\Res\\Save.bmp"

   CONTROL w1,@BUTTON,"",5,230,30,30,@CTLBTNBITMAP,SaveAsButton
           SETCONTROLTEXT w1,SaveAsButton,GETSTARTPATH() + "\\Res\\SaveAs.bmp"

   CONTROL w1,@BUTTON,"",5,270,30,30,@CTLBTNBITMAP,BackupButton
           SETCONTROLTEXT w1,BackupButton,GETSTARTPATH() + "\\Res\\Backup.bmp"

   CONTROL w1,@BUTTON,"",5,310,30,30,@CTLBTNBITMAP,CogButton
           SETCONTROLTEXT w1,CogButton,GETSTARTPATH() + "\\Res\\Cog.bmp"

   CONTROL w1,@BUTTON,"",5,350,30,30,@CTLBTNBITMAP,AutoButton
           IF AutoCompleteKeyWords = 1
              SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOn.bmp"
           ELSE
              SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOff.bmp"
           ENDIF

   CONTROL w1,@BUTTON,"",5,390,30,30,@CTLBTNBITMAP,BinButton
           SETCONTROLTEXT w1,BinButton,GETSTARTPATH() + "\\Res\\Bin.bmp"

   'File tabs
   CONTROL w1,@BUTTON,"",0,647,216,20,@CTEDITLEFT,FileTab1
           SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,FileTab1

   CONTROL w1,@BUTTON,"",216,647,216,20,@CTEDITLEFT,FileTab2
           SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,FileTab2
           SHOWWINDOW w1,@SWHIDE,FileTab2

   CONTROL w1,@BUTTON,"",432,647,216,20,@CTEDITLEFT,FileTab3
           SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,FileTab3
           SHOWWINDOW w1,@SWHIDE,FileTab3

   CONTROL w1,@BUTTON,"",648,647,216,20,@CTEDITLEFT,FileTab4
           SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,FileTab4
           showwindow w1,@SWHIDE,FileTab4

   CONTROL w1,@BUTTON,"",864,647,216,20,@CTEDITLEFT,FileTab5
           SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,FileTab5
           showwindow w1,@SWHIDE,FileTab5

   CONTROL w1,@BUTTON,"",1080,647,216,20,@CTEDITLEFT,FileTab6
           SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,FileTab6
           showwindow w1,@SWHIDE,FileTab6

   'Line entry
   CONTROL w1,@STATIC," Go to line",35,0,100,20,@CTEDITLEFT|0x200,LineStatic
           SETCONTROLCOLOR w1,LineStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,LineStatic

   CONTROL w1,@BUTTON,"",5,17,25,25,@CTLBTNBITMAP,BUTTON_4
           SETCONTROLTEXT w1,BUTTON_4,GETSTARTPATH() + "\\Res\\jump.bmp"
           showwindow w1,@SWHIDE,BUTTON_4

   CONTROL w1,@EDIT,"",35,19,84,22,@CTEDITNUMBER|@CTEDITAUTOH|ES_SUNKEN,EDIT_1 'Control jump to line number
           CONTROLCMD w1,EDIT_1,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_1
           showwindow w1,@SWHIDE,EDIT_1

   CONTROL w1,@EDIT,"",35,19,70,22,@CTEDITNUMBER|@CTEDITAUTOH||ES_SUNKEN,EDIT_11 'User jump to line number
           CONTROLCMD w1,EDIT_11,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_11

   CONTROL w1,@BUTTON,"",5,45,25,25,@CTLBTNBITMAP,BUTTON_44
           SETCONTROLTEXT w1,BUTTON_44,GETSTARTPATH() + "\\Res\\jump.bmp"
           showwindow w1,@SWHIDE,BUTTON_44

   CONTROL w1,@EDIT,"",35,45,70,22,@CTEDITNUMBER|@CTEDITAUTOH||ES_SUNKEN,EDIT_111 'User jump to line number
           CONTROLCMD w1,EDIT_111,@EDSETLIMITTEXT,255
           SETFONT w1,"Courier New",11,400,0,EDIT_111

   'Subroutines
   CONTROL w1,@BUTTON,"",155,17,25,25,@CTLBTNBITMAP,SubJump
           SETCONTROLTEXT w1,SubJump,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@BUTTON,"",155,47,25,25,@CTLBTNBITMAP,EndSubb
           SETCONTROLTEXT w1,EndSubb,GETSTARTPATH() + "\\Res\\jumpEnd.bmp"

   CONTROL w1,@BUTTON,"",155,75,25,25,@CTLBTNBITMAP,ClearSubs
           SETCONTROLTEXT w1,ClearSubs,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@BUTTON,"",185,47,25,25,@CTLBTNBITMAP,CopySubButton
           SETCONTROLTEXT w1,CopySubButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

   CONTROL w1,@BUTTON,"",215,47,25,25,@CTLBTNBITMAP,CopySubBlockButton
           SETCONTROLTEXT w1,CopySubBlockButton,GETSTARTPATH() + "\\Res\\block2.bmp"

   CONTROL w1,@BUTTON,"",245,47,25,25,@CTLBTNBITMAP,MoveSubButton
           SETCONTROLTEXT w1,MoveSubButton,GETSTARTPATH() + "\\Res\\Move2.bmp"

   CONTROL w1,@BUTTON,"",285,47,25,25,@CTLBTNBITMAP,DeleteSubButton
           SETCONTROLTEXT w1,DeleteSubButton,GETSTARTPATH() + "\\Res\\remove2.bmp"

   CONTROL w1,@BUTTON,"",328,47,25,25,@CTLBTNBITMAP,ShowSubButton
           SETCONTROLTEXT w1,ShowSubButton,GETSTARTPATH() + "\\Res\\show.bmp"

   'Windows
	CONTROL w1,@LISTVIEW,"",340,0,420,58,@BORDER|@LVSSHOWSELALWAYS|@LVSSORTASCENDING|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView4
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView4
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,0,"Window"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,0,150
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,1,"Begins"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,1,50
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,2,"Ends"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,2,50
			  CONTROLCMD w1,ListView4,@LVINSERTCOLUMN,3,"Handler name"
			  CONTROLCMD w1,ListView4,@LVSETCOLWIDTH,3,150
           showwindow w1,@SWHIDE,ListView4

   CONTROL w1,@STATIC," Windows && dialogs",425,0,167,20,@CTEDITLEFT|0x200,WinStatic
           SETCONTROLCOLOR w1,WinStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,WinStatic

   CONTROL w1,@COMBOBOX,"",425,19,207,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo4
           SETFONT w1,"Arial",11,400,0,Combo4

   CONTROL w1,@BUTTON,"",395,17,25,25,@CTLBTNBITMAP,WinJump
           SETCONTROLTEXT w1,WinJump,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@BUTTON,"",395,47,25,25,@CTLBTNBITMAP,EndWin
           SETCONTROLTEXT w1,EndWin,GETSTARTPATH() + "\\Res\\jumpEnd.bmp"

   CONTROL w1,@BUTTON,"",395,75,25,25,@CTLBTNBITMAP,ClearWins
           SETCONTROLTEXT w1,ClearWins,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@BUTTON,"",425,47,25,25,@CTLBTNBITMAP|0x200,WinHandler
           SETCONTROLTEXT w1,WinHandler,GETSTARTPATH() + "\\Res\\handle.bmp"

   CONTROL w1,@BUTTON,"",455,47,25,25,@CTLBTNBITMAP,CopyWinButton
           SETCONTROLTEXT w1,CopyWinButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

   CONTROL w1,@BUTTON,"",485,47,25,25,@CTLBTNBITMAP,CopyWinBlockButton
           SETCONTROLTEXT w1,CopyWinBlockButton,GETSTARTPATH() + "\\Res\\block2.bmp"

   CONTROL w1,@BUTTON,"",515,47,25,25,@CTLBTNBITMAP,MoveWinButton
           SETCONTROLTEXT w1,MoveWinButton,GETSTARTPATH() + "\\Res\\move2.bmp"

   CONTROL w1,@BUTTON,"",550,47,25,25,@CTLBTNBITMAP,DeleteWinButton
           SETCONTROLTEXT w1,DeleteWinButton,GETSTARTPATH() + "\\Res\\remove2.bmp"

   CONTROL w1,@BUTTON,"",583,47,25,25,@CTLBTNBITMAP,ShowWindowButton
           SETCONTROLTEXT w1,ShowWindowButton,GETSTARTPATH() + "\\Res\\show.bmp"

   'Bookmarks
   CONTROL w1,@STATIC," Bookmarks",680,0,167,20,@CTEDITLEFT|0x200,BookStatic
           SETCONTROLCOLOR w1,BookStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,BookStatic

	CONTROL w1,@LISTVIEW,"",870,590,250,80,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView6
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView6
			  CONTROLCMD w1,ListView6,@LVINSERTCOLUMN,0,"Line"
			  CONTROLCMD w1,ListView6,@LVSETCOLWIDTH,0,150
			  CONTROLCMD w1,ListView6,@LVINSERTCOLUMN,1,"Description"
			  CONTROLCMD w1,ListView6,@LVSETCOLWIDTH,1,100
           SHOWWINDOW w1,@SWHIDE,ListView6

   CONTROL w1,@COMBOBOX,"",680,19,160,500,@CTCOMBODROPDOWN|@VSCROLL|SS_NOTIFY|@TABSTOP,Combo6
           SETFONT w1,"Arial",10,400,0,Combo6

   CONTROL w1,@BUTTON,"",650,17,25,25,@CTLBTNBITMAP,BookJump
           SETCONTROLTEXT w1,BookJump,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@BUTTON,"",680,47,25,25,@CTLBTNBITMAP,BookAdd
           SETCONTROLTEXT w1,BookAdd,GETSTARTPATH() + "\\Res\\add.bmp"

   CONTROL w1,@BUTTON,"",710,47,25,25,@CTLBTNBITMAP,BookDel
           SETCONTROLTEXT w1,BookDel,GETSTARTPATH() + "\\Res\\minus.bmp"

   CONTROL w1,@BUTTON,"",750,47,25,25,@CTLBTNBITMAP,BookDelAll
           SETCONTROLTEXT w1,BookDelAll,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@BUTTON,"",790,47,25,25,@CTLBTNBITMAP,ShowBookMarksButton
           SETCONTROLTEXT w1,ShowBookMarksButton,GETSTARTPATH() + "\\Res\\show.bmp"

   'Block code
   CONTROL w1,@STATIC,"Insert",435,75,38,20,@CTEDITLEFT|0x200,STATIC_4
           SETCONTROLCOLOR w1,STATIC_4,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,STATIC_4

   CONTROL w1,@BUTTON,"",480,75,25,25,@CTLBTNBITMAP,BlockJumpButton
           SETCONTROLTEXT w1,BlockJumpButton,GETSTARTPATH() + "\\Res\\jump.bmp"

   CONTROL w1,@COMBOBOX,"",506,73,165,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo1
           PrintDir(GETSTARTPATH + "\\Res\\")
           SETFONT w1,"Arial",12,400,0,Combo1

   'Selects
	CONTROL w1,@LISTVIEW,"",870,590,400,80,@BORDER|@LVSSHOWSELALWAYS|@LVSSORTASCENDING|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView8
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView8
			  CONTROLCMD w1,ListView8,@LVINSERTCOLUMN,0,"Select"
			  CONTROLCMD w1,ListView8,@LVSETCOLWIDTH,0,150
			  CONTROLCMD w1,ListView8,@LVINSERTCOLUMN,1,"Begins"
			  CONTROLCMD w1,ListView8,@LVSETCOLWIDTH,1,50
			  CONTROLCMD w1,ListView8,@LVINSERTCOLUMN,2,"Ends"
			  CONTROLCMD w1,ListView8,@LVSETCOLWIDTH,2,50
			  CONTROLCMD w1,ListView8,@LVINSERTCOLUMN,3,"Subroutine"
			  CONTROLCMD w1,ListView8,@LVSETCOLWIDTH,3,150
           showwindow w1,@SWHIDE,ListView8

           CONTROL w1,@COMBOBOX,"",890,19,140,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo16
                   SETFONT w1,"Arial",10,400,0,Combo16

   CONTROL w1,@STATIC," Selects",890,0,167,20,@CTEDITLEFT|0x200,SelectStatic
           SETCONTROLCOLOR w1,SelectStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,SelectStatic

   CONTROL w1,@COMBOBOX,"",890,45,140,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo8
           SETFONT w1,"Arial",10,400,0,Combo8
					    int lvcountIn

			  CONTROL w1,@BUTTON,"",860,17,25,25,@CTLBTNBITMAP,SelectJump
					    SETCONTROLTEXT w1,SelectJump,GETSTARTPATH() + "\\Res\\jump.bmp"

			  CONTROL w1,@BUTTON,"",860,47,25,25,@CTLBTNBITMAP,SelectEnd
					    SETCONTROLTEXT w1,SelectEnd,GETSTARTPATH() + "\\Res\\jumpEnd.bmp"


   'Cases
	CONTROL w1,@LISTVIEW,"",870,590,250,80,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView10
			  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView10
			  CONTROLCMD w1,ListView10,@LVINSERTCOLUMN,0,"Case"
			  CONTROLCMD w1,ListView10,@LVSETCOLWIDTH,0,150
			  CONTROLCMD w1,ListView10,@LVINSERTCOLUMN,1,"Begins"
			  CONTROLCMD w1,ListView10,@LVSETCOLWIDTH,1,100
           showwindow w1,@SWHIDE,ListView10

   CONTROL w1,@STATIC," Cases",1080,0,167,20,@CTEDITLEFT|0x200,CaseStatic
           SETCONTROLCOLOR w1,CaseStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,CaseStatic

			  CONTROL w1,@COMBOBOX,"",1080,19,198,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo10
					    SETFONT w1,"Arial",10,400,0,Combo10

					    CONTROL w1,@BUTTON,"",1050,17,25,25,@CTLBTNBITMAP,CaseJump
								   SETCONTROLTEXT w1,CaseJump,GETSTARTPATH() + "\\Res\\jump.bmp"

                   CONTROL w1,@EDIT,"",1080,45,140,25,@CTEDITAUTOH|@CTEDITLEFT,EDIT_4
                           CONTROLCMD w1,EDIT_4,@EDSETLIMITTEXT,255
					            SETFONT w1,"Arial",10,400,0,EDIT_4
                           setcontrolnotify(w1,EDIT_4,1,1)

                   CONTROL w1,@BUTTON,"",1225,45,25,25,@CTLBTNBITMAP,ShowCasesButton
                           SETCONTROLTEXT w1,ShowCasesButton,GETSTARTPATH() + "\\Res\\show.bmp"

                   'CONTROL w1,@STATIC,"",1230,45,167,20,@CTEDITLEFT|0x200,CaseFindStatic
                           'SETCONTROLCOLOR w1,CaseFindStatic,RGB(0,0,0),WindowBackColour
                           'SETFONT w1,"Arial",10,400,0,CaseFindStatic

                   CONTROL w1,@BUTTON,"",1050,45,25,25,@CTLBTNBITMAP,CaseFind
                           SETCONTROLTEXT w1,CaseFind,GETSTARTPATH() + "\\Res\\find.bmp"

                   CONTROL w1,@BUTTON,"",1050,73,25,25,@CTLBTNBITMAP,CaseDelete
                           SETCONTROLTEXT w1,CaseDelete,GETSTARTPATH() + "\\Res\\delete.bmp"

                   CONTROL w1,@COMBOBOX,"",1080,73,180,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo14
			                  SETFONT w1,"Arial",10,400,0,Combo14
   'Top / botton buttons
   CONTROL w1,@BUTTON,"",1307,80,15,15,@CTLBTNBITMAP,TopButton
           SETCONTROLTEXT w1,TopButton,GETSTARTPATH() + "\\Res\\top.bmp"

   CONTROL w1,@BUTTON,"",1307,584,15,15,@CTLBTNBITMAP,BottomButton
           SETCONTROLTEXT w1,BottomButton,GETSTARTPATH() + "\\Res\\bottom.bmp"

   'Exit button
   CONTROL w1,@BUTTON,"Close",1240,620,80,25,@CTEDITLEFT,ExitButton
           SETCONTROLCOLOR w1,ExitButton,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,ExitButton

   'Includes
   CONTROL w1,@STATIC,"Include files",680,75,70,20,@CTEDITLEFT|0x200,IncludeStatic
           SETCONTROLCOLOR w1,IncludeStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,IncludeStatic

           CONTROL w1,@COMBOBOX,"",760,73,160,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo20
                   SETFONT w1,"Arial",12,400,0,Combo20

   'Navigation
	CONTROL w1,@COMBOBOX,"",160,75,200,500,@CTCOMBODROPDOWN|@VSCROLL|SS_NOTIFY|@TABSTOP,Combo18
			  SETFONT w1,"Arial",11,400,0,Combo18
           SHOWWINDOW w1,@SWHIDE,Combo18

	CONTROL w1,@BUTTON,"",5,75,26,25,@CTLBTNBITMAP,NavBackGrey
			  SETCONTROLTEXT w1,NavBackGrey,GETSTARTPATH() + "\\Res\\navbackgrey.bmp"

	CONTROL w1,@BUTTON,"",5,75,26,25,@CTLBTNBITMAP,NavBackButton
			  SETCONTROLTEXT w1,NavBackButton,GETSTARTPATH() + "\\Res\\navback.bmp"
           SHOWWINDOW w1,@SWHIDE,NavBackButton

	CONTROL w1,@BUTTON,"",35,75,25,25,@CTLBTNBITMAP,NavForwardGrey
			  SETCONTROLTEXT w1,NavForwardGrey,GETSTARTPATH() + "\\Res\\navforwardgrey.bmp"

	CONTROL w1,@BUTTON,"",35,75,25,25,@CTLBTNBITMAP,NavForwardButton
			  SETCONTROLTEXT w1,NavForwardButton,GETSTARTPATH() + "\\Res\\navforward.bmp"
           SHOWWINDOW w1,@SWHIDE,NavForwardButton

	CONTROL w1,@BUTTON,"",65,75,25,25,@CTLBTNBITMAP,NavButton
			  SETCONTROLTEXT w1,NavButton,GETSTARTPATH() + "\\Res\\add.bmp"

   CONTROL w1,@BUTTON,"",95,75,25,25,@CTLBTNBITMAP,NavDeleteButton
			  SETCONTROLTEXT w1,NavDeleteButton,GETSTARTPATH() + "\\Res\\delete.bmp"

   'Auto jump
   CONTROL w1,@CHECKBOX,"Auto jump to selections",195,73,180,25,@CTEDITLEFT,Check1
           SETCONTROLCOLOR w1,Check1,RGB(0,0,0),BackColour
           SETFONT w1,"Arial",11,400,0,Check1
           IF AutoJumpTo = 1
              SETSTATE w1,Check1,1
           ENDIF

   'Line
   'CONTROL w1,@STATIC,"Navigate",1,77,55,20,@CTEDITRIGHT|0x200,LinePosStatic
   'CONTROL w1,@EDIT,"",68,75,80,20,@CTEDITLEFT,LinePosEdit
   'showwindow w1,@SWHIDE,LinePosEdit

   'CONTROL w1,@STATIC,"Char",155,75,40,20,@CTEDITRIGHT|0x200,LineCharStatic
   CONTROL w1,@EDIT,"",204,75,80,20,@CTEDITLEFT,LineCharEdit
   showwindow w1,@SWHIDE,LineCharEdit

   'CONTROL w1,@STATIC,"Edit Pos",285,75,70,20,@CTEDITRIGHT|0x200,nwPosStatic
   CONTROL w1,@EDIT,"",364,75,80,20,@CTEDITLEFT,nwPosEdit
   showwindow w1,@SWHIDE,nwPosEdit

			  SETCONTROLCOLOR w1,LinePosStatic,RGB(0,0,0),WindowBackColour
			  SETCONTROLCOLOR w1,LineCharStatic,RGB(0,0,0),WindowBackColour
			  SETCONTROLCOLOR w1,nwPosStatic,RGB(0,0,0),WindowBackColour
           SETFONT w1,"Arial",10,400,0,LinePosStatic
           SETFONT w1,"Arial",10,400,0,LineCharStatic
           SETFONT w1,"Arial",10,400,0,nwPosStatic
           SETFONT w1,"Arial",10,400,0,LinePosEdit
           SETFONT w1,"Arial",10,400,0,LineCharEdit
           SETFONT w1,"Arial",10,400,0,nwPosEdit
           'SETFONT w1,"Arial",10,400,0,EditPosEdit

   'Key words
   CONTROL w1,@LISTVIEW,"",1050,0,200,60,@BORDER|@LVSNOCOLUMNHEADER|@LVSSHOWSELALWAYS|@LVSREPORT,ListView
           SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView
           CONTROLCMD w1,ListView,@LVINSERTCOLUMN,0,""
           CONTROLCMD w1,ListView,@LVSETCOLWIDTH,0,280
           CONTROLCMD w1,ListView,@LVINSERTITEM,0,""
           showwindow w1,@SWHIDE,ListView

   CONTROL w1,@EDIT,"",10,650,1000,20,@CTEDITLEFT,101
           showwindow w1,@SWHIDE,101

   'Key word search
   CONTROL w1,@COMBOBOX,"",372,617,210,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo12
			  SETFONT w1,"Arial",11,400,0,Combo12

			  CONTROL w1,@BUTTON,"",590,590,25,25,@CTLBTNBITMAP,KeyFind
						 SETCONTROLTEXT w1,KeyFind,GETSTARTPATH() + "\\Res\\find.bmp"

           CONTROL w1,@BUTTON,"",590,617,25,25,@CTLBTNBITMAP,KeyDelete
                   SETCONTROLTEXT w1,KeyDelete,GETSTARTPATH() + "\\Res\\delete.bmp"

		     CONTROL w1,@STATIC,"Key word search",350,590,120,25,@CTEDITRIGHT|0x200,KeyWordStatic
			          SETCONTROLCOLOR w1,KeyWordStatic,RGB(0,0,0),WindowBackColour
			          SETFONT w1,"Arial",10,400,0,KeyWordStatic

		     CONTROL w1,@STATIC,"",325,617,40,25,@CTEDITRIGHT|0x200,KeyWordResults
			          SETCONTROLCOLOR w1,KeyWordResults,RGB(0,0,0),WindowBackColour
			          SETFONT w1,"Arial",10,400,0,KeyWordResults

           CONTROL w1,@EDIT,"",480,590,100,25,@CTEDITAUTOH|@CTEDITLEFT|ES_UPPERCASE,EDIT_2
                   CONTROLCMD w1,EDIT_2,@EDSETLIMITTEXT,255
			          SETFONT w1,"Arial",10,400,0,EDIT_2
                   SETCONTROLNOTIFY(w1,EDIT_2,1,1)
                   MaskEditControl(w1,EDIT_2,LettersOnly)

   'Code word search
   INT CodeWordAndV = 1
   INT CodeWordOrV = 0
   CONTROL w1,@STATIC,"Single word search",580,590,160,25,@CTEDITRIGHT|0x200,CodeWordStatic
			  SETCONTROLCOLOR w1,CodeWordStatic,RGB(0,0,0),WindowBackColour
			  SETFONT w1,"Arial",10,400,0,CodeWordStatic

   CONTROL w1,@EDIT,"",750,590,100,25,@CTEDITAUTOH|@CTEDITLEFT,CodeWordEdit1
           CONTROLCMD w1,CodeWordEdit1,@EDSETLIMITTEXT,255
	        SETFONT w1,"Arial",10,400,0,CodeWordEdit1
           setcontrolnotify(w1,CodeWordEdit1,1,1)

           MaskEditControl(w1,CodeWordEdit1,LettersOnly)

			  CONTROL w1,@BUTTON,"",860,590,25,25,@CTLBTNBITMAP,CodeWordSearch
						 SETCONTROLTEXT w1,CodeWordSearch,GETSTARTPATH() + "\\Res\\find.bmp"

   CONTROL w1,@EDIT,"",750,618,100,25,@CTEDITAUTOH|@CTEDITLEFT,CodeWordEdit2
           CONTROLCMD w1,CodeWordEdit2,@EDSETLIMITTEXT,255
	        SETFONT w1,"Arial",10,400,0,CodeWordEdit2
           setcontrolnotify(w1,CodeWordEdit2,1,1)

           MaskEditControl(w1,CodeWordEdit2,LettersOnly)

           CONTROL w1,@BUTTON,"",860,618,25,25,@CTLBTNBITMAP,CodeWordDelete
                   SETCONTROLTEXT w1,CodeWordDelete,GETSTARTPATH() + "\\Res\\delete.bmp"

   CONTROL w1,@CHECKBOX,"And",640,620,45,25,@CTEDITLEFT,CodeWordAnd
			  SETCONTROLCOLOR w1,CodeWordAnd,RGB(0,0,0),WindowBackColour
			  SETFONT w1,"Arial",11,400,0,CodeWordAnd
           setstate w1,CodeWordAnd,1
           enablecontrol w1,CodeWordAnd,0

   CONTROL w1,@CHECKBOX,"Or",700,620,45,25,@CTEDITLEFT,CodeWordOr
			  SETCONTROLCOLOR w1,CodeWordOr,RGB(0,0,0),WindowBackColour
			  SETFONT w1,"Arial",11,400,0,CodeWordOr
           enablecontrol w1,CodeWordOr,0

   'Phrase search
   CONTROL w1,@STATIC,"Instring search",890,590,100,25,@CTEDITRIGHT|0x200,CodePhraseStatic
			  SETCONTROLCOLOR w1,CodePhraseStatic,RGB(0,0,0),WindowBackColour
			  SETFONT w1,"Arial",10,400,0,CodePhraseStatic

   CONTROL w1,@EDIT,"",1000,590,120,25,@CTEDITAUTOH|@CTEDITLEFT,CodePhraseEdit
           CONTROLCMD w1,CodePhraseEdit,@EDSETLIMITTEXT,255
	        SETFONT w1,"Arial",10,400,0,CodePhraseEdit
           setcontrolnotify(w1,CodePhraseEdit,1,1)

			  CONTROL w1,@CHECKBOX,"In line",1000,620,60,20,@CTEDITRIGHT,CodePhraseExact
					    SETCONTROLCOLOR w1,CodePhraseExact,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",10,400,0,CodePhraseExact
					    SETSTATE w1,CodePhraseExact,1

			  CONTROL w1,@CHECKBOX,"Words",1065,620,70,20,@CTEDITRIGHT,CodePhraseWords
					    SETCONTROLCOLOR w1,CodePhraseWords,RGB(0,0,0),WindowBackColour
					    SETFONT w1,"Arial",10,400,0,CodePhraseWords
					    SETSTATE w1,CodePhraseWords,0

			  CONTROL w1,@BUTTON,"",1130,590,25,25,@CTLBTNBITMAP,CodePhraseSearch
						 SETCONTROLTEXT w1,CodePhraseSearch,GETSTARTPATH() + "\\Res\\find.bmp"

           CONTROL w1,@BUTTON,"",1130,618,25,25,@CTLBTNBITMAP,PhraseDeleteButton
                   SETCONTROLTEXT w1,PhraseDeleteButton,GETSTARTPATH() + "\\Res\\delete.bmp"

                   INT CodePhraseExactV = 1
                   INT CodePhraseWordsV = 0

    'Load key words into a list view...
    CONTROLCMD w1,ListView,@LVINSERTITEM,0," "
	        FOR a = 1 TO 1661
		         CONTROLCMD w1,ListView,@LVINSERTITEM,a,#p[a].words
	        NEXT a

   ENABLECONTROL w1,1,1
   SETCONTROLNOTIFY(w1,1,1,1)

   ShowSubRoutineButtons(0)
   ShowWindowButtons(0)

   'Load file & details
   InitialLoad = 1

int x1 = GetTickCount()
'print GetTickCount()
   DoInitialLoad()
int x2 = GetTickCount()

print "Time taken ",x2-x1

   if ToolTips = 1
      DoToolTips()
   endif
   InitialLoad = 0
   Loading = 0

   OldLines = CONTROLCMD(w1,1,@RTGETLINECOUNT)

   STARTTIMER w1,TimerSpeed1,10000
   STARTTIMER w1,TimerSpeed1,10001
   STARTTIMER w1,ReIndexSpeed,10002

   WAITUNTIL ISWINDOWCLOSED(w1)
   CLOSECONSOLE
   Finish()

SUB Main(),INT

	 SELECT @MESSAGE

		CASE @IDCREATE
				CENTERWINDOW w1
				CONTROL w1,@LISTVIEW,"",0,0,270,58,@BORDER|@LVSSHOWSELALWAYS|@LVSSORTASCENDING|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListView2
						  SENDMESSAGE w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView2
						  CONTROLCMD w1,ListView2,@LVINSERTCOLUMN,0,"Subroutine"
						  CONTROLCMD w1,ListView2,@LVSETCOLWIDTH,0,150
						  CONTROLCMD w1,ListView2,@LVINSERTCOLUMN,1,"Begins"
						  CONTROLCMD w1,ListView2,@LVSETCOLWIDTH,1,50
						  CONTROLCMD w1,ListView2,@LVINSERTCOLUMN,2,"Ends"
						  SHOWWINDOW w1,@SWHIDE,ListView2

				CONTROL w1,@STATIC," Subroutines",180,2,150,20,@CTEDITLEFT,SubStatic
						  SETCONTROLCOLOR w1,SubStatic,RGB(0,0,0),WindowBackColour
						  SETFONT w1,"Arial",10,400,0,SubStatic

				CONTROL w1,@COMBOBOX,"",186,19,190,500,@CTCOMBODROPDOWN|@VSCROLL|@CTCOMBOSORT|SS_NOTIFY|@TABSTOP,Combo2
						  SETFONT w1,"Arial",11,400,0,Combo2

				CONTROL w1,@RICHEDIT,"",110,100,EndButtons-100,480,0x50B010C4,1
							SETFONT w1, "Courier New", 10, 400,0,1
							MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,1)
							REDRAWFRAME(w1,1)
							mask = CONTROLCMD(w1,1,@RTGETEVENTMASK)
							CONTROLCMD w1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS

							SETCONTROLTEXT w1,1,""
							SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,1
							SENDMESSAGE w1,EM_SHOWSCROLLBAR,SB_VERT,FALSE,1
							CONTROLCMD w1,1,@RTSETLIMITTEXT,500000
							SubclassRichEdit(w1,1)

				CONTROL w1,@SCROLLBAR,"",EndButtons+10,100,15,480,0x50000001,16

				CONTROL w1,@RICHEDIT,"",110,100,EndButtons-100,480,0x50B010C4,TextBlock1
							SETFONT w1, "Courier New", 10, 400,0,TextBlock1
							MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock1)
							REDRAWFRAME(w1,TextBlock1)
							mask = CONTROLCMD(w1,TextBlock1,@RTGETEVENTMASK)
							CONTROLCMD w1,TextBlock1,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS

							SETCONTROLTEXT w1,TextBlock1,""
							SendMessage w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock1
							CONTROLCMD w1,TextBlock1,@RTSETLIMITTEXT,10000
                     showwindow w1,@SWHIDE,TextBlock1

				CONTROL w1,@RICHEDIT,"",110,100,EndButtons-100,480,0x50B010C4,TextBlock2
							SETFONT w1, "Courier New", 10, 400,0,TextBlock2
							ModifyExStyle(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock2)
							ReDrawFrame(w1,TextBlock2)
							mask = CONTROLCMD(w1,TextBlock2,@RTGETEVENTMASK)
							CONTROLCMD w1,TextBlock2,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS

							SETCONTROLTEXT w1,TextBlock2,""
							SendMessage w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock2
							CONTROLCMD w1,TextBlock2,@RTSETLIMITTEXT,10000
                     showwindow w1,@SWHIDE,TextBlock2

				CONTROL w1,@RICHEDIT,"",110,100,EndButtons-100,480,0x50B010C4,TextBlock3
							SETFONT w1, "Courier New", 10, 400,0,TextBlock3
							ModifyExStyle(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock3)
							ReDrawFrame(w1,TextBlock3)
							mask = CONTROLCMD(w1,TextBlock3,@RTGETEVENTMASK)
							CONTROLCMD w1,TextBlock3,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS

							SETCONTROLTEXT w1,TextBlock3,""
							SendMessage w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock3
							CONTROLCMD w1,TextBlock3,@RTSETLIMITTEXT,10000
                     showwindow w1,@SWHIDE,TextBlock3

				CONTROL w1,@RICHEDIT,"",110,100,EndButtons-100,480,0x50B010C4,TextBlock4
							SETFONT w1, "Courier New", 10, 400,0,TextBlock4
							ModifyExStyle(w1,0,@EXCLIENTEDGE|WS_BORDER,TextBlock4)
							ReDrawFrame(w1,TextBlock4)
							mask = CONTROLCMD(w1,TextBlock4,@RTGETEVENTMASK)
							CONTROLCMD w1,TextBlock4,@RTSETEVENTMASK, mask | @ENMKEYEVENTS | @ENMSCROLL | @ENMCHANGE | ENM_MOUSEEVENTS

							SETCONTROLTEXT w1,TextBlock4,""
							SENDMESSAGE w1,EM_SETBKGNDCOLOR,0,ScreenColour,TextBlock4
							CONTROLCMD w1,TextBlock4,@RTSETLIMITTEXT,10000
                     SHOWWINDOW w1,@SWHIDE,TextBlock4

	CASE @IDVSCROLL
		SELECT @CONTROLID

			CASE 16 'Scrollbar

				SELECT @CODE

					     CASE @SBTHUMBTRACK
							    sRange.Low = GETSCROLLPOS(w1,16) * 16
                         cLine = GETSCROLLPOS(w1,16) + 1
                         StoreLine = cLine
							    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                         'ScrollWheel(1)
                         SETCONTROLTEXT(w1,EDIT_1,LTRIM$(STR$(cLine)))

					     CASE& @SBTHUMBPOS
							     SETSCROLLPOS w1,16,@QUAL

						  CASE @SBLINEUP
                         DoLineUp()

						  CASE @SBLINEDOWN
                         DoLineDown()

						  CASE @SBPAGEUP
								 SETSCROLLPOS(w1,16,GETSCROLLPOS(w1,16)-34)
                         ColourText()
								 sRange.Low = GETSCROLLPOS(w1,16) * 16
								 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)

						  CASE @SBPAGEDOWN
								 SETSCROLLPOS(w1,16,GETSCROLLPOS(w1,16)+34)
                         ColourText()
								 sRange.Low = GETSCROLLPOS(w1,16) * 16
								 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)

				ENDSELECT
      ENDSELECT

		CASE @IDCLOSEWINDOW
Finish()
           DoCloseProgram()

      CASE @IDMENUPICK
           SELECT @MENUNUM
                  CASE 201 'Cut
                       'CtrlDown = 1

							  IF LEN(CutLine)
								  SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
								  Undo2Count[OnTab] ++
								  Undo2[OnTab].Press[Undo2Count[OnTab]]  = 4
								  Undo2[OnTab].Length[Undo2Count[OnTab]]  = len(ClipText)
								  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = ClipText
								  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]  = cr.cpMin
								  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]  = cr.cpMax
								  UndoBlock[OnTab].Length[Undo2Count[OnTab]]  = len(ClipText)
								  UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]  = cLine-1
							  endif

                       CopyStringToClipboard(CutLine)
                       SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
                       SendMessage(rHandle,EM_SETSEL,cr.cpMin,cr.cpMax)
                       CONTROLCMD w1,1,@RTDELETESEL
                       return 0


                  case 202 'Copy
                       'CtrlDown = 1
                       CopyStringToClipboard(CutLine)
                       return 0

                  case 203 'Paste
                       'CtrlDown = 1
                       PasteOn = 1
                       Loading = 1

							  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
							  SendMessage(rHandle,WM_SETREDRAW,false,0)
                       DoPasteKeyBoard()

							  SendMessage(rHandle,WM_SETREDRAW,false,0)
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							  GetTheScrollPos(w1,1,rHandle)
							  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
							  InvalidateRect(rHandle,0,true)
							  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

							  for a = 1 to 30
								   setcontroltext(w1,a+1000,str$(FirstVisLine+(a+2)))
								   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
							  next a

                       SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1)
                       setfocus w1,1
                       Loading = 0
                       return 0

           endselect

           select @CODE
                  case 401 'Cut
							  if len(CutLine)
								  SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
								  Undo2Count[OnTab] ++
								  Undo2[OnTab].Press[Undo2Count[OnTab]]  = 4
								  Undo2[OnTab].Length[Undo2Count[OnTab]]  = len(ClipText)
								  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = ClipText
								  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]  = cr.cpMin
								  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]  = cr.cpMax
								  UndoBlock[OnTab].Length[Undo2Count[OnTab]]  = len(ClipText)
								  UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]  = cLine-1
							  ENDIF

                       CopyStringToClipboard(CutLine)

                       SENDMESSAGE(rHandle,EM_SETSEL,cr.cpMin,cr.cpMax)
                       CONTROLCMD w1,1,@RTDELETESEL
                       RETURN 0

                  CASE 402 'Copy
                       CopyStringToClipboard(CutLine)
                       RETURN 0

                  CASE 403 'Paste
                       Loading = 1
                       DoPaste()
                       FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
							  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
							  FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
							  GetTheScrollPos(w1,1,rHandle)
							  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
							  InvalidateRect(rHandle,0,true)
							  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
                       SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1)
                       SETFOCUS w1,1
                       Loading = 0
                       INT NewRange = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                       SETSCROLLRANGE w1,16,0,NewRange
                       RETURN 0

                  CASE 207 'Send to block
                       SendToBlock()

           endselect

      case @IDTIMER
			  select @CODE

					  case 10000

								int modd = CONTROLCMD(w1,1,@RTGETMODIFIED)
								if modd = 1

								endif

                       if getselected(w1,Combo2) = -1
                          ShowSubRoutineButtons(0)
                       ELSE
                          ShowSubRoutineButtons(1)
                       ENDIF
                       IF GETSELECTED(w1,Combo4) = -1
                          ShowWindowButtons(0)
                       ELSE
                          ShowWindowButtons(1)
                       ENDIF
							  handle = GetFocus()
							  IF handle = GETCONTROLHANDLE(w1,1)
									cLine = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1) + 1
									INT TvarStart = 0
									CONTROLCMD w1,1,@RTGETSELECTION,varStart,varEnd
									ppos = GETCARETPOSITION w1,AcrossX,DownY
									INT lvX = AcrossX
									INT lvY = DownY
									IF kw = 0
										SETSIZE w1,lvX+58,lvY+98,300,38,ListView
									ENDIF
									AcrossX --
									AcrossX = AcrossX / 8
									AcrossX ++
									EditPos = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
									EditPos = EditPos + AcrossX

									INT tStartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
									INT b1 = 0
									STRING WordBefore = ""
									INT length2 = CONTROLCMD(w1,1,@RTGETLINELENGTH,cLine-1)

									IF KeyUp = 1
										KeyUp = 0
										ScrollUpKey()
										cLine -= 1
										char_index = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine)
										SENDMESSAGE(GETCONTROLHANDLE(w1,1),EM_SETSEL,char_index,char_index)
										StoreLine = cLine
										RETURN 0
									ENDIF

									IF StoreLine <> cLine
										StoreLine = cLine
										ttx = varStart
										varEnd = varStart
										SHOWWINDOW w1,@SWHIDE,ListView
										SETCONTROLTEXT(w1,101,"")
										kw = 0
										DelFound = 0
										IF Skip = 1
											Skip = 0
										ELSE
											SetLines()
										ENDIF
										SETCONTROLTEXT(w1,LinePosEdit,LTRIM$(GETCONTROLTEXT(w1,1029)))
										IF AcrossX < 0 THEN AcrossX = 1
										setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
										setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
										setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
									endif

									if AcrossX < 0 then AcrossX = 0
									if EditPos < 0 then EditPos = 0
									if MouseWheel = 1
										MouseWheel = 0
										cLine = val(ltrim$(getcontroltext(w1,1030)))
										StoreLine = cLine
										setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
										setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
										setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
										SETCONTROLTEXT(w1,EditPosEdit,LTRIM$(STR$(EditPos)))
									ENDIF
							  ENDIF

							  INT OnLine = (sRange.Low / 16) + 1
							  SENDMESSAGE(w1.hWnd,EM_GETSCROLLPOS,0,sRange,1)

							  IF MouseWheel = 1
								  MouseWheel = 0
								  cLine = VAL(LTRIM$(GETCONTROLTEXT(w1,1030)))
								  StoreLine = cLine
								  'setcontroltext w1,STATIC_2,"On line " + ltrim$(getcontroltext(w1,1030)) + "  Line char pos " + ltrim$(str$(AcrossX)) + "  New word start pos " + ltrim$(str$(ttx)) +  "  Edit control pos " + ltrim$(str$(EditPos))
								  SETCONTROLTEXT(w1,LinePosEdit,LTRIM$(STR$(cLine)))
								  SETCONTROLTEXT(w1,LineCharEdit,LTRIM$(STR$(AcrossX)))
								  SETCONTROLTEXT(w1,nwPosEdit,LTRIM$(STR$(ttx)))
								  SETCONTROLTEXT(w1,EditPosEdit,LTRIM$(STR$(EditPos)))
							  ENDIF

					  CASE 10001
							  IF GETKEYSTATE(0x25) OR GETKEYSTATE(0x27) OR GETKEYSTATE(0x08) OR GETKEYSTATE(0x20)  'Left / right arrow keys
								  CONTROLCMD w1,1,@RTGETSELECTION,varStart,varEnd
								  ppos = GETCARETPOSITION w1,AcrossX,DownY
								  AcrossX --
								  AcrossX = AcrossX / 8
								  AcrossX ++
								  EditPos = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
								  EditPos = EditPos + AcrossX
								  IF kw = 0
									  ttx = varStart
								  ENDIF
							  ENDIF

							  if getkeystate(0x26) or getkeystate(0x28) 'Up arrow / down arrow keys
								  CONTROLCMD w1,1,@RTGETSELECTION,varStart,varEnd
								  ppos = GETCARETPOSITION w1,AcrossX,DownY
								  AcrossX --
								  AcrossX = AcrossX / 8
								  AcrossX ++
								  EditPos = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
								  EditPos = EditPos + AcrossX
								  if kw = 0
									  ttx = varStart
								  endif
							  endif

							  if getkeystate(0x0D) 'Enter key
								  if kw
									  SETCONTROLTEXT(w1,101,"")
									  STRING Line2$ = ""
									  STRING Line4$ = ""
								  ENDIF
								  StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
								  ttx = StartAt
								  varEnd = StartAt + 1
							  ENDIF

					  CASE 10002
                      IF Typing = 1 THEN RETURN 0
                      DoRebuild()

			  ENDSELECT

		CASE @IDCONTROL
			  SELECT @CONTROLID

           CASE ExitButton
                IF @NOTIFYCODE = 0
                   DoCloseProgram()
                ENDIF

           CASE BinButton
                IF @NOTIFYCODE = 0
                   WindowDelete(6)
                   IF DelConfirm = 1
							 CLS
							 Undo2Count[OnTab] = 0
							 Redo2Count[OnTab] = 0
                      ShowConfirm(-110)
                   ENDIF
                ENDIF

           CASE AutoButton
                IF @NOTIFYCODE = 0
                   AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   IF AutoCompleteKeyWords = 0
                      AutoCompleteStore = 0
                      SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOff.bmp"
                   ELSE
                      AutoCompleteStore = 1
                      SETCONTROLTEXT w1,AutoButton,GETSTARTPATH() + "\\Res\\SpellingOn.bmp"
                   ENDIF
                ENDIF

           CASE TopButton
                IF @NOTIFYCODE = 0
                   SETCONTROLTEXT(w1,EDIT_1,"1")
                   SETSCROLLPOS(w1,16,0)
                ENDIF

           CASE BottomButton
                IF @NOTIFYCODE = 0
                   INT BL = CONTROLCMD(w1,1,@RTGETLINECOUNT) - 1
                   setcontroltext(w1,EDIT_1,ltrim$(str$(BL)))
                   cLine = BL
                endif

           case NewButton
                if @NOTIFYCODE = 0
                   Loading = 1
                   DoMinimiseAll()
                   ProgPath = getstartpath + "\Res\\Untitled.iwb"
                   DoOpen(1)
                   ProgPath = getstartpath + "Untitled.iwb"
                   string NewFileCaption = getcaption w1
                   setcaption w1,NewFileCaption + "*"
                   if OnTab = 1
                      setcontroltext(w1,FileTab1,"Untitled.iwb*")
                   endif
                   if OnTab = 2
                      setcontroltext(w1,FileTab2,"Untitled.iwb*")
                   endif
                   if OnTab = 3
                      setcontroltext(w1,FileTab3,"Untitled.iwb*")
                   endif
                   if OnTab = 4
                      setcontroltext(w1,FileTab4,"Untitled.iwb*")
                   endif
                   if OnTab = 5
                      setcontroltext(w1,FileTab5,"Untitled.iwb*")
                   endif
                   if OnTab = 6
                      setcontroltext(w1,FileTab6,"Untitled.iwb*")
                   endif
                   Loading = 0
                endif

           case OpenButton
                if @NOTIFYCODE = 0
                   Loading = 1
                   DoMinimiseAll()
						 DoOpen()
						 if NoNewFile = 1
							 NoNewFile = 0
                      if OnTab = 1
                         DoRestore(0,1)
                      endif
                      if OnTab = 2
                         DoRestore(0,2)
                      endif
                      if OnTab = 3
                         DoRestore(0,3)
                      endif
                      if OnTab = 4
                         DoRestore(0,4)
                      endif
                      if OnTab = 5
                         DoRestore(0,5)
                      endif
                      if OnTab = 6
                         DoRestore(0,6)
                      endif
						 endif
						 if Restoring = 1
							 Restoring = 0
						 ENDIF
                   Loading = 0
                ENDIF

           CASE CloseButton
                IF @NOTIFYCODE = 0
                   ClearEditor()
                   IF OnTab = 1
                      buffer1 = ""
                      buffer1 = buffer2
                      buffer2 = ""
                      buffer2 = buffer3
                      buffer3 = ""
                      buffer3 = buffer4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[1] = RecentProgs[2]
                      RecentProgs[2] = RecentProgs[3]
                      RecentProgs[3] = RecentProgs[4]
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = ""
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[1]
                      GetFileName(w1,0,ProgPath,1)
                      SETCONTROLTEXT(w1,FileTab1,FileNameIs)
                      SETCONTROLTEXT(w1,FileTab2,GETCONTROLTEXT(w1,FileTab3))
                      setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab4))
                      setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
                      setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab6))
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab1)
							 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      if getcontroltext(w1,FileTab1) <> ""
                         DoRestore(0,1)
                      else
                         OnTab = 0
                         TabTaken = 0
                         Tab1Loaded = 0
                      endif
                   endif

                   if OnTab = 2
                      buffer2 = ""
                      buffer2 = buffer3
                      buffer3 = ""
                      buffer3 = buffer4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[2] = RecentProgs[3]
                      RecentProgs[3] = RecentProgs[4]
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = ""
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[2]
                      GetFileName(w1,0,ProgPath,1)
                      SETCONTROLTEXT(w1,FileTab2,FileNameIs)
                      SETCONTROLTEXT(w1,FileTab3,GETCONTROLTEXT(w1,FileTab4))
                      SETCONTROLTEXT(w1,FileTab4,GETCONTROLTEXT(w1,FileTab5))
                      SETCONTROLTEXT(w1,FileTab5,GETCONTROLTEXT(w1,FileTab6))
                      SETCONTROLTEXT(w1,FileTab6,"")
                      SHOWWINDOW w1,@SWHIDE,FileTab6
                      FileNameIs = GETCONTROLTEXT(w1,FileTab2)
							 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),Green
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,2)
                   ENDIF

                   IF OnTab = 3
                      buffer3 = ""
                      buffer3 = buffer4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[3] = RecentProgs[4]
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = ""
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[3]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab3,FileNameIs)
                      setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab5))
                      setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab5))
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab3)
							 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),Green
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,3)
                   endif

                   if OnTab = 4
                      buffer4 = ""
                      buffer4 = buffer5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[4] = RecentProgs[5]
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = ""
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[4]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab4,FileNameIs)
                      setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab5))
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab4)
							 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),Green
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,4)
                   ENDIF

                   IF OnTab = 5
                      buffer5 = ""
                      buffer5 = buffer6
                      buffer6 = ""
                      RecentProgs[5] = RecentProgs[6]
                      RecentProgs[6] = ""
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[5]
                      GetFileName(w1,0,ProgPath,1)
                      SETCONTROLTEXT(w1,FileTab5,FileNameIs)
                      SETCONTROLTEXT(w1,FileTab6,"")
                      SHOWWINDOW w1,@SWHIDE,FileTab6
                      FileNameIs = GETCONTROLTEXT(w1,FileTab5)
							 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),Green
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,5)
                   ENDIF

                   IF OnTab = 6
                      OnTab = 5
                      buffer6 = ""
                      RecentProgs[6] = ""
                      Tab6Loaded = 0
                      ProgCount = 5
                      ProgPath = RecentProgs[5]
                      GetFileName(w1,0,ProgPath,1)
                      setcontroltext(w1,FileTab5,FileNameIs)
                      setcontroltext(w1,FileTab6,"")
                      showwindow w1,@SWHIDE,FileTab6
                      FileNameIs = getcontroltext(w1,FileTab5)
							 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),Green
							 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
							 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
                      DoRestore(0,5)
                   endif

                   if getcontroltext(w1,FileTab1) <> ""
                      TabTaken = 1
                   else
                      Tab1Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab2) <> ""
                      TabTaken = 2
                   else
                      Tab2Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab3) <> ""
                      TabTaken = 3
                   else
                      Tab3Loaded = 0
                   endif

                   if getcontroltext(w1,FileTab4) <> ""
                      TabTaken = 4
                   ELSE
                      Tab4Loaded = 0
                   ENDIF

                   IF GETCONTROLTEXT(w1,FileTab5) <> ""
                      TabTaken = 5
                   ELSE
                      Tab5Loaded = 0
                   ENDIF

                   IF GETCONTROLTEXT(w1,FileTab5) <> ""
                      TabTaken = 5
                   ELSE
                      Tab5Loaded = 0
                   ENDIF

                   IF GETCONTROLTEXT(w1,FileTab6) <> ""
                      TabTaken = 6
                   ELSE
                      Tab6Loaded = 0
                   ENDIF

                   IF RecentProgs[1] = ""
                      buffer1 = ""
                      Tab1Loaded = 0
                      TabTaken = 0
                      SHOWWINDOW w1,@SWHIDE,FileTab1
                   ENDIF

                   IF RecentProgs[2] = ""
                      buffer2 = ""
                      TabTaken = 1
                      Tab2Loaded = 0
                      showwindow w1,@SWHIDE,FileTab2
                   endif

                   if RecentProgs[3] = ""
                      buffer3 = ""
                      TabTaken = 2
                      Tab3Loaded = 0
                      showwindow w1,@SWHIDE,FileTab3
                   endif

                   if RecentProgs[4] = ""
                      buffer4 = ""
                      TabTaken = 3
                      Tab4Loaded = 0
                      SHOWWINDOW w1,@SWHIDE,FileTab4
                   ENDIF

                   IF RecentProgs[5] = ""
                      buffer5 = ""
                      TabTaken = 4
                      Tab5Loaded = 0
                      SHOWWINDOW w1,@SWHIDE,FileTab5
                   ENDIF

                   IF RecentProgs[6] = ""
                      buffer6 = ""
                      TabTaken = 5
                      Tab6Loaded = 0
                      SHOWWINDOW w1,@SWHIDE,FileTab6
                   ENDIF

                   TabTaken = 0

					    IF OPENFILE(MyFile2,GETSTARTPATH + "\\Res\\" + "xeditor4.ini","W") = 0
						    FOR a = 1 TO ProgCount
								  IF RTRIM$(LTRIM$(RecentProgs[a])) <> ""
									  WRITE MyFile2,RecentProgs[a]
                             TabTaken ++
                             IF TabTaken = 1 THEN Tab1Loaded = 1
                             IF TabTaken = 2 THEN Tab2Loaded = 1
                             IF TabTaken = 3 THEN Tab3Loaded = 1
                             IF TabTaken = 4 THEN Tab4Loaded = 1
                             IF TabTaken = 5 THEN Tab5Loaded = 1
                             IF TabTaken = 6 THEN Tab6Loaded = 1
								  endif
						    next a
						    closefile MyFile2
					    endif

                   ProgCount = TabTaken

                   if TabTaken = 1
                      LoadTab(1)
                   endif

                   if TabTaken = 2
                      LoadTab(2)
                   endif

                   if TabTaken = 3
                      LoadTab(3)
                   endif

                   if TabTaken = 4
                      LoadTab(4)
                   endif

                   if TabTaken = 5
                      LoadTab(5)
                   endif

                endif

           case MinButton
                if @NOTIFYCODE = 0
                   if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4)) and !instr(getcaption(w1),getcontroltext(w1,FileTab5)) and !instr(getcaption(w1),getcontroltext(w1,FileTab6))
                      DoMinimise()
                   endif
                endif

           case FileTab1
                if @NOTIFYCODE = 0
                   showwindow w1,@SWHIDE,1
                   LoadTab(1)
                   setcaption w1,getcontroltext(w1,FileTab1)
                   showwindow w1,@SWSHOW,1
                endif

           case FileTab2
                if @NOTIFYCODE = 0
                   showwindow w1,@SWHIDE,1
                   LoadTab(2)
                   setcaption w1,getcontroltext(w1,FileTab2)
                   showwindow w1,@SWSHOW,1
                endif

           case FileTab3
                if @NOTIFYCODE = 0
                   LoadTab(3)
                   setcaption w1,getcontroltext(w1,FileTab3)
                endif

           case FileTab4
                if @NOTIFYCODE = 0
                   LoadTab(4)
                   SETCAPTION w1,GETCONTROLTEXT(w1,FileTab4)
                ENDIF

           CASE FileTab5
                IF @NOTIFYCODE = 0
                   LoadTab(5)
                   SETCAPTION w1,GETCONTROLTEXT(w1,FileTab5)
                ENDIF

           CASE FileTab6
                IF @NOTIFYCODE = 0
                   LoadTab(6)
                   SETCAPTION w1,GETCONTROLTEXT(w1,FileTab6)
                ENDIF

           CASE BackupButton
                IF @NOTIFYCODE = 0
                   BackupWindow()
						 IF Confirm = 1
							 STRING StoreBookFileD = GETSTARTPATH() + "Backup\\" + BackupDesc
							 CLOSEFILE MyFile2
							 IF OPENFILE(MyFile2,StoreBookFileD,"W") = 0
								 buffer = ""
								 buffer = GETCONTROLTEXT(w1,1)
								 WRITE MyFile2,buffer
							 ENDIF
							 CLOSEFILE MyFile2
						 ENDIF
                ENDIF

           CASE CogButton
                IF @NOTIFYCODE = 0
/*
                   ShowConfirm(99)
                   Loading = 1
                   DoSave(OnTab)
                   'showwindow w1,@SWHIDE,1
                   ClearEditor()
                   StartUp()
                   Mod = 0
                   Loading = 0

                   if OnTab = 1
							 if instr(getcontroltext(w1,FileTab1),"*")
								 setcontroltext(w1,FileTab1,mid$(getcontroltext(w1,FileTab1),1,instr(getcontroltext(w1,FileTab1),"*")-1))
							 endif
                   endif

                   if OnTab = 2
							 if instr(getcontroltext(w1,FileTab2),"*")
								 setcontroltext(w1,FileTab2,mid$(getcontroltext(w1,FileTab2),1,instr(getcontroltext(w1,FileTab2),"*")-1))
							 endif
                   endif

                   if OnTab = 3
							 if instr(getcontroltext(w1,FileTab3),"*")
								 setcontroltext(w1,FileTab3,mid$(getcontroltext(w1,FileTab3),1,instr(getcontroltext(w1,FileTab3),"*")-1))
							 endif
                   endif

                   if OnTab = 4
							 if instr(getcontroltext(w1,FileTab4),"*")
								 setcontroltext(w1,FileTab4,mid$(getcontroltext(w1,FileTab4),1,instr(getcontroltext(w1,FileTab4),"*")-1))
							 endif
                   endif

                   if OnTab = 5
							 if instr(getcontroltext(w1,FileTab5),"*")
								 setcontroltext(w1,FileTab5,mid$(getcontroltext(w1,FileTab5),1,instr(getcontroltext(w1,FileTab5),"*")-1))
							 endif
                   endif

                   if OnTab = 6
							 if instr(getcontroltext(w1,FileTab6),"*")
								 setcontroltext(w1,FileTab6,mid$(getcontroltext(w1,FileTab6),1,instr(getcontroltext(w1,FileTab6),"*")-1))
							 endif
                   endif
                   'showwindow w1,@SWSHOW,1
                   ShowConfirm(-100)
                   setfocus w1,1

*/
                   ShowConfirm(99)
                   DoRebuild()
                   ShowConfirm(-100)
                endif

           case NavButton
                if @NOTIFYCODE = 0
                   int FirstNavLine = val(getcontroltext(w1,1002))
                   FirstNavLine --

                   int DupNavMark = 0
                   FOR a = 0 TO GETSTRINGCOUNT(w1,Combo18) - 1
                       STRING NavString = GETSTRING(w1,Combo18,a)
                       IF LTRIM$(STR$(FirstNavLine)) = LTRIM$(NavString)
                          DupNavMark = 1
                          BREAKFOR
                       ENDIF
                   NEXT a

                   IF DupNavMark = 0
                      NavMax ++
                      INSERTSTRING(w1,Combo18,NavMax-1,LTRIM$(STR$(FirstNavLine)))
                      ShowConfirm(18)
                      IF NavMax > 1
								 SHOWWINDOW w1,@SWSHOW,NavBackButton
								 SHOWWINDOW w1,@SWSHOW,NavForwardButton
								 SHOWWINDOW w1,@SWHIDE,NavBackGrey
								 SHOWWINDOW w1,@SWHIDE,NavForwardGrey
                      ENDIF
							 IF NavMax = 1
								 SHOWWINDOW w1,@SWSHOW,NavBackButton
								 SHOWWINDOW w1,@SWHIDE,NavBackGrey
								 RETURN 0
							 ENDIF
                   ENDIF
                ENDIF

           CASE NavBackButton
                IF @NOTIFYCODE = 0
                   IF NavMax = 0 THEN RETURN 0
                   IF NavPos = 1
                      SHOWWINDOW w1,@SWHIDE,NavBackButton
                      SHOWWINDOW w1,@SWSHOW,NavBackGrey
                   ENDIF
                   IF NavPos = 0
                      NavPos = NavMax
                   ELSE
                      NavPos --
                      IF NavPos <= 1
                         NavPos = 1
                         SHOWWINDOW w1,@SWHIDE,NavBackButton
                         SHOWWINDOW w1,@SWSHOW,NavBackGrey
                      ENDIF
                   ENDIF
                   SETCONTROLTEXT(w1,EDIT_1,GETSTRING(w1,Combo18,NavPos-1))
                   IF NavPos < NavMax
                      SHOWWINDOW w1,@SWSHOW,NavForwardButton
                      SHOWWINDOW w1,@SWHIDE,NavForwardGrey
                   ENDIF
                ENDIF

           CASE NavForwardButton
                IF @NOTIFYCODE = 0
                   IF NavMax = 0 THEN RETURN 0
                   IF NavPos = NavMax
                         SHOWWINDOW w1,@SWHIDE,NavForwardButton
                         SHOWWINDOW w1,@SWSHOW,NavForwardGrey
                   ENDIF
                   IF NavPos = 0
                      NavPos = 1
                   ELSE
                      NavPos ++
                      SHOWWINDOW w1,@SWSHOW,NavBackButton
                      SHOWWINDOW w1,@SWHIDE,NavBackGrey
                      IF NavPos >= NavMax
                         NavPos = NavMax
                         SHOWWINDOW w1,@SWHIDE,NavForwardButton
                         SHOWWINDOW w1,@SWSHOW,NavForwardGrey
                      ENDIF
                   ENDIF
                   SETCONTROLTEXT(w1,EDIT_1,GETSTRING(w1,Combo18,NavPos-1))
                ENDIF

           CASE NavDeleteButton
                IF @NOTIFYCODE = 0
						 SHOWWINDOW w1,@SWHIDE,NavBackButton
						 SHOWWINDOW w1,@SWHIDE,NavForwardButton
						 SHOWWINDOW w1,@SWSHOW,NavBackGrey
						 SHOWWINDOW w1,@SWSHOW,NavForwardGrey
                   SendMessage(GetDlgItem(w1.hwnd,Combo18),CB_RESETCONTENT,0,0)
                   NavPos = 0
                   NavMax = 0
                endif

           case SaveButton
                if @NOTIFYCODE = 0
				       if !instr(ProgPath,IncludePath)
                      DoSave()
                   else
                      ShowConfirm(-40)
                   endif
                endif

           case SaveAsButton
                if @NOTIFYCODE = 0
                   DoSaveAs()
                endif

           case CopySubButton 'Copy sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif
                   CutLine = ""
                   GetSub(w1,1)
                   ShowConfirm(1)
                endif

           case CopySubBlockButton 'Copy sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif
                   CutLine = ""
                   GetSub(w1,1,1)
                   ShowConfirm(2)
                endif

           case MoveSubButton 'Move sub
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo2)) = -1
                      ShowConfirm(-2)
                      setfocus w1,Combo2
                      return 0
                   endif

                   'Copy sub to clipboard
                   CutLine = ""
                   GetSub(w1,1,1)

                   'Delete sub
                   RemoveSub(w1,ListView4,Combo4,1)

                   'Paste sub to new location
					    Loading = 1
					    DoPaste()
					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
					    SendMessage(rHandle,WM_SETREDRAW,false,0)
					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    GetTheScrollPos(w1,1,rHandle)
					    SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
					    InvalidateRect(rHandle,0,true)
					    SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					    SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1)
					    setfocus w1,1
					    Loading = 0
                endif

           case MoveWinButton 'Move window
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif

                   MoveToPosition = cLine

                   CutLine = "" 'Copy sub
                   GetSubToFile(w1,ListView4,1)
                   RemoveSub(w1,ListView4,Combo4,1)

						 INT char_index1 = CONTROLCMD (w1,1,@RTCHARFROMLINE,MoveToPosition-1)
						 CONTROLCMD w1,1,@RTSETSELECTION,char_index1,char_index1
					 	 SetLines()

						 BlockIn = GETSTARTPATH() + "\\Res\\xtemp.txt"
						 INT count = ReadBlock(BlockIn)

						 CopyStringToClipBoard(CutLine)

					    ReadClipBoard()
					    StorecLine = MoveToPosition

					    CONTROLCMD w1,1,@RTPASTE

					    rHandle = GETCONTROLHANDLE(w1,1)
					    SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,0)
					    SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

					    FOR a = MoveToPosition-1 TO MoveToPosition + (count-1)
							  char_index = CONTROLCMD (w1,1,@RTCHARFROMLINE,a-1)
							  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
							  ColourLineZ(rHandle,a-1,line$,char_index)
					    NEXT a

					    SENDMESSAGE(rHandle,WM_SETREDRAW,true,0)
					    InvalidateRect(rHandle,0,true)
					    SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					    ShowCursor(TRUE)

					    int lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
					    ADDSTRING w1,Combo4,StoreSubName
					    lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
					    for a = 0 to lvcount2
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
							  if ucase$(StoreSubName) = ucase$(text)
								  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,ltrim$(str$(MoveToPosition)))
								  CONTROLCMD w1,ListView4,@LVSETTEXT,a,2,ltrim$(str$((MoveToPosition + count) - 1))
								  breakfor
							  endif
					    next a

					    MoveBlocks(cLine,LineCount-1,1)

                   SETSELECTED(w1,Combo4,-1)

                ENDIF

           CASE ShowWindowButton 'Window details
                IF @NOTIFYCODE = 0
                   IF ISWINDOWCLOSED(w8) = 0
                      CLOSEWINDOW w8
                   ENDIF
                   WindowDetails(4)
                ENDIF

           CASE ClearWins 'Clear Win selection
                IF @NOTIFYCODE = 0
                   SETSELECTED(w1,Combo4,-1)
                   ShowWindowButtons(0)
                ENDIF

           CASE ShowSubButton 'Sub details
                IF @NOTIFYCODE = 0
                   IF ISWINDOWCLOSED(w8) = 0
                      CLOSEWINDOW w8
                   ENDIF
                   WindowDetails(2)
                ENDIF

           CASE ClearSubs 'Clear Sub selection
                IF @NOTIFYCODE = 0
                   SETSELECTED(w1,Combo2,-1)
                   ShowSubroutineButtons(0)
                ENDIF

           CASE DeleteSubButton 'Remove sub
                IF @NOTIFYCODE = 0
                   IF (GETSELECTED(w1,Combo2)) = -1
                      ShowConfirm(-2)
                      SETFOCUS w1,Combo2
                      INT NewRangeDel = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                      SETSCROLLRANGE w1,16,0,NewRangeDel
                      RETURN 0
                   ENDIF
                   IF ConfirmMessage = 0
                      RemoveSub(w1,ListView2,Combo2)
                      DelConfirm = 0
                      NewRangeDel = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                      SETSCROLLRANGE w1,16,0,NewRangeDel
                      RETURN 0
                   ENDIF
                   WindowDelete(2)
                   IF DelConfirm = 1
                      RemoveSub(w1,ListView2,Combo2)
                   ENDIF
                   DelConfirm = 0
                   NewRangeDel = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                   SETSCROLLRANGE w1,16,0,NewRangeDel
                ENDIF

           CASE CopyWinButton 'Copy window
                IF @NOTIFYCODE = 0
                   IF (GETSELECTED(w1,Combo4)) = -1
                      ShowConfirm(-4)
                      SETFOCUS w1,Combo4
                      RETURN 0
                   ENDIF
                   CutLine = ""
                   GetWindowE(w1,1)
                   ShowConfirm(1)
                ENDIF

           CASE CopyWinBlockButton 'Copy window
                IF @NOTIFYCODE = 0
                   IF (GETSELECTED(w1,Combo4)) = -1
                      ShowConfirm(-4)
                      SETFOCUS w1,Combo4
                      RETURN 0
                   ENDIF
                   CutLine = ""
                   GetWindowE(w1,1,1)
                   ShowConfirm(2)
                endif

           case DeleteWinButton 'Remove window
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo4)) = -1
                      ShowConfirm(-4)
                      setfocus w1,Combo4
                      return 0
                   endif
                   WindowDelete(4)
                   if DelConfirm = 1
                      RemoveWindow(w1,1)
                   endif
                   DelConfirm = 0
                   NewRangeDel = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                   SETSCROLLRANGE w1,16,0,NewRangeDel
                endif

           case CopyBlockButton
                if @NOTIFYCODE = 0
                   if OnBlock = 1
                      CutLine = ""
                      CutLine = getcontroltext(w1,TextBlock1)
                      CopyStringToClipboard(CutLine)
                   endif
                   if OnBlock = 2
                      CutLine = ""
                      CutLine = getcontroltext(w1,TextBlock2)
                      CopyStringToClipboard(CutLine)
                   endif
                   if OnBlock = 3
                      CutLine = ""
                      CutLine = getcontroltext(w1,TextBlock3)
                      CopyStringToClipboard(CutLine)
                   endif
                   if OnBlock = 4
                      CutLine = ""
                      CutLine = getcontroltext(w1,TextBlock4)
                      CopyStringToClipboard(CutLine)
                   endif
                endif

           case DeleteBlockButton
                if @NOTIFYCODE = 0
                   if OnBlock = 1
                      setcontroltext(w1,TextBlock1,"")
                      enablecontrol w1,ShowBlock1,0
                      FocusMain()
                   endif
                   if OnBlock = 2
                      setcontroltext(w1,TextBlock2,"")
                      enablecontrol w1,ShowBlock2,0
                      FocusMain()
                   endif
                   if OnBlock = 3
                      setcontroltext(w1,TextBlock3,"")
                      enablecontrol w1,ShowBlock3,0
                      FocusMain()
                   endif
                   if OnBlock = 4
                      SETCONTROLTEXT(w1,TextBlock4,"")
                      ENABLECONTROL w1,ShowBlock4,0
                      FocusMain()
                   ENDIF
                ENDIF

           CASE ShowCode
                IF @NOTIFYCODE = 0
                   FocusMain()
                ENDIF

           CASE ShowBlock1
                IF @NOTIFYCODE = 0
                   FocusBlock1()
                ENDIF

           CASE ShowBlock2
                IF @NOTIFYCODE = 0
                   FocusBlock2()
                ENDIF

           CASE ShowBlock3
                IF @NOTIFYCODE = 0
                   FocusBlock3()
                ENDIF

           CASE ShowBlock4
                IF @NOTIFYCODE = 0
                   FocusBlock4()
                ENDIF

           CASE BookAdd
                IF @NOTIFYCODE = 0
						 handle = GetFocus()
						 INT NoLineClicked = 1
						 STRING StringLineNo = ""
						 FOR a = 1 TO 30
							  StringLineNo = GETCONTROLTEXT(w1,a+1000)
							  IF INSTR(StringLineNo,">")
								  NoLineClicked = 0
								  BREAKFOR
							  ENDIF
						 NEXT a
						 IF NoLineClicked = 1
							 ShowConfirm(-66)
						 RETURN 0
						 ENDIF

                   INT DupBookMark = 0
                   FOR b = 0 TO GETSTRINGCOUNT(w1,Combo6) - 1
                       STRING BookString = GETSTRING(w1,Combo6,b)
                       STRING BookLineNumber = BookString
                       IF INSTR(BookLineNumber," ")
                          BookLineNumber = MID$(BookLineNumber,1,INSTR(BookLineNumber," ")-1)
                       ENDIF
                       if BookLineNumber = ltrim$(str$(cLine))
                          DupBookMark = 1
                          breakfor
                       endif
                   next b

                   if DupBookMark = 0
                      StringLineNo = rtrim$(ltrim$(mid$(StringLineNo,instr(StringLineNo,">")+1,len(StringLineNo))))
                      cLine = val(StringLineNo)
                      BookmarkWindow()
                      lvcountIn = CONTROLCMD(w1,ListView6,@LVGETCOUNT)
					       CONTROLCMD w1,ListView6,@LVINSERTITEM,lvcountIn+1,StringLineNo
					       CONTROLCMD w1,ListView6,@LVSETTEXT,lvcountIn+1,1,BookMarkDesc
                      addstring w1,Combo6,StringLineNo + " " + BookMarkDesc
                      ShowConfirm(6)
                      SortBookMarks()
                   else
                      ShowConfirm(66)
                   endif
                   BookMarkDesc = ""
                endif

           case BookDel
                if @NOTIFYCODE = 0
                   if (getselected(w1,Combo6)) = -1
                      ShowConfirm(-6)
                      setfocus w1,Combo6
                      return 0
                   endif
						 deletestring(w1,Combo6,getselected(w1,Combo6))
						 setselected w1,Combo6,-1
                endif

           case BookDelAll
                if @NOTIFYCODE = 0
                   SendMessage(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
                   CONTROLCMD(w1,ListView6,@LVDELETEALL)
						 setselected w1,Combo6,-1
                ENDIF

           CASE ShowBookmarksButton
                IF @NOTIFYCODE = 0
                   IF ISWINDOWCLOSED(w14) = 0
                      CLOSEWINDOW w14
                   ENDIF
                   WindowBookmarks()
                ENDIF

           CASE Combo6
                IF @NOTIFYCODE = @CBNSELCHANGE AND DoingOpen = 0
                   IF AutoJumpTo = 1
                      STRING Combo6String = GETSTRING(w1,Combo6,GETSELECTED(w1,Combo6))
                      IF INSTR(Combo6String," ")
                         SETCONTROLTEXT(w1,EDIT_1,MID$(Combo6String,1,INSTR(Combo6String," ")-1))
                      ELSE
                         SETCONTROLTEXT(w1,EDIT_1,Combo6String)
                      ENDIF
                   ENDIF
                ENDIF

           CASE Combo8
                IF @NOTIFYCODE = @CBNSELCHANGE AND DoingOpen = 0
                   DoCombo8()
                ENDIF

           CASE SelectJump
                IF @NOTIFYCODE = 0
                   IF GETSELECTED(w1,Combo8) = -1 THEN RETURN 0
                   SETCONTROLTEXT(w1,EDIT_1,TextIn1)
                   Combo10Add()
                   setfocus w1
                endif

           case SelectEnd
                if @NOTIFYCODE = 0
                   if getselected(w1,Combo8) = -1 then return 0
                   setcontroltext(w1,EDIT_1,TextIn2)
                endif

           case Combo10
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   if AutoJumpTo = 1
                      goto AutoJumpCombo10
                   endif
                endif

           case CaseJump
                if @NOTIFYCODE = 0
                   label AutoJumpCombo10
                   if getselected(w1,Combo10) = -1 then return 0
                   string lv10String = getstring(w1,Combo10,getselected(w1,Combo10))
					    CONTROLCMD(w1,ListView10,@LVGETTEXT,getselected(w1,Combo10),0,TextInName)
				       CONTROLCMD(w1,ListView10,@LVGETTEXT,getselected(w1,Combo10),1,TextIn1)
                   setcontroltext(w1,EDIT_1,TextIn1)
                endif

           case ShowCasesButton
                if @NOTIFYCODE = 0
                   if iswindowclosed(w14) = 1
                      WindowCases()
                   endif
                endif

           case EDIT_2 'Search key words
                if @NOTIFYCODE = @ENCHANGE
                   SendMessage(GetDlgItem(w1.hwnd, Combo12),CB_RESETCONTENT,0,0)
					    for a = 1 to 1661
							  if instr(#p[a].words,ucase$(getcontroltext(w1,EDIT_2)))
								  addstring(w1,Combo12,#p[a].words)
							  endif
					    next a
                   setselected(w1,Combo12,0)

						 if getstringcount(w1,Combo12) > 0
							 setcontroltext(w1,KeyWordResults,"(" + ltrim$(str$(getstringcount(w1,Combo12))) + ")")
						 else
							 setcontroltext(w1,KeyWordResults,"(0)")
						 endif

                   if len(getcontroltext(w1,EDIT_2)) = 0
                      setcontroltext(w1,KeyWordResults,"")
                      closewindow w2
                   endif

                   int Combo12Count
                   string Combo12String
                endif

           case KeyFind
                if @NOTIFYCODE = 0
                   if getcontroltext(w1,EDIT_2) = ""
                      setfocus w1,EDIT_2
                      return 0
                   endif
                   WindowSearch()
                endif

           case KeyDelete
                if @NOTIFYCODE = 0
                   closewindow w2
                   SendMessage(GetDlgItem(w1.hwnd,Combo12),CB_RESETCONTENT,0,0)
                   setcontroltext(w1,EDIT_2,"")
                   setfocus w1,EDIT_2
                endif

           case ListViewResult
					 if @NOTIFYCODE=@NMCLICK
                   label ClickListViewResult
						 lvpos=*<NMLISTVIEW>@LPARAM.iItem
						 CONTROLCMD(w1,ListViewResult,@LVGETTEXT,lvpos,0,text)
						 setcontroltext(w1,EDIT_1,text)
					 endif

           case EDIT_4 'Search cases
                IF @NOTIFYCODE = @ENENTERKEY
                   GOTO DoCaseFind
                ENDIF

                IF @NOTIFYCODE = @ENCHANGE
                   Combo12Count = GETSTRINGCOUNT(w1,Combo10)
                   FOR a = 0 TO Combo12Count - 1
                       Combo12String = UCASE$(GETSTRING(w1,Combo10,a))
                       IF INSTR(Combo12String,UCASE$(GETCONTROLTEXT(w1,EDIT_4)))
								  SETSELECTED(w1,Combo10,a)
								  BREAKFOR
                       ENDIF
                   NEXT a
                ENDIF

           CASE CaseFind 'Search cases (generic)
                IF @NOTIFYCODE = 0
                   LABEL DoCaseFind
                   SENDMESSAGE(GetDlgItem(w1.hwnd,Combo14),CB_RESETCONTENT,0,0)
                   Combo12Count = GETSTRINGCOUNT(w1,Combo10)
                   FOR a = 0 TO Combo12Count - 1
                       Combo12String = GETSTRING(w1,Combo10,a)
                       IF INSTR(UCASE$(Combo12String),UCASE$(GETCONTROLTEXT(w1,EDIT_4)))
                          ADDSTRING(w1,Combo14,Combo12String) '+ " - " + ltrim$(str$(a)))
                       ENDIF
                   NEXT a
                   SETSELECTED(w1,Combo14,0)
                   SETCONTROLTEXT(w1,CaseFindStatic,"(" + LTRIM$(STR$(GETSTRINGCOUNT(w1,Combo14))) + ")")
                ENDIF

           CASE Combo14
                IF @NOTIFYCODE = @CBNSELCHANGE
                   STRING Combo14String = GETSTRING(w1,Combo14,GETSELECTED(w1,Combo14))
					    lvcountIn = CONTROLCMD(w1,ListView10,@LVGETCOUNT)
					    FOR a = 0 TO lvcountIn - 1
							  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
                       IF text = Combo14String
                          STRING text4 = ""
							     CONTROLCMD(w1,ListView10,@LVGETTEXT,a,1,text4)
                          SETSELECTED (w1,Combo10,a)
                          BREAKFOR
                       ENDIF
                   NEXT a
                ENDIF

           CASE CaseDelete
                IF @NOTIFYCODE = 0
                   SETCONTROLTEXT(w1,EDIT_4,"")
                   SETCONTROLTEXT(w1,CaseFindStatic,"")
                   SENDMESSAGE(GetDlgItem(w1.hwnd,Combo14),CB_RESETCONTENT,0,0)
                   SETFOCUS w1,EDIT_4
                ENDIF

           CASE Combo16
                IF @NOTIFYCODE = @CBNSELCHANGE AND DoingOpen = 0
                   DoSelect16()
                endif

           case CodeWordAnd
                if @NOTIFYCODE = 0
                   CodeWordAndV = 1 - CodeWordAndV
                   CodeWordOrV  = 1 - CodeWordOrV
                   setstate w1,CodeWordAnd,CodeWordAndV
                   setstate w1,CodeWordOr,CodeWordOrV
                   setfocus w1
                endif

           case CodeWordOr
                if @NOTIFYCODE = 0
                   CodeWordAndV = 1 - CodeWordAndV
                   CodeWordOrV  = 1 - CodeWordOrV
                   setstate w1,CodeWordAnd,CodeWordAndV
                   setstate w1,CodeWordOr,CodeWordOrV
                   setfocus w1
                endif

           case CodeWordEdit1
                if @NOTIFYCODE = @ENENTERKEY
                   setfocus w1,CodeWordEdit2
                endif

                if @NOTIFYCODE = @ENCHANGE
                   if len(getcontroltext(w1,CodeWordEdit2)) = 0 or len(getcontroltext(w1,CodeWordEdit1)) = 0
                      enablecontrol w1,CodeWordAnd,0
                      enablecontrol w1,CodeWordOr,0
                   else
                      enablecontrol w1,CodeWordAnd,1
                      enablecontrol w1,CodeWordOr,1
                   endif
                endif

           case CodeWordEdit2
                if @NOTIFYCODE = @ENENTERKEY
                   WindowSearchCode()
                endif

                if @NOTIFYCODE = @ENCHANGE
                   if len(getcontroltext(w1,CodeWordEdit2)) = 0 or len(getcontroltext(w1,CodeWordEdit1)) = 0
                      enablecontrol w1,CodeWordAnd,0
                      enablecontrol w1,CodeWordOr,0
                   else
                      enablecontrol w1,CodeWordAnd,1
                      enablecontrol w1,CodeWordOr,1
                   endif
                endif

           case CodeWordSearch
                if @NOTIFYCODE = 0
                   if (getcontroltext(w1,CodeWordEdit1)) = ""
                      setfocus w1,CodeWordEdit1
                      return 0
                   endif
                   WindowSearchCode()
                endif

           case CodeWordDelete
                IF @NOTIFYCODE = 0
                   CLOSEWINDOW w4
                   SETCONTROLTEXT(w1,CodeWordEdit1,"")
                   SETCONTROLTEXT(w1,CodeWordEdit2,"")
                   CodeWordAndV = 1
                   CodeWordOrV = 0
                   SETSTATE w1,CodeWordOr,0
                   SETSTATE w1,CodeWordAnd,1
                   ENABLECONTROL w1,CodeWordAnd,0
                   ENABLECONTROL w1,CodeWordOr,0
                   SETFOCUS w1,CodeWordEdit1
                ENDIF

           CASE CodePhraseEdit
                IF @NOTIFYCODE = @ENCHANGE
                   IF LEN(GETCONTROLTEXT(w1,CodePhraseEdit)) < LEN(NewEdit)
                      NewEdit = GETCONTROLTEXT(w1,CodePhraseEdit)
                   ENDIF
                   INT Spaces = 0
                   INT SpacePos = 0
                   STRING WordsToLookup = GETCONTROLTEXT(w1,CodePhraseEdit)
                   a = 0
                   IF INSTR(WordsToLookup," ") <> 0
                      DO
                        a ++
                        IF MID$(WordsToLookup,a,1) = " "
                           SpacePos = a
                        ENDIF

                      UNTIL INSTR(WordsToLookup," ") = 0 OR a = LEN(WordsToLookup)
                   ENDIF
						 IF SpacePos = 0
							 Search_And_Highlight(1,getcontroltext(w1,CodePhraseEdit),1)
						 else
							 Search_And_Highlight(1,mid$(WordsToLookup,SpacePos + 1,len(WordsToLookup)),1)
						 endif
                endif

                if @NOTIFYCODE = @ENENTERKEY
                   showwindow w1,@SWHIDE,ListView
                   if (getcontroltext(w1,CodePhraseEdit)) = ""
                      setfocus w1,CodePhraseEdit
                      return 0
                   endif
						 WordsToLookup = mid$(WordsToLookup,1,SpacePos+1)
						 NewEdit = NewEdit + " " + InfoA
						 NewEdit = ltrim$(NewEdit)
						 setcontroltext(w1,CodePhraseEdit,NewEdit)
						 AppendEdit(w1,CodePhraseEdit,"",0)
                   showwindow w1,@SWHIDE,ListView
                endif

           case CodePhraseExact
                if @NOTIFYCODE = 0
                   CodePhraseExactV = 1 - CodePhraseExactV
                   CodePhraseWordsV  = 1 - CodePhraseWordsV
                   setstate w1,CodePhraseExact,CodePhraseExactV
                   setstate w1,CodePhraseWords,CodePhraseWordsV
                   AppendEdit(w1,CodePhraseEdit,"",0)
                   setcontroltext(w1,CodePhraseStatic,"Instring search")
                   showwindow w1,@SWHIDE,MaxWordsStatic
                   setfocus w1,CodePhraseEdit
                endif

           case CodePhraseWords
                if @NOTIFYCODE = 0
                   CodePhraseExactV = 1 - CodePhraseExactV
                   CodePhraseWordsV  = 1 - CodePhraseWordsV
                   setstate w1,CodePhraseExact,CodePhraseExactV
                   setstate w1,CodePhraseWords,CodePhraseWordsV
                   AppendEdit(w1,CodePhraseEdit,"",0)
                   SETCONTROLTEXT(w1,CodePhraseStatic,"Word search")
                   SHOWWINDOW w1,@SWSHOW,MaxWordsStatic
                   SETFOCUS w1,CodePhraseEdit
                ENDIF

           CASE PhraseDeleteButton
                IF @NOTIFYCODE = 0
                   NewEdit = ""
                   SETCONTROLTEXT(w1,CodePhraseEdit,"")
                   SHOWWINDOW w1,@SWHIDE,ListView
                   IF ISWINDOWCLOSED(w6) = 0
                      CLOSEWINDOW w6
                   ENDIF
                   SETFOCUS w1,CodePhraseEdit
                ENDIF

           CASE CodePhraseSearch
                IF @NOTIFYCODE = 0
                   SHOWWINDOW w1,@SWHIDE,ListView
                   IF (GETCONTROLTEXT(w1,CodePhraseEdit)) = ""
                      SETFOCUS w1,CodePhraseEdit
                      RETURN 0
                   ENDIF
                   IF ISWINDOWCLOSED(w6) = 0
                      CLOSEWINDOW w6
                   ENDIF
                   WindowSearchPhrase()
                ENDIF

           CASE BookJump
                IF @NOTIFYCODE = 0
						 if getselected(w1,Combo6) = -1
							 ShowConfirm(-6)
							 setfocus w1,Combo6
							 return 0
						 endif
                   BookLineNumber = getstring(w1,Combo6,getselected(w1,Combo6))
                   if instr(BookLineNumber," ")
                      BookLineNumber = mid$(BookLineNumber,1,instr(BookLineNumber," ")-1)
                   endif
                   setcontroltext(w1,EDIT_1,BookLineNumber)
                endif

           case Check1
                if @NOTIFYCODE = 0
                   AutoJumpTo = 1 - AutoJumpTo
                   setfocus w1
                endif

           case Combo2
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                    lv2Selected = getselected(w1,Combo2)
                    ShowSubroutineButtons(1)
                    if AutoJumpTo = 1
							  stoptimer w1,10000
							  int ComboPos = getselected(w1,Combo2)
                       string ComboJump = ""
                       string ComboName = getstring(w1,Combo2,getselected(w1,Combo2))
                       for a = 0 to getstringcount(w1,Combo2)-1
                           CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,ComboJump)
                           if ucase$(ComboName) = ucase$(ComboJump)
							         CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
                              breakfor
                           endif
                       next a
							  StoreLine = val(text)
							  setscrollpos(w1,16,StoreLine)
							  cLine = val(text)
							  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
							  rHandle = GETCONTROLHANDLE(w1,1)
							  FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

							  FOR a = 1 TO 35
									SETCONTROLTEXT(w1,a+1000,STR$(FirstVisLine+(a-1)))
							  NEXT a

							  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
							  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

							  GetTheScrollPos(w1,1,rHandle)

							  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
							  InvalidateRect(rHandle,0,true)
							  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

							  StoreLine = VAL(text)
							  SETSCROLLPOS(w1,16,StoreLine)
							  cLine = VAL(text)
							  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
							  FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

							  SETCONTROLTEXT(w1,4,LTRIM$(STR$(FirstVisLine)))
							  SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
							  SETCONTROLCOLOR w1,1001,Red,RGB(220,220,220)
							  SETCONTROLTEXT(w1,LinePosEdit,LTRIM$(STR$(cLine)))
							  SETCONTROLTEXT(w1,LineCharEdit,LTRIM$(STR$(AcrossX)))
							  SETCONTROLTEXT(w1,nwPosEdit,LTRIM$(STR$(ttx)))
							  SETCONTROLTEXT(w1,EditPosEdit,LTRIM$(STR$(EditPos)))
                       ResetScroll()
							  STARTTIMER w1,TimerSpeed1,10000
                       SETFOCUS w1,1
							  RETURN 0
                    ENDIF
                ENDIF

           CASE SubJump
                IF @NOTIFYCODE = 0
                   IF (GETSELECTED(w1,Combo2)) = -1
                      ShowConfirm(-2)
                      SETFOCUS w1,Combo2
                      RETURN 0
                   ENDIF
						 STOPTIMER w1,10000
						 ComboPos = GETSELECTED(w1,Combo2)
						 CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,1,text)
						 ComboJump = ""
						 ComboName = GETSTRING(w1,Combo2,GETSELECTED(w1,Combo2))
						 lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
						 FOR a = 0 TO lvcount2
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,ComboJump)
							  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
							  if ucase$(ComboName) = ucase$(ComboJump)
								  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
								  breakfor
							  endif
						 next a
                   StoreLine = val(text) - 1
                   cLine = val(text) - 1
                   setcontroltext(w1,EDIT_1,ltrim$(text))
						 starttimer w1,TimerSpeed1,10000
                   setfocus w1,1
						 return 0
                endif

           case EndSubb
                if @NOTIFYCODE = 0
                    if (getselected(w1,Combo2)) = -1
                       ShowConfirm(-2)
                       setfocus w1,Combo2
                       return 0
                    endif
						  stoptimer w1,10000
						  ComboPos = getselected(w1,Combo2)
						  CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,2,text)
                    StoreLine = val(text)
                    setscrollpos(w1,16,StoreLine)
                    cLine = val(text)
						  sRange.Low = (getscrollpos(w1,16) * 16) - 16
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
						  rHandle = getcontrolhandle(w1,1)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

						  for a = 1 to 30
							   setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
						  next a

						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)

						  GetTheScrollPos(w1,1,rHandle)

						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

                    StoreLine = val(text)
                    setscrollpos(w1,16,StoreLine)
                    cLine = val(text)
						  sRange.Low = (getscrollpos(w1,16) * 16) - 16
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

						  setcontroltext(w1,4,ltrim$(str$(FirstVisLine)))
						  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
						  SETCONTROLCOLOR w1,1001,Red,RGB(220,220,220)
						  setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
						  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
						  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
						  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
                    ResetScroll()
						  starttimer w1,TimerSpeed1,10000
						  return 0
                ENDIF

           CASE Combo4
                IF @NOTIFYCODE = @CBNSELCHANGE AND DoingOpen = 0
                    ShowWindowButtons(1)
                    IF AutoJumpTo = 1
							  STOPTIMER w1,10000
							  ComboPos = GETSELECTED(w1,Combo4)
							  CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
							  StoreLine = VAL(text)
							  SETSCROLLPOS(w1,16,StoreLine)
							  cLine = VAL(text)
							  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
							  rHandle = GETCONTROLHANDLE(w1,1)
							  FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

							  FOR a = 1 TO 35
									SETCONTROLTEXT(w1,a+1000,STR$(FirstVisLine+(a-1)))
							  NEXT a

							  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
							  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

							  GetTheScrollPos(w1,1,rHandle)

							  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
							  InvalidateRect(rHandle,0,true)
							  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

							  StoreLine = VAL(text)
							  SETSCROLLPOS(w1,16,StoreLine)
							  cLine = val(text)
							  sRange.Low = (getscrollpos(w1,16) * 16) - 16
							  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
							  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
							  setcontroltext(w1,4,ltrim$(str$(FirstVisLine)))
							  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
							  SETCONTROLCOLOR w1,1001,Red,RGB(220,220,220)
						     setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
							  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
							  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
							  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
                       ResetScroll()
							  starttimer w1,TimerSpeed1,10000
                       setfocus w1,1
							  return 0
                    endif
                endif

           case WinJump
                if @NOTIFYCODE = 0
                    if (getselected(w1,Combo4)) = -1
                       ShowConfirm(-4)
                       setfocus w1,Combo4
                       return 0
                    endif
						  stoptimer w1,10000
						  ComboPos = getselected(w1,Combo4)
						  CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
                    StoreLine = val(text)
                    setscrollpos(w1,16,StoreLine)
                    cLine = val(text)
						  sRange.Low = (getscrollpos(w1,16) * 16) - 16
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
						  rHandle = getcontrolhandle(w1,1)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

						  for a = 1 to 35
							   setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
						  NEXT a

						  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
						  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

						  GetTheScrollPos(w1,1,rHandle)

						  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

                    StoreLine = VAL(text)
                    SETSCROLLPOS(w1,16,StoreLine)
                    cLine = VAL(text)
						  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                    FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

						  SETCONTROLTEXT(w1,4,LTRIM$(STR$(FirstVisLine)))
						  SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
						  SETCONTROLCOLOR w1,1001,Red,RGB(220,220,220)
						  SETCONTROLTEXT(w1,LinePosEdit,LTRIM$(STR$(cLine)))
						  SETCONTROLTEXT(w1,LineCharEdit,LTRIM$(STR$(AcrossX)))
						  SETCONTROLTEXT(w1,nwPosEdit,LTRIM$(STR$(ttx)))
						  SETCONTROLTEXT(w1,EditPosEdit,LTRIM$(STR$(EditPos)))
                    ResetScroll()
						  STARTTIMER w1,TimerSpeed1,10000
						  RETURN 0
                ENDIF

           CASE EndWin
                IF @NOTIFYCODE = 0
                    if (getselected(w1,Combo4)) = -1
                       ShowConfirm(-4)
                       setfocus w1,Combo4
                       return 0
                    endif
						  stoptimer w1,10000
						  ComboPos = getselected(w1,Combo4)
						  CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,2,text)
                    StoreLine = val(text)
                    setscrollpos(w1,16,StoreLine)
                    cLine = val(text)
						  sRange.Low = (getscrollpos(w1,16) * 16) - 16
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
						  rHandle = getcontrolhandle(w1,1)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

						  for a = 1 to 35
							   setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
						  next a

						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)

						  GetTheScrollPos(w1,1,rHandle)

						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

                    StoreLine = val(text)
                    setscrollpos(w1,16,StoreLine)
                    cLine = val(text)
						  sRange.Low = (getscrollpos(w1,16) * 16) - 16
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

						  setcontroltext(w1,4,ltrim$(str$(FirstVisLine)))
						  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
						  SETCONTROLCOLOR w1,1001,Red,RGB(220,220,220)
						  setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
						  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
						  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
						  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
                    ResetScroll()
						  starttimer w1,TimerSpeed1,10000
						  return 0
                endif

           case WinHandler
                if @NOTIFYCODE = 0
                    if (getselected(w1,Combo4)) = -1
                       ShowConfirm(-4)
                       setfocus w1,Combo4
                       return 0
                    endif
						  stoptimer w1,10000
						  ComboPos = getselected(w1,Combo4)
                    string hText = ""
						  CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,3,hText)

						  int lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) -1
						  FOR a = 0 TO lvcount
							   CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
							   IF UCASE$(text) = UCASE$(hText)
									  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
                             SETSELECTED(w1,Combo2,a)

									  StoreLine = VAL(text)
									  SETSCROLLPOS(w1,16,StoreLine)
									  cLine = VAL(text)
									  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
									  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
									  rHandle = GETCONTROLHANDLE(w1,1)
									  FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

									  FOR a = 1 TO 35
											SETCONTROLTEXT(w1,a+1000,STR$(FirstVisLine+(a-1)))
									  NEXT a

									  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
									  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

									  GetTheScrollPos(w1,1,rHandle)

									  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
									  InvalidateRect(rHandle,0,true)
									  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

									  StoreLine = VAL(text)
									  SETSCROLLPOS(w1,16,StoreLine)
									  cLine = VAL(text)
									  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
									  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
									  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

									  setcontroltext(w1,4,ltrim$(str$(FirstVisLine)))
									  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
									  SETCONTROLCOLOR w1,1001,Red,RGB(220,220,220)
									  setcontroltext(w1,LinePosEdit,ltrim$(str$(cLine)))
									  setcontroltext(w1,LineCharEdit,ltrim$(str$(AcrossX)))
									  setcontroltext(w1,nwPosEdit,ltrim$(str$(ttx)))
									  setcontroltext(w1,EditPosEdit,ltrim$(str$(EditPos)))
                             ResetScroll()
									  starttimer w1,TimerSpeed1,10000
									  return 0
                        endif
						  next a
                ENDIF

           CASE 101 'Dummy edit box
                IF Loading = 0
						 CONTROLCMD w1,101,@EDGETSELECTION,xStart,xEnd
                ENDIF

           CASE 4
                IF @NOTIFYCODE = @ENCHANGE AND Loading = 0 'and NoUpdate = 0
                NoUpdate = 1
                NoUpdate = 0
                ENDIF

           CASE Combo1 'Block words
                IF @NOTIFYCODE = @CBNSELCHANGE
						 IF AutoJumpTo = 1
							 InsertPoint = cLine
							 sRange.Low = GETSCROLLPOS(w1,16) * 16
							 BlockIn = GETSTRING(w1,Combo1,GETSELECTED(w1,Combo1))
							 BlockIn = GETSTARTPATH + "\\Res\\" + BlockIn
							 count = ReadBlock(BlockIn)
							 CopyStringToClipBoard(CutLine)
							 DoPaste()
                      INT srMin,srMax
                      GETSCROLLRANGE(w1,16,srMin,srMax)
                      SETSCROLLRANGE w1,16,0,srMax + count
						 ENDIF
                ENDIF

           CASE BlockJumpButton
                IF @NOTIFYCODE = 0
						 IF GETSELECTED(w1,Combo1) = -1
							 ShowConfirm(-1)
							 SETFOCUS w1,Combo1
							 RETURN 0
						 ENDIF

                   NoLineClicked = 1
                   StringLineNo = ""
                   FOR a = 1 TO 30
                       StringLineNo = GETCONTROLTEXT(w1,a+1000)
                       IF INSTR(StringLineNo,">")
                          NoLineClicked = 0
                          BREAKFOR
                       ENDIF
                   NEXT a
                   IF NoLineClicked = 1
                      ShowConfirm(-11)
                   RETURN 0
                   ENDIF

						 InsertPoint = cLine
						 sRange.Low = GETSCROLLPOS(w1,16) * 16
						 BlockIn = GETSTRING(w1,Combo1,GETSELECTED(w1,Combo1))
						 BlockIn = GETSTARTPATH + "\\Res\\" + BlockIn
						 count = ReadBlock(BlockIn)
						 CopyStringToClipBoard(CutLine)
						 DoPaste()
                   getscrollrange(w1,16,srMin,srMax)
                   SETSCROLLRANGE w1,16,0,srMax + count
                endif

           case Combo20
                if @NOTIFYCODE = @CBNSELCHANGE and DoingOpen = 0
                   int WasChanged = 0
						 string IncludeFile = getstring w1,Combo20,getselected(w1,Combo20)
						 string OpenInclude = IncludePath + IncludeFile
						 if openfile(MyFile2,OpenInclude,"R") = 0
							 DoMinimiseAll()
							 CreatePathFile()
							 ProgPath = OpenInclude
							 DoOpen(1)
                      ColourText()
							 ProgCount ++
							 RecentProgs[ProgCount] = ProgPath
							 'SendMessage (getcontrolhandle(w1,1),EM_SETREADONLY,TRUE,0)
						 else
							 OpenInclude = getstartpath + IncludeFile

							 if openfile(MyFile2,OpenInclude,"R") = 0
								 DoMinimiseAll()
								 CreatePathFile()
								 ProgPath = OpenInclude
								 DoOpen(1)
								 ProgCount ++
								 RecentProgs[ProgCount] = ProgPath
							 endif
						 endif


						 closefile MyFile2
                endif

           case EDIT_1
                if @NOTIFYCODE = @ENCHANGE
                   JumpLine()
                   ResetScroll()
                   OldsRange = (sRange.Low / 16) + 30
                   if iswindowclosed(w2) = 0
                      setfocus w2
                   endif
                endif

           case BUTTON_4 'User jump to line button
                if @NOTIFYCODE = 0
                   if (getcontroltext w1,EDIT_11) <> ""
                      JumpLineUser(EDIT_11)
                   endif
						 sRange.Low = (getscrollpos(w1,16) * 16) - 16
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
						 cLine = getscrollpos(w1,16)
						 StoreLine = cLine
                endif

           case BUTTON_44 'User jump to line button
                if @NOTIFYCODE = 0
                   if (getcontroltext w1,EDIT_111) <> ""
                      JumpLineUser(EDIT_111)
                   endif
						 sRange.Low = (getscrollpos(w1,16) * 16) - 16
						 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
						 cLine = getscrollpos(w1,16)
						 StoreLine = cLine
                endif

           case EDIT_11
                if @NOTIFYCODE = @ENCHANGE and DoingOpen = 0
                   if getcontroltext(w1,EDIT_11) <> ""
                      showwindow w1,@SWSHOW,BUTTON_4
                   else
                      showwindow w1,@SWHIDE,BUTTON_4
                   endif
                   JumpLineUser(EDIT_11)
                   ResetScroll()
                   OldsRange = (sRange.Low / 16) + 30
                   if iswindowclosed(w2) = 0
                      setfocus w2
                   endif
                endif

           CASE EDIT_111
                IF @NOTIFYCODE = @ENCHANGE AND DoingOpen = 0
                   IF GETCONTROLTEXT(w1,EDIT_111) <> ""
                      SHOWWINDOW w1,@SWSHOW,BUTTON_44
                   ELSE
                      SHOWWINDOW w1,@SWHIDE,BUTTON_44
                   ENDIF
                   JumpLineUser(EDIT_111)
                   ResetScroll()
                   OldsRange = (sRange.Low / 16) + 30
                   IF ISWINDOWCLOSED(w2) = 0
                      SETFOCUS w2
                   ENDIF
                ENDIF

  			  CASE ListView
                sRange.Low = GETSCROLLPOS(w1,16) * 16
  				    SELECT @NOTIFYCODE
							  CASE NM_CUSTOMDRAW '<--- Do something when list view is being re-drawn
							       RETURN ColourListViewSearch(w1.hWnd,@LPARAM) '<--- Color the list view items
                ENDSELECT

			  CASE ListView2 'Sub routines list
                sRange.Low = GETSCROLLPOS(w1,16) * 16
					 IF @NOTIFYCODE=@NMCLICK 'Click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView2,@LVGETTEXT,lvpos,1,text)
                          sRange.High = 0
                          sRange.Low = (VAL(text) * 16) - 16
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                          SETCONTROLTEXT w1,4,text
                          ColourThis = val(text)
                          setfocus w1,1
								  StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,sRange)
								  CONTROLCMD w1,1,@RTSETSELECTION,StartAt,StartAt
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour
                          setscrollpos(w1,16,val(text))
                          return 0
					 endif

					 if @NOTIFYCODE=@NMDBLCLK 'Double click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView2,@LVGETTEXT,lvpos,2,text)
                          sRange.High = 0
                          sRange.Low = (val(text) * 16) - 16
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                          setcontroltext w1,4,text
                          ColourThis = val(text)
                          setfocus w1
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour
                          setscrollpos(w1,16,val(text))
                          return 0
					 endif

			  CASE ListView4
                sRange.Low = GETSCROLLPOS(w1,16) * 16
					 if @NOTIFYCODE=@NMCLICK 'Click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView4,@LVGETTEXT,lvpos,1,text)
                          sRange.High = 0
                          sRange.Low = (val(text) * 16) - 16
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                          setfocus w1
                          SetLines()
								  setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour
                          SETSCROLLPOS(w1,16,VAL(text))
                          RETURN 0
					 ENDIF

					 IF @NOTIFYCODE=@NMDBLCLK 'Double click on listview
							lvpos=*<NMLISTVIEW>@LPARAM.iItem
                          CONTROLCMD(w1,ListView4,@LVGETTEXT,lvpos,2,text)
                          sRange.High = 0
                          sRange.Low = (VAL(text) * 16) - 16
                          SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
                          SETFOCUS w1
                          SetLines()
								  SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
								  SETCONTROLCOLOR w1,1001,Red,BackColour
                          SETSCROLLPOS(w1,16,VAL(text))
                          RETURN 0
					 ENDIF

				CASE 1 'Richedit
                  IF Loading = 1 THEN RETURN 0
                  IF @NOTIFYCODE = EN_CHANGE AND Loading = 0
                     Mod = 1
							IF OnTab = 1
								IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab1))
									IF !instr(GETCONTROLTEXT(w1,FileTab1),"*")
										SETCONTROLTEXT(w1,FileTab1,GETCONTROLTEXT(w1,FileTab1) + "*")
                              SETCAPTION(w1,GETCAPTION(w1) + "*")
									ENDIF
								ENDIF
							ENDIF

							if OnTab = 2
								if instr(getcaption(w1),getcontroltext(w1,FileTab2))
									if !instr(getcontroltext(w1,FileTab2),"*")
										setcontroltext(w1,FileTab2,getcontroltext(w1,FileTab2) + "*")
                              setcaption(w1,getcaption(w1) + "*")
									endif
								endif
							endif

							if OnTab = 3
								if instr(getcaption(w1),getcontroltext(w1,FileTab3))
									if !instr(getcontroltext(w1,FileTab3),"*")
										setcontroltext(w1,FileTab3,getcontroltext(w1,FileTab3) + "*")
                              setcaption(w1,getcaption(w1) + "*")
									endif
								endif
							endif

							if OnTab = 4
								if instr(getcaption(w1),getcontroltext(w1,FileTab4))
									if !instr(getcontroltext(w1,FileTab4),"*")
										setcontroltext(w1,FileTab4,getcontroltext(w1,FileTab4) + "*")
                              setcaption(w1,getcaption(w1) + "*")
									endif
								endif
							endif

							if OnTab = 5
								if instr(getcaption(w1),getcontroltext(w1,FileTab5))
									if !instr(getcontroltext(w1,FileTab5),"*")
										setcontroltext(w1,FileTab5,getcontroltext(w1,FileTab5) + "*")
                              setcaption(w1,getcaption(w1) + "*")
									endif
								endif
							endif

							if OnTab = 6
								if instr(getcaption(w1),getcontroltext(w1,FileTab6))
									if !instr(getcontroltext(w1,FileTab6),"*")
										setcontroltext(w1,FileTab6,getcontroltext(w1,FileTab6) + "*")
                              setcaption(w1,getcaption(w1) + "*")
									endif
								endif
							endif

                  endif

						SENDMESSAGE(w1.hWnd,EM_GETSCROLLPOS,0,sRange,1)
						int OnLine2 = (sRange.Low / 16) + 1

                  if Colouring = 1 then return 0
						if Loading = 0
							SendMessage w1,EM_POSFROMCHAR, &pt, pt.y ,1
							ppos = GETCARETPOSITION w1,x,y
						endif

						SELECT @NOTIFYCODE
								 case @ENENTERKEY 'Enter key pressed...
										showwindow w1,@SWHIDE,ListView
										if kw = 0 'Insert blank line
											MoveBlocks(cLine,1,1)
											sRange.Low = GETSCROLLPOS(w1,16) * 16
											CONTROLCMD w1,1,@RTSETSELECTION,varEnd,varEnd
											CONTROLCMD w1,1,@RTREPLACESEL,chr$(13) + chr$(10)
											StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
											setcontroltext(w1,101,"")
											InfoA = ""
											Line2$ = ""
											Line4$ = ""
											ttx = StartAt
											Match = 0
											kw = 0
											ttx = varStart
											CommentsOn = 0
											sRange.Low = GETSCROLLPOS(w1,16) * 16
											SetLines2()
											ListViewUpdate(1,1)
											setfocus w1,1
											return 0
										endif

										if kw > 0
											int eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,0)
											SendMessage(rHandle,WM_SETREDRAW,false,0)
											CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
											Store1 = ttx
											Store2 = varEnd
											CONTROLCMD w1,1,@RTSETSELECTION,ttx,EditPos
											line2$ = ""
											CONTROLCMD w1,1,@RTGETSELTEXT,Line2$
											sRange.Low = GETSCROLLPOS(w1,16) * 16
											SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,2)
											SENDMESSAGE(rHandle,WM_SETREDRAW,true,0)
											InvalidateRect(rHandle,0,true)
											SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
										ENDIF

										DelFound = 1

										IF Line2$ = "" OR Line2$ = " "
											sRange.Low = GETSCROLLPOS(w1,16) * 16
											CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
											CONTROLCMD w1,1,@RTREPLACESEL,CHR$(13) + CHR$(10)
											StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
											CONTROLCMD w1,1,@RTSETSELECTION,StartAt,StartAt+1
											CONTROLCMD w1,1,@RTREPLACESEL," "
											CONTROLCMD w1,1,@RTSETSELECTION,StartAt,StartAt
											CONTROLCMD w1,1,@RTSETSELCOLOR,RGB(0,0,0)
											SETCONTROLTEXT(w1,101,"")
											InfoA  = ""
											Line2$ = ""
											Line4$ = ""
											ttx = StartAt
											kw = 0
											CommentsOn = 0
											sRange.Low = GETSCROLLPOS(w1,16) * 16
											return 0
										endif


                              'Sel contains partial key word typed e.g. pr for PRINT
                              'Select for replacement
										CONTROLCMD w1,1,@RTSETSELECTION,ttx,varEnd

print "Line4$  !",Line4$,"!"
										if kw

print "ttx ",ttx,"    ",varEnd,"    letters typed  ",varEnd - ttx
										   if Ucase = 2 then InfoA = lcase$(InfoA)
											if Ucase = 3 and CapsOn = 0 then InfoA = lcase$(InfoA)
											CONTROLCMD w1,1,@RTREPLACESEL,InfoA
											CONTROLCMD w1,1,@RTSETSELECTION,ttx,(ttx) + (LEN(InfoA))

											Undo2Count[OnTab] = (Undo2Count[OnTab] - (varEnd - ttx))
PRINT "Count reset to ",Undo2Count[OnTab]
											FOR a = 1 TO LEN(InfoA)
												 INT xLine,Was
												 Undo2Count[OnTab] ++
												 Undo2[OnTab].Press[Undo2Count[OnTab]] = 1
												 Undo2[OnTab].Typed[Undo2Count[OnTab]] = MID$(InfoA,a,1)
PRINT "Added ",MID$(InfoA,a,1),"      ",Undo2Count[OnTab]
												 Undo2[OnTab].Pos[Undo2Count[OnTab]] = a + (ttx-1)
												 xLine = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
												 Undo2[OnTab].LineNo[Undo2Count[OnTab]] = xLine
												 CONTROLCMD(w1,1,@RTGETLINE,xLine,line$,512)
												 Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,xLine,0)
												 Undo2[OnTab].Offset[Undo2Count[OnTab]] = Offset
												 Was = (varStart - Offset) + 1
												 Undo2[OnTab].Was[Undo2Count[OnTab]] = MID$(Line$,Was,1)
											NEXT a

											CONTROLCMD w1,1,@RTSETSELCOLOR,#Attrib[Match].Colour
											CONTROLCMD w1,1,@RTSETSELECTION,(ttx) + (LEN(InfoA))+1,(ttx) + (LEN(InfoA))+1
											SENDMESSAGE(rHandle,WM_SETREDRAW,true,0)
											SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

PRINT
PRINT "Added count ",Undo2Count[OnTab]
PRINT
										ENDIF

										ttx = varStart-1
										Line2$ = ""
										Line4$ = ""
										kw = 0
										SETCONTROLTEXT(w1,101,"")
										ttx = varEnd
										OnWord = 1
										ttt = 0
										RETURN 0

						       CASE @ENCHANGE
									   IF ManualChange = 1 THEN RETURN 0
									   IF GETKEYSTATE(0x0D) THEN RETURN 0
									   sRange.Low = GETSCROLLPOS(w1,16) * 16
									   cLine = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1) + 1
									   CONTROLCMD w1,1,@RTGETSELECTION,varStart,varEnd

									   line4$ = ""
									   FirstChar = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
									   IF FirstChar = varStart
										   CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
									   ELSE
										   CONTROLCMD w1,1,@RTSETSELECTION,varStart-1,varEnd
									   ENDIF
									   CONTROLCMD (w1,1,@RTGETSELTEXT,line4$,255)
									   CONTROLCMD w1,1,@RTSETSELECTION,varEnd,varEnd

									   IF INSTR(CheckLetter,line4$) > 0 or DelFound or line4$ = "" 'Delimiter found.
										   FirstChar = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
										   if FirstChar = varEnd
											   CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
										   else
											   CONTROLCMD w1,1,@RTSETSELECTION,varStart-1,varEnd
										   endif
										   if line4$ = chr$(34)
											   if QuotesOn = 1
											 	   Int QutoesWere = 1
											   endif
											   QuotesOn = 1 - QuotesOn
										   endif
										   if QuotesOn = 1 or QutoesWere = 1
											   CONTROLCMD w1,1,@RTSETSELCOLOR,Purple
										   else
											   if CommentsOn = 0 and LineColoured[cLine-1] = 0
												   CONTROLCMD w1,1,@RTSETSELCOLOR,rgb(0,0,0)
											   endif
										   endif

										   if FirstChar = varEnd
											   CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
										   else
											   CONTROLCMD w1,1,@RTSETSELECTION,varEnd,varEnd
										   endif

										   if line4$ = chr$(39)
											   CONTROLCMD w1,1,@RTSETSELECTION,varStart-1,varEnd
											   CONTROLCMD w1,1,@RTSETSELCOLOR,Green
											   CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
											   CommentsOn = 1
										   endif

										   ttx = varStart '+ 1
										   varEnd = varStart
										   showwindow w1,@SWHIDE,ListView
										   setcontroltext(w1,101,"")
										   kw = 0
										   DelFound = 0
										   Line2$ = ""
										   Line4$ = ""
										   setfocus w1,1
										   sRange.Low = GETSCROLLPOS(w1,16) * 16
										   return 0
									   endif

									   if ttx = 0 and Loading = 0
										   ttx = varStart '-1
									   endif

									   line2$ = ""
									   CONTROLCMD(w1,1,@RTGETLINE,cLine-1,line2$,512)
									   setcontroltext w1,101,line2$
									   StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)

                              if BackSpacePressed
                                 BackSpacePressed = 0
									      TheWord = mid$(getcontroltext(w1,101),(ttx-StartAt),(varEnd-StartAt)+1)
                              ELSE
									      TheWord = MID$(GETCONTROLTEXT(w1,101),(ttx-StartAt)+1,(varEnd-StartAt)+1)
                              ENDIF

									   CONTROLCMD w1,1,@RTSETSELECTION,varStart-1,varStart-1
									   CONTROLCMD w1,1,@RTGETSELTEXT,Line4$
									   IF FirstChar = varEnd
										   CONTROLCMD w1,1,@RTSETSELECTION,varStart,varEnd
									   ELSE
										   CONTROLCMD w1,1,@RTSETSELECTION,varEnd,varEnd
									   ENDIF

									   IF INSTR(TheWord," ")
										   TheWord = MID$(TheWord,1,INSTR(TheWord," ")-1)
									   ENDIF

									   SETCONTROLTEXT w1,101,TheWord

									   INT length = CONTROLCMD(w1,1,@RTGETLINELENGTH,StartAt)
									   IF Loading = 0
										   OnWord = 1
										   IF GETCONTROLTEXT(w1,101) <> "" OR  GETCONTROLTEXT(w1,101) <> " "
											   Search_And_Highlight(1,GETCONTROLTEXT(w1,101)) '<------------------
											   IF QuotesOn = 1
												   CONTROLCMD w1,1,@RTSETSELCOLOR,Purple
											   ELSE
												   IF LineColoured[StoreLine-1] = 0
													   CONTROLCMD w1,1,@RTSETSELCOLOR,RGB(0,0,0)
												   ENDIF
											   ENDIF
											   IF CommentsOn = 1
												   CONTROLCMD w1,1,@RTSETSELCOLOR,Green
											   ENDIF
										   ELSE
											   kw = 0
											   Line2$ = ""
											   Line4$ = ""
										   ENDIF
										   AddToUndo = 0
									   ENDIF

					ENDSELECT
			ENDSELECT
	ENDSELECT
RETURN 0
ENDSUB

SUB DoOpen(OPT INT Switch)
    DoingOpen = 1
    STOPTIMER w1,10000
    IF !Switch
	    STRING OpenThisFile = FILEREQUEST("Load File",w1,1)
       IF LTRIM$(OpenThisFile) = ""
          NoNewFile = 1
          STARTTIMER w1,TimerSpeed1,10000
          return
       endif

       string StoreProgPath = ProgPath
       string StoreFileName = FileNameIs
       ProgPath = OpenThisFile

		 if instr(ProgPath,getcontroltext(w1,FileTab1))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName
			 LoadTab(1)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,10000
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab2))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName
			 LoadTab(2)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,10000
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab3))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName
			 LoadTab(3)
			 NoNewFile = 1
          starttimer w1,TimerSpeed1,10000
			 return
		 endif

		 if instr(ProgPath,getcontroltext(w1,FileTab4))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName
			 LoadTab(4)
			 NoNewFile = 1
          STARTTIMER w1,TimerSpeed1,10000
			 RETURN
		 ENDIF

		 IF INSTR(ProgPath,GETCONTROLTEXT(w1,FileTab5))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName
			 LoadTab(5)
			 NoNewFile = 1
          STARTTIMER w1,TimerSpeed1,10000
			 RETURN
		 ENDIF

		 IF INSTR(ProgPath,GETCONTROLTEXT(w1,FileTab6))
			 ProgPath = StoreProgPath
			 FileNameIs = StoreFileName
			 LoadTab(6)
			 NoNewFile = 1
          STARTTIMER w1,TimerSpeed1,10000
			 RETURN
		 ENDIF

       GetFileName(w1,0,ProgPath,1)
       IF !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab1)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab2)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab4)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab5)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab6))
          ProgCount ++
          IF ProgCount > MaxTabs THEN ProgCount = MaxTabs
			 RecentProgs[ProgCount] = ProgPath
			 STRING MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
			 STRING StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
			 IF OPENFILE(MyFile2,StoreBookFileD,"W") = 0
				 WRITE MyFile2,LTRIM$(ProgPath)
			 endif
			 closefile MyFile2
       else
          ProgPath   = StoreProgPath
          FileNameIs = StoreFileName
          if instr(getcaption(w1),getcontroltext(w1,FileTab1))
				 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,1)
          ENDIF
          IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab2))
				 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,2)
          ENDIF
          IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3))
				 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,3)
          ENDIF
          IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab4))
				 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,4)
          ENDIF
          IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab5))
				 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,5)
          ENDIF
          IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab6))
				 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 ClearEditor()
				 DoRestore(0,6)
          ENDIF
          STARTTIMER w1,TimerSpeed1,10000
          RETURN
       ENDIF
    ENDIF
    'Has been loaded before?
	 IF(LEN(ProgPath) > 0)
          ClearEditor()
			 GetFileName(w1,0,ProgPath,1)
			 MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
			 StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
			 IF OPENFILE(MyFile2,StoreBookFileD,"R") = 0
				 CLOSEFILE MyFile2

             IF InitialLoad = 1
                GOTO SkipLoad
             ENDIF
				 x = GetLines(1)
				 SETCONTROLTEXT(w1,1,ClipText)
             LABEL SkipLoad
				 DoRestore(0)
             Restoring = 1
             IF (GETCONTROLTEXT(w1,FileTab1)) <> ""
                OnTab = 1
                Tab1Loaded = 1
             ENDIF
             IF (GETCONTROLTEXT(w1,FileTab2)) <> ""
                OnTab = 2
                Tab2Loaded = 1
             ENDIF
             IF (GETCONTROLTEXT(w1,FileTab3)) <> ""
                OnTab = 3
                Tab3Loaded = 1
             ENDIF
             IF (GETCONTROLTEXT(w1,FileTab4)) <> ""
                OnTab = 4
                Tab4Loaded = 1
             ENDIF
             IF (GETCONTROLTEXT(w1,FileTab5)) <> ""
                OnTab = 5
                Tab5Loaded = 1
             ENDIF
             IF (GETCONTROLTEXT(w1,FileTab6)) <> ""
                OnTab = 6
                Tab6Loaded = 1
             ENDIF
			 ELSE
				 ClearEditor()
				 StartUp()
PRINT "Clear editor and do startup"
			 ENDIF
    ELSE
       STARTTIMER w1,TimerSpeed1,10000
       RETURN 'setcontroltext(w1,1,"")
	 ENDIF

    IF !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab1)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab2)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab4)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab5)) AND !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab6))
      IF TabTaken = 1
          Tab1Loaded = 1
          Tab2Loaded = 0
          Tab3Loaded = 0
          Tab4Loaded = 0
          Tab5Loaded = 0
          Tab6Loaded = 0
       ENDIF
       IF TabTaken = 2
          Tab1Loaded = 1
          Tab2Loaded = 1
          Tab3Loaded = 0
          Tab4Loaded = 0
          Tab5Loaded = 0
          Tab6Loaded = 0
       ENDIF
       IF TabTaken = 3
          Tab1Loaded = 1
          Tab2Loaded = 1
          Tab3Loaded = 1
          Tab4Loaded = 0
          Tab5Loaded = 0
          Tab6Loaded = 0
       endif
       if TabTaken = 4
          Tab1Loaded = 1
          Tab2Loaded = 1
          Tab3Loaded = 1
          Tab4Loaded = 1
          Tab5Loaded = 0
          Tab6Loaded = 0
       endif
       IF TabTaken = 5
          Tab1Loaded = 1
          Tab2Loaded = 1
          Tab3Loaded = 1
          Tab4Loaded = 1
          Tab5Loaded = 1
          Tab6Loaded = 0
       ENDIF
       IF TabTaken = 6
          Tab1Loaded = 1
          Tab2Loaded = 1
          Tab3Loaded = 1
          Tab4Loaded = 1
          Tab5Loaded = 1
          Tab6Loaded = 1
       ENDIF

       IF Tab1Loaded = 0
          TabTaken = 1
          GOTO DoTabLoad
       ENDIF
       IF Tab2Loaded = 0
          TabTaken = 2
          GOTO DoTabLoad
       ENDIF
       IF Tab3Loaded = 0
          TabTaken = 3
          GOTO DoTabLoad
       ENDIF
       IF Tab4Loaded = 0
          TabTaken = 4
          GOTO DoTabLoad
       endif
       if Tab5Loaded = 0
          TabTaken = 5
          goto DoTabLoad
       endif
       if Tab6Loaded = 0
          TabTaken = 6
       endif

       label DoTabLoad
		 if TabTaken = 1
			 OnTab = 1
			 Tab1Loaded = 1
			 showwindow w1,@SWSHOW,FileTab1
			 setcontroltext(w1,FileTab1,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
          buffer1 = ""
			 buffer1 = GETCONTROLTEXT(w1,1)
		 ENDIF
		 IF TabTaken = 2
			 OnTab = 2
			 Tab2Loaded = 1
			 SHOWWINDOW w1,@SWSHOW,FileTab2
			 SETCONTROLTEXT(w1,FileTab2,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),Green
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
          buffer2 = ""
			 buffer2 = GETCONTROLTEXT(w1,1)
		 ENDIF
		 IF TabTaken = 3
			 OnTab = 3
			 Tab3Loaded = 1
			 SHOWWINDOW w1,@SWSHOW,FileTab3
			 SETCONTROLTEXT(w1,FileTab3,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),Green
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
          buffer3 = ""
			 buffer3 = getcontroltext(w1,1)
		 endif
		 if TabTaken = 4
			 OnTab = 4
			 Tab4Loaded = 1
			 showwindow w1,@SWSHOW,FileTab4
			 setcontroltext(w1,FileTab4,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),Green
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
          buffer4 = ""
			 buffer4 = getcontroltext(w1,1)
		 endif
		 if TabTaken = 5
			 OnTab = 5
			 Tab5Loaded = 1
			 showwindow w1,@SWSHOW,FileTab5
			 setcontroltext(w1,FileTab5,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),Green
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
          buffer5 = ""
			 buffer5 = getcontroltext(w1,1)
		 endif
		 if TabTaken = 6
			 OnTab = 6
			 Tab6Loaded = 1
			 showwindow w1,@SWSHOW,FileTab6
			 SETCONTROLTEXT(w1,FileTab6,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),Green
			 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
			 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
          buffer6 = ""
			 buffer6 = GETCONTROLTEXT(w1,1)
		 ENDIF
	 ENDIF
    DoingOpen = 0
    STARTTIMER w1,TimerSpeed1,10000
RETURN
ENDSUB

SUB DoSave(OPT INT Switch)
    DoMinimiseAll()
    IF Switch = 0
       Switch = OnTab
    ENDIF
	 IF(LEN(ProgPath) > 0)
		 IF(OPENFILE(file1,ProgPath,"W") = 0)
         Modified = 0
         SETCAPTION w1,FileNameIs
         IF Switch = 0
			   buffer = GETCONTROLTEXT(w1,1)
				IF !instr(ProgPath,IncludePath)
 			      WRITE file1,buffer
               DoRestore(0)
            ENDIF
         ENDIF
         if Switch = 1
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer1
               DoRestore(0,1)
               if instr(getcontroltext(w1,FileTab1),"*")
                  setcontroltext(w1,FileTab1,mid$(getcontroltext(w1,FileTab1),1,instr(getcontroltext(w1,FileTab1),"*")-1))
               endif
            endif
         endif
         if Switch = 2
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer2
               DoRestore(0,2)
               if instr(getcontroltext(w1,FileTab2),"*")
                  setcontroltext(w1,FileTab2,mid$(getcontroltext(w1,FileTab2),1,instr(getcontroltext(w1,FileTab2),"*")-1))
               endif
            endif
         endif
         if Switch = 3
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer3
               DoRestore(0,3)
               if instr(getcontroltext(w1,FileTab3),"*")
                  setcontroltext(w1,FileTab3,mid$(getcontroltext(w1,FileTab3),1,instr(getcontroltext(w1,FileTab3),"*")-1))
               endif
            endif
         endif
         if Switch = 4
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer4
               DoRestore(0,4)
               if instr(getcontroltext(w1,FileTab4),"*")
                  setcontroltext(w1,FileTab4,mid$(getcontroltext(w1,FileTab4),1,instr(getcontroltext(w1,FileTab4),"*")-1))
               endif
            endif
         endif
         if Switch = 5
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer5
               DoRestore(0,5)
               if instr(getcontroltext(w1,FileTab5),"*")
                  setcontroltext(w1,FileTab5,mid$(getcontroltext(w1,FileTab5),1,instr(getcontroltext(w1,FileTab5),"*")-1))
               endif
            endif
         endif
         if Switch = 6
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer6
               DoRestore(0,6)
               if instr(getcontroltext(w1,FileTab6),"*")
                  setcontroltext(w1,FileTab6,mid$(getcontroltext(w1,FileTab6),1,instr(getcontroltext(w1,FileTab6),"*")-1))
               endif
            endif
         endif
			closefile file1
		 endif
		 closefile file1
	 endif
endsub

SUB DoSaveToTab()
    TabTaken ++
    string StoreFileName = GETSTARTPATH() + "\\Res\\" + FileNameIs

    if TabTaken = 1
       setcontroltext(w1,FileTab1,FileNameIs)
       buffer1 = ""
 	    buffer1 = getcontroltext(w1,1)
    endif

    if TabTaken = 2
       setcontroltext(w1,FileTab2,FileNameIs)
       buffer2 = ""
 	    buffer2 = getcontroltext(w1,1)
    endif

    if TabTaken = 3
       setcontroltext(w1,FileTab3,FileNameIs)
       buffer3 = ""
 	    buffer3 = getcontroltext(w1,1)
    endif

    if TabTaken = 4
       setcontroltext(w1,FileTab4,FileNameIs)
       buffer4 = ""
 	    buffer4 = getcontroltext(w1,1)
    endif

    if TabTaken = 5
       setcontroltext(w1,FileTab5,FileNameIs)
       buffer5 = ""
 	    buffer5 = getcontroltext(w1,1)
    endif

    if TabTaken = 6
       setcontroltext(w1,FileTab6,FileNameIs)
       buffer6 = ""
 	    buffer6 = getcontroltext(w1,1)
    endif

	 string MainNameD = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 string StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 if openfile(MyFile2,StoreBookFileD,"W") = 0
		 write MyFile2,ltrim$(ProgPath)
	 endif
	 closefile MyFile2
endsub

SUB DoSaveAs(OPT INT Switch)
	 STRING ProgPathNew = FILEREQUEST("Save File",w1,0,filter,"iwb")
	 IF(LEN(ProgPathNew) > 0)
       ProgPath = ProgPathNew
       GetFileName(w1,0,ProgPath,1)
		 IF(OPENFILE(file1,ProgPath,"W") = 0)
         Modified = 0
         SETCAPTION w1,FileNameIs
		   buffer = GETCONTROLTEXT(w1,1)
		   WRITE file1,buffer
         IF OnTab = 1
            SETCONTROLTEXT(w1,FileTab1,FileNameIs)
            RecentProgs[1] = ProgPath
         ENDIF
         IF OnTab = 2
            SETCONTROLTEXT(w1,FileTab2,FileNameIs)
            RecentProgs[2] = ProgPath
         ENDIF
         IF OnTab = 3
            SETCONTROLTEXT(w1,FileTab3,FileNameIs)
            RecentProgs[3] = ProgPath
         ENDIF
         IF OnTab = 4
            SETCONTROLTEXT(w1,FileTab4,FileNameIs)
            RecentProgs[4] = ProgPath
         ENDIF
         IF OnTab = 5
            SETCONTROLTEXT(w1,FileTab5,FileNameIs)
            RecentProgs[5] = ProgPath
         ENDIF
         IF OnTab = 6
            SETCONTROLTEXT(w1,FileTab6,FileNameIs)
            RecentProgs[6] = ProgPath
         endif
		 endif
       closefile file1
	 endif
return
endsub

SUB DoSaveOnExit(opt int Switch)
    'DoMinimiseAll()
	 if(len(ProgPath) > 0)
		 if(openfile(file1,ProgPath,"W") = 0)
         Modified = 0
         setcaption w1,FileNameIs
         if Switch = 0
            buffer = ""
			   buffer = getcontroltext(w1,1)
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer
            endif
         endif
         if Switch = 1
            'DoMinimise(1)
            DoRestore(0,1)
            buffer1 = ""
            buffer1 = getcontroltext(w1,1)
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer1
            endif
         endif
         if Switch = 2
            DoRestore(0,2)
            buffer2 = ""
            buffer2 = getcontroltext(w1,1)
				if !instr(ProgPath,IncludePath)
 			      write file1,buffer2
            endif
         ENDIF
         IF Switch = 3
            DoRestore(0,3)
            buffer3 = ""
            buffer3 = GETCONTROLTEXT(w1,1)
				IF !instr(ProgPath,IncludePath)
 			      WRITE file1,buffer3
            ENDIF
         ENDIF
         IF Switch = 4
            DoRestore(0,4)
            buffer4 = ""
            buffer4 = GETCONTROLTEXT(w1,1)
				IF !instr(ProgPath,IncludePath)
 			      WRITE file1,buffer4
            ENDIF
         ENDIF
         IF Switch = 5
            DoRestore(0,5)
            buffer5 = ""
            buffer5 = GETCONTROLTEXT(w1,1)
				IF !instr(ProgPath,IncludePath)
 			      WRITE file1,buffer5
            ENDIF
         ENDIF
         IF Switch = 6
            DoRestore(0,6)
            buffer6 = ""
            buffer6 = GETCONTROLTEXT(w1,1)
				IF !instr(ProgPath,IncludePath)
 			      WRITE file1,buffer6
            ENDIF
         endif
			closefile file1
		 endif
		 closefile file1
	 endif
endsub

sub Search_And_Highlight(int ListViewPos,string WordIn,opt int Switch)
    if AutoCompleteKeyWords = 0 then return
    kw = 0
    if Switch = 1
		 setsize w1,990,520,300,38,ListView
    else
		 ppos = GETCARETPOSITION w1,AcrossX,DownY
		 int lvX = AcrossX
		 int lvY = DownY
		 setsize w1,lvX+58,lvY+118,300,38,ListView
    endif

    SearchFor = WordIn

	 if len(SearchFor) < 2
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif

	 int AscValue = asc(mid$(SearchFor,1,1))
	 if AscValue < 64 and AscValue <> 36
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif
	 if AscValue >= 91 and AscValue <= 96 and AscValue <> 95
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif
	 if AscValue = 81 or AscValue = 113 or AscValue = 88 or AscValue = 89 or AscValue = 90 or AscValue = 120 or AscValue = 121 or AscValue = 122
		 SendMessage(w1,@LVM_ENSUREVISIBLE,0,0,ListView)
		 showwindow w1,@SWHIDE,ListView
       kw = 0
		 return 0
	 endif

    int aa = 0
    if mid$(SearchFor,1,1) = "@"
       aa = 0
       SearchLoopTo = 805
    else
       aa = 806
       SearchLoopTo = CONTROLCMD(w1,ListView,@LVGETCOUNT) -1
    endif

    WordIn = ltrim$(WordIn)
    SearchFor = ""

    istring SearchForX[255] = WordIn
	 FOR SearchLoop = 1 TO LEN(WordIn)
        IF MID$(SearchForX,SearchLoop,1) = CHR$(13)
           BREAKFOR
        ELSE
           SearchFor = SearchFor + MID$(SearchForX,SearchLoop,1)
        ENDIF
    NEXT SearchLoop
    Match = 0

    UINT rHandle = GETCONTROLHANDLE(w1,1)
    INT eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,0)
    SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

	 FOR SearchLoop = aa TO SearchLoopTo
		  InvalidateRect(GETCONTROLHANDLE(w1,ListView),NULL,0)
		  CONTROLCMD(w1,ListView,@LVGETTEXT,SearchLoop,0,InfoA)
		  IF MID$(UCASE$(InfoA),1,LEN(SearchFor)) = MID$(UCASE$(SearchFor),1,LEN(SearchFor))
			  IF UCASE$(InfoA) = UCASE$(SearchFor)
              SHOWWINDOW w1,@SWSHOW,ListView
				  SENDMESSAGE(w1,@LVM_ENSUREVISIBLE,SearchLoop,0,ListView)
              SETCONTROLTEXT w1,101,InfoA
              Match = SearchLoop
				  LastPosFound = SearchLoop
              IF !Switch
                 kw = 2
              ENDIF
				  BREAKFOR
			  ENDIF
			  IF MID$(UCASE$(InfoA),1,LEN(SearchFor)) = MID$(UCASE$(SearchFor),1,LEN(SearchFor)) 'instr(ucase$(InfoA),ucase$(SearchFor))
              SHOWWINDOW w1,@SWSHOW,ListView
				  SENDMESSAGE(w1,@LVM_ENSUREVISIBLE,SearchLoop,0,ListView)
              SETCONTROLTEXT w1,101,InfoA
              Match = SearchLoop
				  LastPosFound = SearchLoop
              if !Switch
                 kw = 1
              endif
				  breakfor
			  endif
		  endif
	next SearchLoop

   if kw = 0 and Switch = 0
      showwindow w1,@SWHIDE,ListView
   endif

	SendMessage(rHandle,WM_SETREDRAW,true,0)
	InvalidateRect(rHandle,0,true)
	SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

return
endsub

sub GetTheScrollPos(window WinIn,int id,int HandleIn,opt int Switch)
    showcursor(FALSE)
    if !Switch
		 OnLine = FirstVisLine
		 for a = FirstVisLine-1 to FirstVisLine + 29
           CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			  if !len(ltrim$(line$)) then goto CheckNextLine
			  Offset = SendMessage(HandleIn,EM_LINEINDEX,a-1,0)
			  ColourLineZ(rHandle,a-1,line$,Offset)
		 label CheckNextLine
		 next a
		 SendMessage(rHandle,EM_SETSEL,1 + Offset,1 + Offset)
		 OldLine = OnLine
    endif
    if Switch = 1
		 OnLine = val(OldLastLine)
       int OldLastLineV = val(OldLastLine)
		 FOR a = OldLastLineV TO OldLastLineV + 1
           CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLine2
			  Offset = SENDMESSAGE(HandleIn,EM_LINEINDEX,a-1,0)
			  ColourLineZ(rHandle,a-1,line$,Offset)
       LABEL CheckNextLine2
		 NEXT a
		 Offset = SENDMESSAGE(HandleIn,EM_LINEINDEX,a,0)
		 SENDMESSAGE(rHandle,EM_SETSEL,1 + Offset,1 + Offset)
		 OldLine = OnLine
    ENDIF
    IF Switch = 2
		 OnLine = VAL(OldFirstLine)
		 FOR a = OldFirstLineX - 3 TO OldFirstLineX + 1
           CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLine4
			  Offset = SENDMESSAGE(HandleIn,EM_LINEINDEX,a-1,0)
			  ColourLineZ(rHandle,a-1,line$,Offset)
       LABEL CheckNextLine4
		 NEXT a
		 SENDMESSAGE(rHandle,EM_SETSEL,1 + Offset,1 + Offset)
		 OldLine = OnLine
    ENDIF
    showcursor(TRUE)
RETURN
ENDSUB

SUB ColourListViewSearch(hWnd:UINT,lParam:UINT),UINT
    STRING tempola
    INT row
	 row = *<NMLVCUSTOMDRAW>lParam.nmcd.dwItemSpec

	 IF row = LastPosFound 'Found a search match in the constant names
	    currentcolor = color1 'Highlight the line
	 ELSE
	    currentcolor = color4 'Otherwise colour the line's background white (normal)
	 ENDIF

    IF row = 0
	    currentcolor = color4 'Colour the line's background white (normal)
    ENDIF

 	 CONTROLCMD w7,ListView,@LVGETTEXT,row,0,tempola

	 SELECT *<NMLVCUSTOMDRAW>lParam.nmcd.dwDrawStage

			  CASE CDDS_PREPAINT
				    rv = CDRF_NOTIFYITEMDRAW

			  CASE CDDS_ITEMPREPAINT
				    rv = CDRF_NOTIFYSUBITEMDRAW

			  CASE CDDS_SUBITEMPREPAINT
				    *<NMLVCUSTOMDRAW>lParam.clrText = color3
				    *<NMLVCUSTOMDRAW>lParam.clrTextBk = currentcolor
				    rv = CDRF_NEWFONT

			  DEFAULT
				    rv = CDRF_DODEFAULT
   ENDSELECT
RETURN rv
ENDSUB

SUB SubclassRichEdit(parent AS WINDOW,id AS INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&Rich_Edit_Handler)
    SetPropA(hEdit,"edit_handler",lpfn)
RETURN
ENDSUB
SUB UnSubclassRichEdit(parent AS WINDOW,id AS INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
    RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB

SUB Rich_Edit_Handler(hwnd:INT,uMsg:INT,wParam:INT,lParam:POINTER),INT
    SELECT uMsg
           case WM_MOUSEMOVE

           case WM_KEYUP
                if wParam = 17 'Ctrl Key
                   CtrlDown = 0
                endif

                Typing = 0
					 if wParam = 20 'Caps lock
					    CapsOn = 1 - CapsOn
					 endif

           case WM_KEYDOWN
                if wParam = 17 'Ctrl Key
                   CtrlDown = 1
                endif

					 IF CtrlDown = 1 and wParam = 67 or wParam = 88 'Ctrl + C / X - Copy / Cut
						 OpenClipboard(w1.hwnd)
						 EmptyClipboard()
						 CloseClipboard()
						 ClipText2 = CutLine
						 CtrlDown = 0
						 return 0
					 endif

                Typing = 1

					 if wParam = UndoKey 'Undo
                   DoUndo(hwnd,uMsg,wParam,lParam)
					 endif

					 if wParam = RedoKey 'Redo
                   if AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   endif
                   DoRedo(hwnd,uMsg,wParam,lParam)
                   if AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   ENDIF
					 ENDIF

					 IF wParam = UndoAllKey 'Undo all
                   INT a1
                   FOR a1 = Undo2Count[OnTab] TO 0 STEP -1
                       DoUndo(hwnd,uMsg,wParam,lParam)
                   NEXT a1
					    eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
					    SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
					    FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    GetTheScrollPos(w1,1,rHandle)
					    SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
					    InvalidateRect(rHandle,0,true)
					    SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					    SENDMESSAGE(rHandle,EM_SETSEL,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] +1,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] +1)
					    SETFOCUS w1,1
   				 ENDIF

					 IF wParam = RedoAllKey 'Redo all
                   IF AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   ENDIF
                   FOR a1 = Redo2Count[OnTab] TO 0 STEP - 1
                       DoRedo(hwnd,uMsg,wParam,lParam)
                   NEXT a1
                   IF AutoCompleteStore = 1
                      AutoCompleteKeyWords = 1 - AutoCompleteKeyWords
                   ENDIF
					    eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
					    SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
					    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
					    GetTheScrollPos(w1,1,rHandle)
					    SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
					    InvalidateRect(rHandle,0,true)
					    SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					    SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] +1,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] +1)
					    setfocus w1,1
   				 endif

                if wParam = 46 or wParam = 8 'Delete / backspace keys
					    int varStart2,varEnd2
					    int xLine = 0

                      if wParam = 8 'Backspace
                         BackSpacePressed = 1
                      endif

							 xLine = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
                      CONTROLCMD(w1,1,@RTGETLINE,xLine,line$,512)
                      if wParam = 8 or wParam = 46 and len(Line$) <= 2
                         DoneBefore = 1
								 Undo2Count[OnTab] ++
								 Undo2[OnTab].Press[Undo2Count[OnTab]]  = 3
								 Undo2[OnTab].Typed[Undo2Count[OnTab]]  = chr$(10) '+ chr$(0)
								 xLine = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
								 Undo2[OnTab].LineNo[Undo2Count[OnTab]]  = xLine
                         CONTROLCMD(w1,1,@RTGETLINE,xLine,line$,512)
								 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine,0)
								 Undo2[OnTab].Pos[Undo2Count[OnTab]]  = Offset
								 Undo2[OnTab].Offset[Undo2Count[OnTab]]  = Offset
								 Undo2[OnTab].Was[Undo2Count[OnTab]]  = chr$(13) + chr$(0)
								 Undo2[OnTab].Colour = RGB(0,0,0)
                      endif

							 if DoneBefore = 1
								 DoneBefore = 0
							 endif

                   LABEL CarryOnDelete
                   CONTROLCMD w1,1,@RTSETMODIFIED,1
                   CurrentLines = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                   IF OldLines <> CurrentLines
                      OldLines = CurrentLines
                      MoveBlocks(cLine,1,0)
                   ENDIF

						 CONTROLCMD w1,1,@RTGETSELTEXT,ClipText
						 CutLine = ""
						 FOR a = 1 TO LEN(ClipText)
							  IF ASC(MID$(ClipText,a,1)) <> 13
								  CutLine = CutLine + MID$(ClipText,a,1)
							  ENDIF
						 NEXT a

                   IF LEN(ClipText) > 1
                      SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
							 Undo2Count[OnTab] ++
							 Undo2[OnTab].Press[Undo2Count[OnTab]]  = 4
							 Undo2[OnTab].Length[Undo2Count[OnTab]]  = LEN(ClipText)
							 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = ClipText
							 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]  = cr.cpMin
							 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]  = cr.cpMax
							 UndoBlock[OnTab].Length[Undo2Count[OnTab]]  = LEN(ClipText)
                      RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                   ENDIF
                ENDIF

                IF wParam = 34 'Page down
                   INT StoreTopLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
                   ScrollDownPage()
                   int NewTopLine = StoreTopLine + 29
                   setcontroltext(w1,EDIT_1,ltrim$(str$(NewTopLine)))
                   Offset = SendMessage(rHandle,EM_LINEINDEX,(sRange.Low / 16) + 28,0)
                   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
                   setfocus w1,1
                   RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                endif

                if wParam = 33 'Page Up
                   StoreTopLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						 ScrollUpPage()
                   NewTopLine = StoreTopLine - 29
                   setcontroltext(w1,EDIT_1,ltrim$(str$(NewTopLine)))
						 Offset = SendMessage(rHandle,EM_LINEINDEX,(sRange.Low / 16),0)
						 SendMessage(rHandle,EM_SETSEL,Offset,Offset)
						 setfocus w1,1
						 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
                endif

					 if wParam = 40 'Down arrow key
                   ScrollDownKey()
					 endif

					 if wParam = 38 'Up arrow key
						 if instr(getcontroltext(w1,1001),">")
							 KeyUp = 1
						 endif
					 endif

					 int xLine2
                xLine2 = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
                if wParam = 46 and len(xLine2) > 3 and DoneBefore = 0 'Delete

						 if Undo2Count[OnTab] = 0
							 Redo2Count[OnTab] = 0
						 endif
						 xLine2 = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
						 CONTROLCMD(w1,1,@RTGETLINE,xLine2,line2$,512)
						 INT varStart22,varEnd22
						 CONTROLCMD w1,1,@EDGETSELECTION,varStart22,varEnd22
						 Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,xLine2,0)
						 INT Wass = (varStart - Offset) + 1
						 Undo2Count[OnTab] ++
						 Undo2[OnTab].Press[Undo2Count[OnTab]]  = 3
						 Undo2[OnTab].Typed[Undo2Count[OnTab]]  = CHR$(46)
						 Undo2[OnTab].Pos[Undo2Count[OnTab]]  = varStart22
						 Undo2[OnTab].Offset[Undo2Count[OnTab]]  = Offset
						 INT Was = (varStart - Offset) + 1
                   Undo2[OnTab].Was[Undo2Count[OnTab]]  = MID$(Line2$,Wass,1)
						 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                ENDIF

						IF wParam = 48 OR wParam = 8
						   IF DoneBefore = 1
							   DoneBefore = 0
							   Undo2Count[OnTab] ++
							   Undo2[OnTab].Press[Undo2Count[OnTab]]  = 3
							   Undo2[OnTab].Typed[Undo2Count[OnTab]]  = CHR$(10)
							   Undo2[OnTab].Pos[Undo2Count[OnTab]]  = varStart22
							   Undo2[OnTab].Offset[Undo2Count[OnTab]]  = Offset
							   Undo2[OnTab].Was[Undo2Count[OnTab]]  = CHR$(10) 'mid$(Line2$,Wass,1
						   ENDIF
                  ENDIF

                IF wParam = 8 'Backspace
						 IF Undo2Count[OnTab] = 0
							 Redo2Count[OnTab] = 0
						 ENDIF
						 xLine2 = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
						 CONTROLCMD(w1,1,@RTGETLINE,xLine2,line2$,512)
						 CONTROLCMD w1,1,@EDGETSELECTION,varStart2,varEnd2
						 Undo2Count[OnTab] ++
						 Undo2[OnTab].Press[Undo2Count[OnTab]]  = 2
						 Undo2[OnTab].Pos[Undo2Count[OnTab]]  = varStart2
						 Undo2[OnTab].LineNo[Undo2Count[OnTab]]  = xLine2
						 Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,xLine2,0)
						 Undo2[OnTab].Offset[Undo2Count[OnTab]]  = Offset
						 Was = (varStart2 - Offset)
						 Undo2[OnTab].Was[Undo2Count[OnTab]]  = MID$(Line2$,Was,1)
						 Undo2[OnTab].Typed[Undo2Count[OnTab]]  = CHR$(8)
						 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                ENDIF

           CASE WM_CHAR


                CharTyped = CHR$(wParam)
					 IF Undo2Count[OnTab] = 0
						 Redo2Count[OnTab] = 0
					 ENDIF

                ManualChange = 0

                if wParam = 9 'Tab
						 CONTROLCMD w1,1,@EDGETSELECTION,varStart2,varEnd2

						 SendMessage(rHandle,EM_SETSEL,varStart2,varEnd2+1)
						 CONTROLCMD w1,1,@RTGETSELTEXT,Line2$
						 Line$ = ""
						 for a = 1 to TabSpacing
							  Line$ = Line$ + " "
							  varEnd2 ++
						 next a
						 CONTROLCMD w1,1,@RTREPLACESEL,Line$ + Line2$
						 SendMessage(rHandle,EM_SETSEL,varEnd2,varEnd2)

					    Undo2Count[OnTab] ++
					    Undo2[OnTab].Press[Undo2Count[OnTab]]  = 6
					    UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = Line$
					    UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]  = varStart2
					    UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]  = varEnd2
					    UndoBlock[OnTab].Length[Undo2Count[OnTab]]  = TabSpacing
                endif

                if wParam <> 8 and wParam <> 9 'and wParam <> 22 'and wParam <> 24
                   if kw and wParam = 13
                      RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
                   endif
						 CONTROLCMD w1,1,@EDGETSELECTION,varStart2,varEnd2
						 Undo2Count[OnTab] ++
						 Undo2[OnTab].Press[Undo2Count[OnTab]]  = 1
						 Undo2[OnTab].Typed[Undo2Count[OnTab]]  = CharTyped
						 Undo2[OnTab].Pos[Undo2Count[OnTab]]  = varStart2
						 xLine = CONTROLCMD(w1,1,@RTLINEFROMCHAR,-1)
						 Undo2[OnTab].LineNo[Undo2Count[OnTab]]  = xLine
						 CONTROLCMD(w1,1,@RTGETLINE,xLine,line$,512)
						 Offset = SendMessage(rHandle,EM_LINEINDEX,xLine,0)
						 Undo2[OnTab].Offset[Undo2Count[OnTab]]  = Offset
						 Was = (varStart - Offset) + 1
						 Undo2[OnTab].Was[Undo2Count[OnTab]]  = mid$(Line$,Was,1)
                   Undo2[OnTab].Colour = RGB(0,0,0)
					    SENDMESSAGE(rHandle,EM_SETSEL,varStart2,varStart2)

                   if wParam <> 39 'Not single comment character
							 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
							 SendMessage(rHandle,WM_SETREDRAW,false,0)
							 ColourLineZ(rHandle,cLine-1,line$,Offset)
							 SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
							 InvalidateRect(rHandle,0,true)
							 SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
							 SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] ,Undo2[OnTab].pos[Undo2Count[OnTab]] )
                   else
                      QuotesOn = 0
                      for a = 1 to len(Line$)
                          string qs = mid$(Line$,a,1)
                          if qs = chr$(34)
                             QuotesOn = 1 - QuotesOn
                          endif
                          if varStart2 = Offset + a
                             breakfor
                          endif
                      next a

							 cf.dwMask = CFM_COLOR
                      IF QuotesOn = 0
							    SENDMESSAGE(rHandle,EM_SETSEL,varStart2,LEN(Line$) + Offset)
							    cf.crTextColor = Green
                      ELSE
							    SENDMESSAGE(rHandle,EM_SETSEL,varStart2,varStart2)
							    cf.crTextColor = Purple
                         ManualChange = 1
                         QuotesOn = 0
                      ENDIF
							 cf.cbSize = SIZEOF(cf)
							 SENDMESSAGE(rHandle,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
							 SENDMESSAGE(rHandle,EM_SETSEL,varStart2,varStart2)
                    ENDIF
                ENDIF

                IF wParam = 13 AND kw = 0
                   Undo2[OnTab].Typed[Undo2Count[OnTab]]  = CHR$(13) + CHR$(10)
					    Undo2[OnTab].Was[Undo2Count[OnTab]]  = Line$
                ENDIF

                'CharTyped = ""

                CONTROLCMD w1,1,@RTSETMODIFIED,1
                sRange.Low = GETSCROLLPOS(w1,16) * 16

                IF wParam = 8
						 INT b1 = 0
						 INT DelS = varStart-1
						 INT DelE = varStart
						 STRING DelChar = ""
						 char_index = CONTROLCMD (w1,1,@RTCHARFROMLINE,cLine-1)
						 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						 SendMessage(rHandle,WM_SETREDRAW,false,0)

						 for b1 = varStart to char_index + 1 step - 1
							  CONTROLCMD w1,1,@RTSETSELECTION,DelS,DelE
							  CONTROLCMD w1,1,@RTGETSELTEXT,DelChar
							  if INSTR(CheckLetter,DelChar) > 0
								  CONTROLCMD w1,1,@RTSETSELECTION,b1,varStart
								  CONTROLCMD w1,1,@RTGETSELTEXT,DelChar
								  setcontroltext(w1,101,DelChar)
								  CONTROLCMD w1,1,@RTSETSELECTION,varStart,varStart
								  ttx = b1
								  varEnd = varStart
								  Search_And_Highlight(1,DelChar)
								  BREAKFOR
							  ENDIF

							  DelS --
							  DelE --

						 NEXT b1

						 IF b1 = char_index
							 CONTROLCMD w1,1,@RTSETSELECTION,b1,varStart
							 CONTROLCMD w1,1,@RTGETSELTEXT,DelChar
							 SETCONTROLTEXT(w1,101,DelChar)
							 CONTROLCMD w1,1,@RTSETSELECTION,varStart,varStart
							 ttx = b1
							 varEnd = varStart
							 Search_And_Highlight(1,DelChar)
						 ENDIF

						 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
						 InvalidateRect(rHandle,0,true)
						 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
                 ENDIF

		     CASE WM_LBUTTONDOWN

		     CASE WM_LBUTTONUP
                CONTROLCMD w1,1,@RTGETSELTEXT,ClipText
                CutLine = ""
                FOR a = 1 TO LEN(ClipText)
                    IF ASC(MID$(ClipText,a,1)) <> 13
                       CutLine = CutLine + MID$(ClipText,a,1)
                    ENDIF
                next a

           case WM_MOUSEWHEEL
					 int zDelta = GET_WHEEL_DELTA_WPARAM(wParam)
					 if zDelta > 0
                   'Scroll up
                   ScrollWheel(1)
					 else
                   'Scrolldown()
                   ScrollWheel(2)
					 endif

		     case WM_RBUTTONDOWN
					 POINT cursor2
					 GetCursorPos(cursor2)
					 ScreenToClient(w1.hwnd, cursor2)
					 CONTEXTMENU w1,cursor2.x, cursor2.y
						 MENUITEM "Cut",0,401
						 MENUITEM "Copy",0,402
						 MENUITEM "Paste",0,403
						 MENUITEM "Remove subroutines",0,204
						 MENUITEM "Select all",0,205
						 MENUITEM "Find",0,206
						 MENUITEM "Send to block",0,207
					 ENDMENU

    ENDSELECT

RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB

sub SetLines()

if Loading = 1 then return

int sl = cLine
FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)

if sl - FirstVisLine = 30
   int BottomLine = sl - FirstVisLine
   sl = val(getcontroltext(w1,1030))
	eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
	SendMessage(rHandle,WM_SETREDRAW,false,0)

	 showcursor(FALSE)
	 OnLine = FirstVisLine
	 for a = sl-1 to sl + 5
		  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
		  if len(ltrim$(line$)) < 3 then goto CheckNextLine
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineZ(rHandle,a-1,line$,Offset)
	 label CheckNextLine
	 next a
	 OldLine = OnLine
	 Offset = SendMessage(rHandle,EM_LINEINDEX,val(getcontroltext(w1,1030)),0)
	 CONTROLCMD w1,1,@RTSETSELECTION,Offset,Offset
	 showcursor(TRUE)

	 SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
	 InvalidateRect(rHandle,0,true)
	 SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

	 setcontroltext(w1,4,ltrim$(str$(FirstVisLine+1)))
	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a+2)))
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 next a

    int dll = val(getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	 setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	 SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour

    Offset = SendMessage(rHandle,EM_LINEINDEX,dll-1,0)
    CONTROLCMD(w1,1,@RTGETLINE,dll-1,line$,512)

    cLine = dll
    StoreLine = cLine
    Skip = 1

return

endif

if Skip = 0
	 setcontroltext(w1,4,ltrim$(str$(FirstVisLine+1)))
	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 next a
	 setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	 SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour
endif

return
endsub

sub SetLines2()

	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) ' + 1
	 setcontroltext(w1,4,ltrim$(str$(FirstVisLine+1)))
    setscrollpos(w1,16,FirstVisLine)
	 for a = 1 to 35
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
		  SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 next a
	 'setcontroltext(w1,1000 + (cLine-FirstVisLine),"> " + getcontroltext(w1,1000 + (cLine-FirstVisLine)))
	 'SETCONTROLCOLOR w1,1000 + (cLine-FirstVisLine),Red,BackColour

	 setcontroltext(w1,1001,"> " + getcontroltext(w1,1001))
	 SETCONTROLCOLOR w1,1001,Red,BackColour
	 sRange.Low = (GETSCROLLPOS(w1,16) * 16)
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)

return
endsub

sub ListViewUpdate(int Direction,int ToAdd)
int sl = 0
int el = 0
string text2 = ""
for a = 0 to CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
    CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
    CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text2)
    sl = val(text)
    el = val(text2)

    if Direction = 1
       if cLine < sl
          sl = sl + ToAdd
          el = el + ToAdd
       endif
       if cLine > sl and cLine < el
          el = el + ToAdd
       endif

    else

       if cLine < sl
          sl = sl - ToAdd
          el = el - ToAdd
       endif
       if cLine > sl and cLine < el
          el = el - ToAdd
       endif

    endif

    CONTROLCMD(w1,ListView2,@LVSETTEXT,a,1,str$(sl))
    CONTROLCMD(w1,ListView2,@LVSETTEXT,a,2,str$(el))
next a

for a = 0 to CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
    CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text2)
    sl = VAL(text)
    el = VAL(text2)

    IF Direction = 1

       IF cLine < sl
          sl = sl + ToAdd
          el = el + ToAdd
       ENDIF
       IF cLine > sl AND cLine < el
          el = el + ToAdd
       ENDIF

    ELSE

       IF cLine < sl
          sl = sl - ToAdd
          el = el - ToAdd
       ENDIF
       IF cLine > sl AND cLine < el
          el = el - ToAdd
       ENDIF

    ENDIF

    CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,STR$(sl))
    CONTROLCMD(w1,ListView4,@LVSETTEXT,a,2,STR$(el))

NEXT a

RETURN
ENDSUB

sub PopulateSubRoutines()
    int lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) -1
    for a = 0 to lvcount
        CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
        ADDSTRING w1,Combo2,text
    next a
return
endsub

sub PopulateWindows()
    int lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) -1
    for a = 0 to lvcount
        CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
        ADDSTRING w1,Combo4,text
    next a
return
endsub

sub ColourText(opt int Switch)

    if Switch = 1
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 34 'Page down
    endif

    if Switch = 2
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) - 34 'Page up
    endif

    if Switch = 3
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    endif

    if Switch = 4
	    FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1
    endif

    if Switch = 8
	    FirstVisLine = Fvis - 1
    endif

    if Switch = 9
	    FirstVisLine = Fvis - 1
    endif

    if Switch = 0
	    FirstVisLine = getscrollpos(w1,16)
    endif

	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 next a

	 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
	 SendMessage(rHandle,WM_SETREDRAW,false,0)

	 GetTheScrollPos(w1,1,rHandle)

	 SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
	 InvalidateRect(rHandle,0,true)
	 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
    IF FirstVisLine = 0
	    SETCONTROLTEXT(w1,4,"1")
    ELSE
	    SETCONTROLTEXT(w1,4,LTRIM$(STR$(FirstVisLine)))
    ENDIF

RETURN
ENDSUB

SUB FocusMain()
    OnBlock = 0
'setcaption w1,str$(OnBlock)
	 SHOWWINDOW w1,@SWHIDE,TextBlock1
	 SHOWWINDOW w1,@SWHIDE,TextBlock2
	 SHOWWINDOW w1,@SWHIDE,TextBlock3
	 SHOWWINDOW w1,@SWHIDE,TextBlock4
	 SHOWWINDOW w1,@SWSHOW,16
	 SHOWWINDOW w1,@SWSHOW,1
	 SETCONTROLCOLOR w1,ShowCode,RGB(255,255,255),Green
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETFOCUS w1
RETURN
ENDSUB

SUB FocusBlock1()
    OnBlock = 1
'setcaption w1,str$(OnBlock)
	 SHOWWINDOW w1,@SWHIDE,1
	 SHOWWINDOW w1,@SWHIDE,16
	 SHOWWINDOW w1,@SWHIDE,TextBlock2
	 SHOWWINDOW w1,@SWHIDE,TextBlock3
	 SHOWWINDOW w1,@SWHIDE,TextBlock4
	 SHOWWINDOW w1,@SWSHOW,TextBlock1
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(255,255,255),Green
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
    ENABLECONTROL w1,ShowBlock1,1
	 SETFOCUS w1,TextBlock1
RETURN
ENDSUB

SUB FocusBlock2()
    OnBlock = 2
'setcaption w1,str$(OnBlock)
	 SHOWWINDOW w1,@SWHIDE,1
	 SHOWWINDOW w1,@SWHIDE,16
	 SHOWWINDOW w1,@SWHIDE,TextBlock1
	 SHOWWINDOW w1,@SWHIDE,TextBlock3
	 SHOWWINDOW w1,@SWHIDE,TextBlock4
	 showwindow w1,@SWSHOW,TextBlock2
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(255,255,255),Green
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
	 setfocus w1,TextBlock2
return
endsub

sub FocusBlock3()
    OnBlock = 3
	 showwindow w1,@SWHIDE,1
	 showwindow w1,@SWHIDE,16
	 showwindow w1,@SWHIDE,TextBlock1
	 showwindow w1,@SWHIDE,TextBlock2
	 showwindow w1,@SWHIDE,TextBlock4
	 showwindow w1,@SWSHOW,TextBlock3
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(255,255,255),Green
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
	 setfocus w1,TextBlock2
return
endsub

sub FocusBlock4()
    OnBlock = 4
	 showwindow w1,@SWHIDE,1
	 showwindow w1,@SWHIDE,16
	 showwindow w1,@SWHIDE,TextBlock1
	 showwindow w1,@SWHIDE,TextBlock2
	 showwindow w1,@SWHIDE,TextBlock3
	 showwindow w1,@SWSHOW,TextBlock4
	 SETCONTROLCOLOR w1,ShowBlock4,RGB(255,255,255),Green
	 SETCONTROLCOLOR w1,ShowBlock1,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock2,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowBlock3,RGB(0,0,0),BackColour
	 SETCONTROLCOLOR w1,ShowCode,RGB(0,0,0),BackColour
	 SETFOCUS w1,TextBlock2
RETURN
ENDSUB

SUB StoreSubs()
	 FOR a = 1 TO 500000
       Subs[a] = 0
    NEXT a
    INT lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) -1
    SubCount = lvcount
	 FOR a = 0 TO lvcount
	    CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
       INT SubVal = VAL(Text)-1
       Subs[SubVal] = SubVal
    NEXT a
ENDSUB

SUB GetSub(WINDOW WinIn,INT id,OPT INT Bin)
    STRING text,text2
    INT ComboPos = GETSELECTED(w1,Combo2)
    IF ComboPos = -1 THEN RETURN
    CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(w1,ListView2,@LVGETTEXT,ComboPos,2,text2)
    INT StartOfSub = VAL(text)
    INT EndOfSub = VAL(text2)
	 FOR a = StartOfSub TO EndOfSub
		  CONTROLCMD(WinIn,id,@RTGETLINE,a-1,line$,255)
        CutLine = CutLine + line$
	 LABEL CheckNextLine
	 NEXT a

print "Start / end ",StartOfSub,"    ",EndOfSub
'print "Get sub ",len(CutLine)
    CopyStringToClipboard(CutLine)


    LineCount = (EndOfSub  - StartOfSub) + 1
    if Bin
       SendToBlock()
    endif
return
endsub

sub GetWindowE(window WinIn,int id,opt int Bin)
    string text,text2
    int ComboPos = getselected(w1,Combo4)
    if ComboPos = -1 then return
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,2,text2)
    int StartOfSub = val(text)
    int EndOfSub = val(text2)
	 for a = StartOfSub to EndOfSub
		  CONTROLCMD(WinIn,id,@RTGETLINE,a-1,line$,255)
        CutLine = CutLine + line$
	 label CheckNextLine
	 next a
    CopyStringToClipboard(CutLine)
    if Bin
       SendToBlock()
    endif
return
endsub

sub RemoveSub(window WinIn,int id,int ComboIn,opt int NoDelete)
    string text,text2,text4
    int ComboPos = getselected(WinIn,ComboIn)
    if ComboPos = -1 then return
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,0,text4)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,2,text2)
    INT StartOfSub = VAL(text)
    INT EndOfSub = VAL(text2)
    INT LinesToDelete = (EndOfSub - StartOfSub)
    INT OffsetS = SENDMESSAGE(rHandle,EM_LINEINDEX,StartOfSub-1,0)
    INT OffsetE = SENDMESSAGE(rHandle,EM_LINEINDEX,EndOfSub,0)
    OffsetE --

    CONTROLCMD w1,1,@RTSETSELECTION,OffsetS,OffsetE

    ClipText = ""
    CONTROLCMD w1,1,@RTGETSELTEXT,ClipText

	 IF LEN(ClipText)
		 Undo2Count[OnTab] ++
		 Undo2[OnTab].Press[Undo2Count[OnTab]] = 4
		 Undo2[OnTab].Length[Undo2Count[OnTab]] = LEN(ClipText)
		 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
		 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = OffsetS
		 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = OffsetE
		 UndoBlock[OnTab].Length[Undo2Count[OnTab]] = LEN(ClipText)
	 ENDIF

    CONTROLCMD w1,1,@RTSETSELECTION,OffsetS,OffsetE
    CONTROLCMD w1,1,@RTDELETESEL
    DELETESTRING WinIn,ComboIn,GETSELECTED(WinIn,ComboIn)

    INT lvcount = CONTROLCMD(WinIn,id,@LVGETCOUNT) - 1
    FOR a = 0 TO lvcount
        CONTROLCMD(WinIn,id,@LVGETTEXT,a,0,text)
        IF text = text4
           if NoDelete = 0
              CONTROLCMD(WinIn,id,@LVDELETEITEM,a)
           endif
           breakfor
        endif
    next a

    MoveBlocks(EndOfSub,LinesToDelete,0)
    ColourText()

return
endsub

sub RemoveWindow(window WinIn,int id)
    STRING text,text2,text4
    INT ComboPos = GETSELECTED(w1,Combo4)
    IF ComboPos = -1 THEN RETURN
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,0,text4)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(w1,ListView4,@LVGETTEXT,ComboPos,2,text2)
    INT StartOfSub = VAL(text)
    INT EndOfSub = VAL(text2)
    INT LinesToDelete = (EndOfSub - StartOfSub)
    INT OffsetS = SENDMESSAGE(rHandle,EM_LINEINDEX,StartOfSub-1,0)
    INT OffsetE = SENDMESSAGE(rHandle,EM_LINEINDEX,EndOfSub,0)
    OffsetE --

    CONTROLCMD WinIn,id,@RTSETSELECTION,OffsetS,OffsetE
    CONTROLCMD WinIn,id,@RTDELETESEL

    DELETESTRING WinIn,Combo4,GETSELECTED(w1,Combo4)

    INT lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
    FOR a = 0 TO lvcount
        CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
        IF text = text4
           CONTROLCMD(w1,ListView4,@LVDELETEITEM,a)
           BREAKFOR
        ENDIF
    NEXT a

    MoveBlocks(EndOfSub,LinesToDelete,0)
    ColourText()
    SETFOCUS w1,1
    SETSELECTED(w1,Combo4,-1)

return
endsub

sub SendToBlock()
	  uint bHandle = 0
	  CopyStringToClipboard(CutLine)

	  ReadClipBoardEditor()
	  int BlockX = 0
	  if getcontroltext(w1,TextBlock1) = ""
		  BlockX = TextBlock1
		  bHandle = getcontrolhandle(w1,TextBlock1)
		  enablecontrol w1,ShowBlock1,1
		  FocusBlock1()
	  else
		  if getcontroltext(w1,TextBlock2) = ""
			  BlockX = TextBlock2
			  bHandle = getcontrolhandle(w1,TextBlock2)
			  enablecontrol w1,ShowBlock2,1
			  FocusBlock2()
		  else
			  if getcontroltext(w1,TextBlock3) = ""
				  BlockX = TextBlock3
				  bHandle = getcontrolhandle(w1,TextBlock3)
				  enablecontrol w1,ShowBlock3,1
				  FocusBlock3()
			  else
				  if getcontroltext(w1,TextBlock4) = ""
					  BlockX = TextBlock4
					  bHandle = getcontrolhandle(w1,TextBlock4)
					  enablecontrol w1,ShowBlock4,1
					  FocusBlock4()
				  endif
			  endif


		  endif
	  endif

	  SETCONTROLTEXT w1,BlockX,""
	  SETCONTROLTEXT w1,BlockX,ClipText
	  SHOWWINDOW w1,@SWHIDE,1
	  SHOWWINDOW w1,@SWHIDE,16
	  SHOWWINDOW w1,@SWSHOW,BlockX

	  SENDMESSAGE(bHandle,EM_SETEVENTMASK,0,0)
	  SENDMESSAGE(bHandle,WM_SETREDRAW,false,0)

	  FOR a = 1 TO CONTROLCMD(w1,BlockX,@RTGETLINECOUNT)
			char_index = CONTROLCMD (w1,BlockX,@RTCHARFROMLINE,a-1)
			CONTROLCMD(w1,BlockX,@RTGETLINE,a-1,line$,255)
			ColourLineZ(bHandle,a-1,line$,char_index)
	  NEXT a

	  SENDMESSAGE(bHandle,WM_SETREDRAW,true,0)
	  InvalidateRect(bHandle,0,true)
	  SENDMESSAGE(bHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	  SENDMESSAGE(bHandle,EM_SETSEL,0,0)
	  ShowCursor(TRUE)
RETURN
ENDSUB

SUB JumpLine(OPT INT Bin)
	 FocusMain()
	 IF Bin
		 INT bm = VAL(GETSTRING(w1,Combo6,GETSELECTED(w1,Combo6)))
		 sRange.Low = (bm * 16) - 16
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
		 SETSCROLLPOS(w1,16,bm)
	 ELSE
	    ColourTextScroll()
		 sRange.Low = ((val(getcontroltext w1,EDIT_1)) * 16) '- 16
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
		 setscrollpos(w1,16,val(getcontroltext w1,EDIT_1))
	 endif

	 StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,sRange)
	 setfocus w1,1
	 CONTROLCMD w1,1,@RTSETSELECTION,StartAt,StartAt
	 ppos = GETCARETPOSITION w1,AcrossX,DownY
	 lvX = AcrossX
	 lvY = DownY
	 if kw = 0
		 setsize w1,lvX+58,lvY+98,300,38,ListView
	 ENDIF
	 AcrossX --
	 AcrossX = AcrossX / 8
	 AcrossX ++
	 EditPos = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
	 EditPos = EditPos + AcrossX
	 'ColourText()

	 StoreLine = VAL(GETCONTROLTEXT w1,EDIT_1)
	 SETSCROLLPOS(w1,16,StoreLine)
	 'cLine = val(text)
	 sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
	 FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

	 FOR a = 1 TO 30
		  SETCONTROLTEXT(w1,a+1000,STR$(FirstVisLine+(a-1)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 NEXT a

	 IF GETCONTROLTEXT(w1,EDIT_1) = ""
		 FOR a = 1 TO 30
			  SETCONTROLTEXT(w1,a+1000,STR$(a))
		 NEXT a
	 ENDIF

	 IF !Bin
		 SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
		 SETCONTROLCOLOR w1,1001,Red,BackColour
		 SETFOCUS w1,EDIT_1
	 ENDIF
RETURN
endsub

sub DoLineUp()
	 setscrollpos(w1,16,getscrollpos(w1,16)-1)
	 ColourText()
	 sRange.Low = (GETSCROLLPOS(w1,16) * 16)
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)

	 if getscrollpos(w1,16) = 0
		 for a = 1 to 35
			  setcontroltext(w1,a+1000,str$(a))
		 next a
	 endif
return
endsub

sub DoLineDown()
	 setscrollpos(w1,16,getscrollpos(w1,16)+1)
	 ColourText()
	 sRange.Low = GETSCROLLPOS(w1,16) * 16
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
return
endsub

Sub DoPaste()

	  ReadClipBoard()
	  StorecLine = cLine

	  if len(ClipText)
		  SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
		  Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
		  Undo2Count[OnTab] ++
		  Undo2[OnTab].Press[Undo2Count[OnTab]] = 5
		  Undo2[OnTab].Length[Undo2Count[OnTab]] = len(ClipText)
		  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]] = ClipText
		  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] = (Offset + ppos) -1 'cr.cpMin
		  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] = (Offset + len(ClipText)) -1  'cr.cpMax
		  UndoBlock[OnTab].Length[Undo2Count[OnTab]] = LEN(ClipText)
	  ENDIF

	  rHandle = GETCONTROLHANDLE(w1,1)
	  SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,0)
	  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

	  SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
	  CONTROLCMD w1,1,@RTDELETESEL
	  SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
	  CONTROLCMD w1,1,@RTREPLACESEL,ClipText

	  FOR a = cLine-(LineCount-1)-1 TO StorecLine + (LineCount-1)
			char_index = CONTROLCMD (w1,1,@RTCHARFROMLINE,a-1)
			CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			ColourLineZ(rHandle,a-1,line$,char_index)
	  NEXT a

	  SENDMESSAGE(rHandle,WM_SETREDRAW,true,0)
	  InvalidateRect(rHandle,0,true)
	  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	  ShowCursor(TRUE)
     MoveBlocks(cLine,LineCount,1)
	  SENDMESSAGE(rHandle,EM_SETSEL,1+char_index,1 + char_index)

RETURN
ENDSUB

SUB PrintDir(path:STRING),INT
DEF count:INT
DEF dir,attrib=0:INT
DEF filename:STRING
DEF fullname:STRING
count = 0
dir = FINDOPEN(path + "*.*")

string Caption = getcaption w1
Caption = mid$(Caption,1,instr(Caption,".")-1)
IF(dir)
	DO
		filename = FINDNEXT(dir,attrib)
		IF len(filename)
			IF attrib & @FILE_DIRECTORY
				IF(filename <> ".") & (filename <> "..")
					fullname = path + filename + "\\"
					count = count + printdir(fullname)
				ENDIF
			ELSE
            if instr(filename,".ini") and instr(filename,Caption) = 0
               count = count + 1
               ADDSTRING w1,Combo1,filename
            endif
			ENDIF
		ENDIF
	UNTIL filename = ""
	FINDCLOSE dir
ENDIF
RETURN count
ENDSUB

Sub DoPasteSub()

	  ReadClipBoard()
	  StorecLine = cLine

	  if len(ClipText)
		  SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)
		  Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
		  Undo2Count[OnTab] ++
		  Undo2[OnTab].Press[Undo2Count[OnTab]]  = 5
		  Undo2[OnTab].Length[Undo2Count[OnTab]]  = LEN(ClipText)
		  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = ClipText
		  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]  = (Offset + ppos) -1 'cr.cpMin
		  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]  = (Offset + LEN(ClipText)) -1  'cr.cpMax
		  UndoBlock[OnTab].Length[Undo2Count[OnTab]]  = LEN(ClipText)
	  ENDIF

	  rHandle = GETCONTROLHANDLE(w1,1)
	  SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,0)
	  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

	  SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
	  CONTROLCMD w1,1,@RTDELETESEL
	  SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
	  CONTROLCMD w1,1,@RTREPLACESEL,ClipText

	  FOR a = cLine-(LineCount-1)-1 TO StorecLine + (LineCount-1)
			char_index = CONTROLCMD (w1,1,@RTCHARFROMLINE,a-1)
			CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			ColourLineZ(rHandle,a-1,line$,char_index)
	  NEXT a

	  SENDMESSAGE(rHandle,WM_SETREDRAW,true,0)
	  InvalidateRect(rHandle,0,true)
	  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	  ShowCursor(TRUE)
     MoveBlocks(cLine,LineCount,1)
	  SENDMESSAGE(rHandle,EM_SETSEL,1+char_index,1 + char_index)

RETURN
ENDSUB

SUB ReadBlock(STRING FileIn),INT
    INT xx = 0
    INT aa = 0
    INT bb = 0

    CutLine = ""

	 OPENFILE(myFile,FileIn,"R")
       DO
			 READ myfile,dIn
          xx ++
          IF LEN(LTRIM$(dIn))
             IF Ucase <> 3
                dIn = ConvertWordsZ(xx,dIn,0)
             ELSE
                dIn = Indent()
             ENDIF
          ENDIF
          CutLine  = CutLine + RTRIM$(dIn) + CHR$(13) + CHR$ (10)
          LineEndPos[xx-1] = LEN(ClipText)
       UNTIL EOF(myFile)
       CLOSEFILE myFile

return xx
endsub

sub MoveBlocks(int FromPoint,int CountIn,int Operator)
    string text2,text4
    if Operator = 1 'Code added
       'Sub routines
		 int lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  int NewStart = val(text) + CountIn
				  text  = LTRIM$(STR$(NewStart-1))
				  INT NewEnd = VAL(text2) + CountIn
				  text2  = LTRIM$(STR$(NewEnd-1))
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,2,text2)
			  ENDIF
		 NEXT a
       'Windows
		 lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
		 FOR a = 0 TO lvcount
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text2)
			  IF VAL(text) >= FromPoint
				  NewStart = VAL(text) + CountIn
				  text  = LTRIM$(STR$(NewStart-1))
				  NewEnd = VAL(text2) + CountIn
				  text2  = LTRIM$(STR$(NewEnd-1))
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,2,text2)
			  ENDIF
		 NEXT a

       'Selects
		 lvcount = CONTROLCMD(w1,ListView8,@LVGETCOUNT) - 1
		 FOR a = 0 TO lvcount
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,2,text2)
			  IF VAL(text) >= FromPoint
				  NewStart = VAL(text) + CountIn
				  text  = LTRIM$(STR$(NewStart))
				  NewEnd = VAL(text2) + CountIn
				  text2  = LTRIM$(STR$(NewEnd))
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,2,text2)
			  ENDIF
		 NEXT a

       'BookMarks
/*


*/
		 lvcount = CONTROLCMD(w1,ListView6,@LVGETCOUNT) -1

		 FOR a = 1 TO 30
			  STRING StringLineNo = GETCONTROLTEXT(w1,a+1000)
			  IF INSTR(StringLineNo,">")
				  BREAKFOR
			  ENDIF
		 NEXT a

		 IF INSTR(StringLineNo,">")
			 StringLineNo = MID$(StringLineNo,INSTR(StringLineNo,">")+2,LEN(StringLineNo))
			 StringLineNo = LTRIM$(StringLineNo)
		 ENDIF

		 FOR a = 0 TO lvcount
			  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,0,text)
			  IF VAL(text) >= VAL(StringLineNo) + 1
				  NewStart = VAL(text) + (CountIn)
              IF CountIn = 1
				     text  = LTRIM$(STR$(NewStart))
              ELSE
				     text  = LTRIM$(STR$(NewStart-1))
              ENDIF
				  CONTROLCMD(w1,ListView6,@LVSETTEXT,a,0,text)
			  ENDIF
		 NEXT a

       IF lvcount > 1
          SortBookMarks()
       ENDIF
		 STRING MainName
		 STRING StoreBookFile

       'Navigation
       FOR a = 0 TO GETSTRINGCOUNT(w1,Combo18)
           text = GETSTRING(w1,Combo18,a)
			  IF VAL(text) >= VAL(StringLineNo) + 1 'FromPoint
				  NewStart = (VAL(text) + CountIn)
				  text  = LTRIM$(STR$(NewStart))
				  DELETESTRING(w1,Combo18,a)
              ADDSTRING(w1,Combo18,text)
			  ENDIF
       NEXT a

    ENDIF

    IF Operator = 0 'Code deleted
       'Sub routines
		 lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
		 FOR a = 0 TO lvcount
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text2)
			  IF VAL(text) >= FromPoint
				  NewStart = VAL(text) - CountIn
				  text  = LTRIM$(STR$(NewStart))
				  NewEnd = VAL(text2) - CountIn
				  text2  = LTRIM$(STR$(NewEnd))
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView2,@LVSETTEXT,a,2,text2)
			  endif
		 next a
       'Windows
		 lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text2)
			  if val(text) >= FromPoint
				  NewStart = val(text) - CountIn
				  text  = ltrim$(str$(NewStart))
				  NewEnd = val(text2) - CountIn
				  text2  = LTRIM$(STR$(NewEnd))
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView4,@LVSETTEXT,a,2,text2)
			  ENDIF
		 NEXT a

       'Selects
		 lvcount = CONTROLCMD(w1,ListView8,@LVGETCOUNT) - 1
		 FOR a = 0 TO lvcount
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text4)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,1,text)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,2,text2)
			  IF VAL(text) >= FromPoint
				  NewStart = VAL(text) - CountIn
				  text  = LTRIM$(STR$(NewStart))
				  NewEnd = VAL(text2) - CountIn
				  text2  = LTRIM$(STR$(NewEnd))
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,1,text)
				  CONTROLCMD(w1,ListView8,@LVSETTEXT,a,2,text2)
			  ENDIF
		 NEXT a

       'BookMarks
		 lvcount = CONTROLCMD(w1,ListView6,@LVGETCOUNT) -1

		 FOR a = 1 TO 30
			  StringLineNo = GETCONTROLTEXT(w1,a+1000)
			  IF INSTR(StringLineNo,">")
				  BREAKFOR
			  ENDIF
		 NEXT a

		 if instr(StringLineNo,">")
			 StringLineNo = mid$(StringLineNo,instr(StringLineNo,">")+2,len(StringLineNo))
			 StringLineNo = ltrim$(StringLineNo)
		 endif

		 for a = 0 to lvcount
			  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,0,text)
			  if val(text) >= val(StringLineNo) + 1
				  NewStart = val(text) - (CountIn)
              if CountIn = 1
				     text  = ltrim$(str$(NewStart))
              else
				     text  = ltrim$(str$(NewStart-1))
              endif
				  CONTROLCMD(w1,ListView6,@LVSETTEXT,a,0,text)
			  endif
		 next a

       if lvcount > 1
          SortBookMarks()
       endif
		 MainName = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
		 StoreBookFile = GETSTARTPATH() + "\\Res\\" + MainName + ".bmk"
		 deletefile StoreBookFile
       SaveBookMarks()

       for a = 0 to getstringcount(w1,Combo18)
           text = getstring(w1,Combo18,a)
			  if val(text) >= val(StringLineNo) + 1 'FromPoint
				  NewStart = (val(text) - CountIn)
				  text  = ltrim$(str$(NewStart))
				  deletestring(w1,Combo18,a)
              addstring(w1,Combo18,text)
			  endif
       next a

    endif

return
endsub

sub GetSubToFile(window WinIn,int id,opt int Bin)
    file MyFile2
    string text,text2

    openfile(MyFile2,GETSTARTPATH() + "\\Res\\xtemp.txt","W")

    if Bin = 0
       int ComboPos = getselected(w1,Combo2)
    else
       ComboPos = getselected(w1,Combo4)
    endif
    if ComboPos = -1 then return
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,0,StoreSubName)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,1,text)
    CONTROLCMD(WinIn,id,@LVGETTEXT,ComboPos,2,text2)

    int StartOfSub = val(text)
    int EndOfSub = val(text2)
	 for a = StartOfSub to EndOfSub
		  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
        line$ = mid$(line$,1,instr(line$,chr$(13))-1)
        write MyFile2,line$
	 label CheckNextLine
	 next a

    closefile(MyFile2)

return
endsub

Sub SaveBookMarks()

	 'string MainName = mid$(FileNameIs,1,instr(FileNameIs,".")-1)
	 'string StoreBookFile = GETSTARTPATH() + "\\Res\\" + MainName + ".bmk"

	 'openfile(MyFile2,StoreBookFile,"W")
		  'for a = 0 to getstringcount(w1,Combo6) - 1
				'write MyFile2,getstring(w1,Combo6,a)
		  'next a
	 'closefile MyFile2

return
endsub

SUB ScrollUpPage()
    ColourScreenPageUp()
RETURN
ENDSUB

SUB ScrollDownPage()
    ColourScreenPageDown()
    cLine -= 1
    StoreLine = cLine
RETURN
ENDSUB

SUB ScrollDownKey()
    INT BottomLine = StringToVal(GETCONTROLTEXT(w1,1028))
    IF cLine >= BottomLine
       ColourScreenVisableDown()
    ENDIF
RETURN
ENDSUB

SUB ScrollUpKey()
    ColourScreenVisableUp()
RETURN
ENDSUB

SUB Combo10Add()
	 INT Combo10Count = GETSTRINGCOUNT(w1,Combo10)
	 IF Combo10Count > 0
       SENDMESSAGE(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)
	 ENDIF
	 INT LoopFrom = VAL(TextIn1)-1
	 INT LoopTo =  VAL(TextIn2)-1
    CONTROLCMD(w1,ListView10,@LVDELETEALL)
	 ToAdd = -1
	 FOR a = LoopFrom TO LoopTo
		  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
		  STRING SimpleCase = LTRIM$(line$)
		  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLine
            IF MID$(UCASE$(line$),1,6) = "ENDSUB" THEN BREAKFOR
				IF INSTR(UCASE$(line$),"CASE") OR INSTR(UCASE$(line$),"DEFAULT")
					IF MID$(UCASE$(SimpleCase),1,4) = "CASE" OR MID$(UCASE$(SimpleCase),1,7) = "DEFAULT"
						ToAdd ++
                  IF MID$(UCASE$(SimpleCase),1,4) = "CASE"
                     SimpleCase = MID$(SimpleCase,5,LEN(SimpleCase))
                     SimpleCase = LTRIM$(SimpleCase)
                     'SimpleCase = mid$(SimpleCase,1,len(SimpleCase)-1)
                  ENDIF
						CONTROLCMD w1,ListView10,@LVINSERTITEM,ToAdd,SimpleCase
					   CONTROLCMD w1,ListView10,@LVSETTEXT,ToAdd,1,LTRIM$(STR$(a))
					ENDIF
				ENDIF
	 LABEL CheckNextLine
	 NEXT a
	 SETCONTROLTEXT(w1,CaseStatic,"Cases (" + LTRIM$(STR$(ToAdd+1)) + ")")
    SortListView()
RETURN
ENDSUB

SUB SortListView()
STRING text2,text3
INT loops,count,swap
INT lvcountIn = CONTROLCMD(w1,ListView10,@LVGETCOUNT)

IF lvcountIn <= 2
	SENDMESSAGE(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)
	FOR a = 0 TO lvcountIn - 1
		 CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
		 ADDSTRING(w1,Combo10,text)
	NEXT a
	RETURN
ENDIF

FOR a = 0 TO lvcountIn - 1
    CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
    CONTROLCMD(w1,ListView10,@LVGETTEXT,a,1,text2)
    CONTROLCMD(w1,ListView10,@LVGETTEXT,a,2,text3)

    Col1[a] = text

    if mid$(Col1[a],1,1) = "&"
       Col1[a] = ltrim$(mid$(Col1[a],2,len(Col1[a])))
    endif

    Col2[a] = text2
    Col3[a] = text3
    Col1[a+1] = ""
    Col2[a+1] = ""
    Col3[a+1] = ""

next a

count = lvcountIn
swap=0

int change,cnt_step
string s_tmp1,s_tmp2,s_tmp3
cnt_step = (count-1)/2

do
	change=0
	loops++
	for x = 0 to count-cnt_step
		if Col1[x]>Col1[x+cnt_step]
			s_tmp1 = Col1[x+cnt_step]
			Col1[x+cnt_step] = Col1[x]
			Col1[x] = s_tmp1
			s_tmp2 = Col2[x+cnt_step]
			Col2[x+cnt_step] = Col2[x]
			Col2[x] = s_tmp2
			s_tmp3 = Col3[x+cnt_step]
			Col3[x+cnt_step] = Col3[x]
			Col3[x] = s_tmp3
			swap++
			change++
		endif
	NEXT x
	IF cnt_step>1
		cnt_step=cnt_step/2
	ENDIF

UNTIL change < 1 AND cnt_step = 1

CONTROLCMD(w1,ListView10,@LVDELETEALL)
SENDMESSAGE(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)

FOR a = 0 TO lvcountIn - 1
    IF INSTR(Col1[a+1]," ")
	    Col1[a+1] = MID$(Col1[a+1],1,INSTR(Col1[a+1]," ")-1)
    ENDIF
	 CONTROLCMD w1,ListView10,@LVINSERTITEM,a,Col1[a+1]
	 CONTROLCMD w1,ListView10,@LVSETTEXT,a,1,Col2[a+1]
	 CONTROLCMD w1,ListView10,@LVSETTEXT,a,2,Col3[a+1]
	 ADDSTRING(w1,Combo10,Col1[a+1])
NEXT a

CONTROLCMD w1,ListView10,@LVGETTEXT,a,0,text
IF text = ""
   CONTROLCMD w1,ListView10,@LVDELETEITEM,0
   DELETESTRING(w1,Combo10,0)
ENDIF

RETURN
ENDSUB

SUB SortBookmarks()
STRING text2
INT loops,count,swap
int lvcountIn = CONTROLCMD(w1,ListView6,@LVGETCOUNT)

if lvcountIn = 1
    CONTROLCMD w1,ListView6,@LVGETTEXT,0,0,text
    CONTROLCMD w1,ListView6,@LVGETTEXT,0,1,text2
    insertstring(w1,Combo6,0,text + " " + text2)
    return
endif

if lvcountIn < 3 then return
for a = 0 to lvcountIn - 1
    CONTROLCMD w1,ListView6,@LVGETTEXT,a,0,text
    CONTROLCMD w1,ListView6,@LVGETTEXT,a,1,text2
    Col1[a] = text
    Col1[a+1] = ""
    Col2[a] = text2
    Col2[a+1] = ""
NEXT a

count = lvcountIn
swap = 0

INT change,cnt_step
STRING s_tmp1,s_tmp2
cnt_step = (count-1)/2

DO
	change = 0
	loops++
	FOR x = 0 TO count-cnt_step
       IF VAL(Col1[x]) > VAL(Col1[x + cnt_step])
			 s_tmp1 = Col1[x + cnt_step]
			 Col1[x + cnt_step] = Col1[x]
			 Col1[x] = s_tmp1
			 s_tmp2 = Col2[x+cnt_step]
			 Col2[x+cnt_step] = Col2[x]
			 Col2[x] = s_tmp2
			 swap++
			 change++
		ENDIF
	NEXT x
	IF cnt_step>1
		cnt_step=cnt_step/2
	ENDIF

IF cnt_step = 0 AND count = 2 THEN BREAK
UNTIL change < 1 AND cnt_step = 1

INT EmptyCount = -1
CONTROLCMD(w1,ListView6,@LVDELETEALL)
SENDMESSAGE(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
FOR a = 0 TO lvcountIn
    IF LEN(Col1[a]) > 0
       EmptyCount ++
	    CONTROLCMD w1,ListView6,@LVINSERTITEM,EmptyCount,Col1[a]
	    CONTROLCMD w1,ListView6,@LVSETTEXT,EmptyCount,1,Col2[a]
       INSERTSTRING(w1,Combo6,EmptyCount,Col1[a] + " " + Col2[a])
    ENDIF
NEXT a

RETURN
ENDSUB

SUB WindowSearch()

OPENWINDOW w2,0,0,800,400,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Find",&handler
  SETWINDOWCOLOR w2,BackColour

  CONTROL w2,@LISTVIEW,"",12,10,770,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w2,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w2,ListViewResult,@LVINSERTCOLUMN,0,"Line"
			 CONTROLCMD w2,ListViewResult,@LVSETCOLWIDTH,0,70
			 CONTROLCMD w2,ListViewResult,@LVINSERTCOLUMN,1,""
			 CONTROLCMD w2,ListViewResult,@LVSETCOLWIDTH,1,500
			 CONTROLCMD w2,ListViewResult,@LVINSERTCOLUMN,2,"Subroutine / Window"
			 CONTROLCMD w2,ListViewResult,@LVSETCOLWIDTH,2,200
          SENDMESSAGE w2,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w2,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w2,"Arial",11,400,0,ListViewResult

  CONTROL w2,@BUTTON,"Close",705,340,80,25,0,2

			 INT InsertPos = -1
			 INT lncount = CONTROLCMD(w1,1,@RTGETLINECOUNT)
			 STRING KeyWString = GETSTRING(w1,Combo12,GETSELECTED(w1,Combo12))
			 CONTROLCMD w1,ListViewResult,@LVDELETEALL
			 FOR a = 0 TO lncount - 1
				  CONTROLCMD(w1,1,@RTGETLINE,a,line$,512)
				  IF INSTR(UCASE$(line$),KeyWString)
					  InsertPos ++
					  CONTROLCMD w2,ListViewResult,@LVINSERTITEM,InsertPos,LTRIM$(STR$(a+1))
					  CONTROLCMD w2,ListViewResult,@LVSETTEXT,InsertPos,1,LTRIM$(line$)
					  STRING text2,text4
					  int lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
					  for b = 0 to lvcount
						   CONTROLCMD(w1,ListView2,@LVGETTEXT,b,0,text4)
						   CONTROLCMD(w1,ListView2,@LVGETTEXT,b,1,text)
						   CONTROLCMD(w1,ListView2,@LVGETTEXT,b,2,text2)
						   if val(text) <= a + 1 and val(text2) >= a + 1
							   CONTROLCMD(w2,ListViewResult,@LVSETTEXT,InsertPos,2,text4)
						   endif
					  next b

					  CONTROLCMD(w2,ListViewResult,@LVGETTEXT,InsertPos,2,text4)

                 if text4 = ""
						  lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
						  FOR b = 0 TO lvcount
								CONTROLCMD(w1,ListView4,@LVGETTEXT,b,0,text4)
								CONTROLCMD(w1,ListView4,@LVGETTEXT,b,1,text)
								CONTROLCMD(w1,ListView4,@LVGETTEXT,b,2,text2)
								IF VAL(text) <= a + 1 AND VAL(text2) >= a + 1
									CONTROLCMD(w2,ListViewResult,@LVSETTEXT,InsertPos,2,text4)
								ENDIF
						  NEXT b
                 ENDIF
				  ENDIF
			 NEXT a

          SETCAPTION w2,KeyWString + " " + STR$(CONTROLCMD(w2,ListViewResult,@LVGETCOUNT)) + " found."

   SETFONT w2,"Arial",10,500,0,2
   SETCONTROLCOLOR w2,2,RGB(0,0,0),RGB(255,255,255)
WAITUNTIL ISWINDOWCLOSED(w2)

RETURN
ENDSUB

SUB handler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w2

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w2

           CASE @IDCONTROL
                SELECT @CONTROLID

							  CASE ListViewResult
									 IF @NOTIFYCODE=@NMCLICK
										 LABEL ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w2,ListViewResult,@LVGETTEXT,lvpos,0,text)
										 SETCONTROLTEXT(w1,EDIT_1,text)
									 ENDIF

							  CASE 2
									 IF @NOTIFYCODE = 0
                               CLOSEWINDOW w2
                            ENDIF

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

SUB WindowSearchCode()

OPENWINDOW w4,0,0,800,400,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Find",&SearchCodeHandler
  SETWINDOWCOLOR w4,BackColour

  CONTROL w4,@LISTVIEW,"",12,10,770,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w4,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w4,ListViewResult,@LVINSERTCOLUMN,0,"Line"
			 CONTROLCMD w4,ListViewResult,@LVSETCOLWIDTH,0,70
			 CONTROLCMD w4,ListViewResult,@LVINSERTCOLUMN,1,""
			 CONTROLCMD w4,ListViewResult,@LVSETCOLWIDTH,1,500
			 CONTROLCMD w4,ListViewResult,@LVINSERTCOLUMN,2,"Subroutine / Window"
			 CONTROLCMD w4,ListViewResult,@LVSETCOLWIDTH,2,200
          SENDMESSAGE w4,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w4,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w4,"Arial",11,400,0,ListViewResult

  CONTROL w4,@STATIC,"Searching...",10,340,600,20,@CTEDITLEFT|0x200,4
          SETFONT w4,"Arial",10,500,0,4
          SETCONTROLCOLOR w4,4,RGB(0,0,0),BackColour

  CONTROL w4,@BUTTON,"Close",705,340,80,25,0,2
          SETFONT w4,"Arial",10,500,0,2
          SETCONTROLCOLOR w4,2,RGB(0,0,0),RGB(255,255,255)

          InsertPosAt = -1
          INT CodeSearchType = 0
			 INT lncount = CONTROLCMD(w1,1,@RTGETLINECOUNT)
          STRING CodeWord1 = RTRIM$(LTRIM$(GETCONTROLTEXT(w1,CodeWordEdit1)))
          STRING CodeWord2 = RTRIM$(LTRIM$(GETCONTROLTEXT(w1,CodeWordEdit2)))
			 FOR a = 0 TO lncount - 1
				  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
				  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLineW4
				  Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,a-1,0)
              IF GETCONTROLTEXT(w1,CodeWordEdit2) <> ""
					  IF GETSTATE(w1,CodeWordAnd) = 1
						  CodeSearchType = 2
					  ELSE
						  CodeSearchType = 1
					  ENDIF
              ELSE
					  CodeSearchType = 1
              ENDIF
				  CodeSearchForWord(w4,ListViewResult,a-1,line$,Offset,CodeWord1,CodeWord2,CodeSearchType)

			 LABEL CheckNextLineW4
			 NEXT a

          SETCONTROLTEXT w4,4,""

          IF CodeSearchType = 1 AND CodeWordOrV = 0
            SETCAPTION w4,"Results for ' " + CodeWord1 + " ' - " + STR$(CONTROLCMD(w4,ListViewResult,@LVGETCOUNT)) + " found."
          endif

          if CodeSearchType = 2 or CodeWordOrV = 1
             if CodeWordOrV = 1
                setcaption w4,"Results for ' " + CodeWord1 + " ' OR ' " + CodeWord2 + " ' - " + str$(CONTROLCMD(w4,ListViewResult,@LVGETCOUNT)) + " found."
             else
                setcaption w4,"Results for ' " + CodeWord1 + " ' AND ' " + CodeWord2 + " ' - " + str$(CONTROLCMD(w4,ListViewResult,@LVGETCOUNT)) + " found."
             endif
          endif

setcontroltext(w1,4,"")

WAITUNTIL IsWindowClosed(w4)

RETURN
ENDSUB

SUB SearchCodeHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w4

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w4

           CASE @IDCONTROL
                SELECT @CONTROLID

							  CASE ListViewResult
									 IF @NOTIFYCODE=@NMCLICK
										 LABEL ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w4,ListViewResult,@LVGETTEXT,lvpos,0,text)
										 SETCONTROLTEXT(w1,EDIT_1,text)
									 ENDIF

							  CASE 2
									 IF @NOTIFYCODE = 0
                               CLOSEWINDOW w4
                            ENDIF

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

SUB WindowSearchPhrase()
ReplaceNow = 0
SHOWWINDOW w1,@SWHIDE,ListView
OPENWINDOW w6,0,0,800,600,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Searching...",&SearchPhraseHandler
  SETWINDOWCOLOR w6,BackColour

  CONTROL w6,@LISTVIEW,"",12,10,770,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w6,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w6,ListViewResult,@LVINSERTCOLUMN,0,"Line"
			 CONTROLCMD w6,ListViewResult,@LVSETCOLWIDTH,0,70
			 CONTROLCMD w6,ListViewResult,@LVINSERTCOLUMN,1,""
			 CONTROLCMD w6,ListViewResult,@LVSETCOLWIDTH,1,500
			 CONTROLCMD w6,ListViewResult,@LVINSERTCOLUMN,2,"Subroutine / Window"
			 CONTROLCMD w6,ListViewResult,@LVSETCOLWIDTH,2,200
          SENDMESSAGE w6,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w6,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w6,"Arial",11,400,0,ListViewResult

  'CONTROL w6,@STATIC,"Searching...",10,340,600,20,@CTEDITLEFT|0x200,4
          'SETFONT w6,"Arial",10,500,0,4
          'SETCONTROLCOLOR w6,4,RGB(0,0,0),RGB(255,255,255)

  CONTROL w6,@BUTTON,"Close",705,540,80,25,0,2
          SETFONT w6,"Arial",10,500,0,2
          SETCONTROLCOLOR w6,2,RGB(0,0,0),RGB(255,255,255)

  CONTROL w6,@BUTTON,"Replace",12,340,80,25,0,ReplaceButton
          SETFONT w6,"Arial",10,500,0,ReplaceButton
          SETCONTROLCOLOR w6,ReplaceButton,RGB(0,0,0),RGB(255,255,255)
          SHOWWINDOW w6,@SWHIDE,ReplaceButton

   CONTROL w6,@EDIT,"",100,340,210,25,@CTEDITAUTOH|@CTEDITLEFT,ReplaceWhat
           CONTROLCMD w6,ReplaceWhat,@EDSETLIMITTEXT,255
	        SETFONT w6,"Arial",10,400,0,ReplaceWhat
           SETCONTROLNOTIFY(w6,ReplaceWhat,1,1)
           SHOWWINDOW w6,@SWHIDE,ReplaceWhat

   CONTROL w6,@STATIC,"With",314,340,35,20,@CTEDITRIGHT|0x200,ReplaceStatic
           SETFONT w6,"Arial",10,500,0,ReplaceStatic
           SETCONTROLCOLOR w6,ReplaceStatic,RGB(0,0,0),BackColour
           SHOWWINDOW w6,@SWHIDE,ReplaceStatic

   CONTROL w6,@EDIT,"",360,340,210,25,@CTEDITAUTOH|@CTEDITLEFT,ReplaceWith
           CONTROLCMD w6,ReplaceWhat,@EDSETLIMITTEXT,255
	        SETFONT w6,"Arial",10,400,0,ReplaceWith
           SETCONTROLNOTIFY(w6,ReplaceWith,1,1)
           SHOWWINDOW w6,@SWHIDE,ReplaceWith

   CONTROL w6,@BUTTON,"Replace now",580,340,110,25,0,GoReplace
           SETFONT w6,"Arial",10,500,0,GoReplace
           SETCONTROLCOLOR w6,GoReplace,RGB(0,0,0),RGB(255,255,255)
           ENABLECONTROL w6,GoReplace,0
           SHOWWINDOW w6,@SWHIDE,GoReplace

          'Word search type
			 IF CodePhraseWordsV = 1
				 INT b1 = 0
				 FOR b1 = 1 TO 4
					  #w[b1].aWord = ""
				 NEXT b1

				 InsertPosAt = -1
				 INT lncount = CONTROLCMD(w1,1,@RTGETLINECOUNT)
				 STRING CodeWord1 = RTRIM$(LTRIM$(GETCONTROLTEXT(w1,CodePhraseEdit)))
				 CodeWordSearchA(1,CodeWord1,a-1)

				 WordCountEdit = WordCount

				 FOR a = 0 TO lncount - 1
					  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
					  STRING ReturnLine = CodeWordSearchA(0,line$,a-1,WordCountEdit,#w[1].aWord,#w[2].aWord,#w[3].aWord,#w[4].aWord)
					  IF ReturnLine <> ""
							  InsertPosAt ++
							  CONTROLCMD w6,ListViewResult,@LVINSERTITEM,InsertPosAt,LTRIM$(STR$(a))
							  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertPosAt,1,LTRIM$(ReturnLine)

							  STRING text2,text4
							  INT lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
							  FOR b = 0 TO lvcount
									CONTROLCMD(w1,ListView2,@LVGETTEXT,b,0,text4)
									CONTROLCMD(w1,ListView2,@LVGETTEXT,b,1,text)
									CONTROLCMD(w1,ListView2,@LVGETTEXT,b,2,text2)
									IF VAL(text) <= a + 1 AND VAL(text2) >= a + 1
										CONTROLCMD(w6,ListViewResult,@LVSETTEXT,InsertPosAt,2,text4)
									ENDIF
							  NEXT b

							  CONTROLCMD(w6,ListViewResult,@LVGETTEXT,InsertPosAt,2,text4)

							  IF text4 = ""
								  lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
								  FOR b = 0 TO lvcount
										CONTROLCMD(w1,ListView4,@LVGETTEXT,b,0,text4)
										CONTROLCMD(w1,ListView4,@LVGETTEXT,b,1,text)
										CONTROLCMD(w1,ListView4,@LVGETTEXT,b,2,text2)
										IF VAL(text) <= a + 1 AND VAL(text2) >= a + 1
											CONTROLCMD(w6,ListViewResult,@LVSETTEXT,InsertPosAt,2,text4)
										ENDIF
								  NEXT b
							  ENDIF

					  ENDIF
				 NEXT a

			  ELSE

				 'Exact search type
				 InsertPosAt = -1
				 lncount = CONTROLCMD(w1,1,@RTGETLINECOUNT)
				 CodeWord1 = RTRIM$(LTRIM$(GETCONTROLTEXT(w1,CodePhraseEdit)))
				 FOR a = 0 TO lncount - 1
					  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
					  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLineW6
						  IF INSTR(UCASE$(line$),UCASE$(CodeWord1))
							  InsertPosAt ++
							  CONTROLCMD w6,ListViewResult,@LVINSERTITEM,InsertPosAt,LTRIM$(STR$(a))
							  CONTROLCMD w6,ListViewResult,@LVSETTEXT,InsertPosAt,1,LTRIM$(line$)
							  text2 = ""
                       text4 = ""
							  lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT) - 1
							  FOR b = 0 TO lvcount
									CONTROLCMD(w1,ListView2,@LVGETTEXT,b,0,text4)
									CONTROLCMD(w1,ListView2,@LVGETTEXT,b,1,text)
									CONTROLCMD(w1,ListView2,@LVGETTEXT,b,2,text2)
									IF VAL(text) <= a + 1 AND VAL(text2) >= a + 1
										CONTROLCMD(w6,ListViewResult,@LVSETTEXT,InsertPosAt,2,text4)
									ENDIF
							  NEXT b

							  CONTROLCMD(w6,ListViewResult,@LVGETTEXT,InsertPosAt,2,text4)

							  IF text4 = ""
								  lvcount = CONTROLCMD(w1,ListView4,@LVGETCOUNT) - 1
								  FOR b = 0 TO lvcount
										CONTROLCMD(w1,ListView4,@LVGETTEXT,b,0,text4)
										CONTROLCMD(w1,ListView4,@LVGETTEXT,b,1,text)
										CONTROLCMD(w1,ListView4,@LVGETTEXT,b,2,text2)
										IF VAL(text) <= a + 1 AND VAL(text2) >= a + 1
											CONTROLCMD(w6,ListViewResult,@LVSETTEXT,InsertPosAt,2,text4)
										ENDIF
								  NEXT b
							  ENDIF
						  ENDIF
					 LABEL CheckNextLineW6
					 NEXT a
			  ENDIF

           SETCONTROLTEXT w6,4,""
           SETCAPTION w6,STR$(CONTROLCMD(w6,ListViewResult,@LVGETCOUNT)) + " found."

           IF CONTROLCMD(w6,ListViewResult,@LVGETCOUNT) > 0
              SHOWWINDOW w6,@SWSHOW,ReplaceButton
           ENDIF

LABEL templabel
WAITUNTIL ISWINDOWCLOSED(w6)

RETURN
ENDSUB

SUB SearchPhraseHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w6

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w6

           CASE @IDCONTROL
                SELECT @CONTROLID
                       CASE ReplaceWhat
                            IF @NOTIFYCODE = @ENCHANGE
                               IF GETCONTROLTEXT(w6,ReplaceWhat) <> "" AND GETCONTROLTEXT(w6,ReplaceWith) <> ""
                                  ENABLECONTROL w6,GoReplace,1
                               ELSE
                                  ENABLECONTROL w6,GoReplace,0
                               ENDIF
                            ENDIF

                            IF @NOTIFYCODE = @ENENTERKEY
                               SETFOCUS w6,ReplaceWith
                            ENDIF
                            IF @NOTIFYCODE = @ENTABKEY
                               SETFOCUS w6,ReplaceWith
                            ENDIF

                       case ReplaceWith
                            IF @NOTIFYCODE = @ENCHANGE
                               if getcontroltext(w6,ReplaceWhat) <> "" and getcontroltext(w6,ReplaceWith) <> ""
                                  enablecontrol w6,GoReplace,1
                               else
                                  enablecontrol w6,GoReplace,0
                               endif
                            endif

                            IF @NOTIFYCODE = @ENENTERKEY
                               goto GoReplaceNow
                            endif

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK
										 LABEL ClickListViewResult
                               IF ReplaceNow = 0
										    lvpos=*<NMLISTVIEW>@LPARAM.iItem
										    CONTROLCMD(w6,ListViewResult,@LVGETTEXT,lvpos,0,text)
										    SETCONTROLTEXT(w1,EDIT_1,text)
                               ENDIF
									 ENDIF

                       CASE ReplaceButton
									 IF @NOTIFYCODE = 0
                               ReplaceNow = 1 - ReplaceNow
                               IF ReplaceNow = 0
                                  SHOWWINDOW w6,@SWHIDE,ReplaceWhat
                                  SHOWWINDOW w6,@SWHIDE,ReplaceStatic
                                  SHOWWINDOW w6,@SWHIDE,ReplaceWith
                                  SHOWWINDOW w6,@SWHIDE,GoReplace
                                  SETCONTROLTEXT(w6,ReplaceButton,"Replace now")
                                  SETFOCUS w6
                               ELSE
                                  SHOWWINDOW w6,@SWSHOW,ReplaceWhat
                                  SHOWWINDOW w6,@SWSHOW,ReplaceStatic
                                  SHOWWINDOW w6,@SWSHOW,ReplaceWith
                                  SHOWWINDOW w6,@SWSHOW,GoReplace
                                  SETCONTROLTEXT(w6,ReplaceButton,"Hide")
                                  SETFOCUS w6,ReplaceWhat
                               ENDIF
                            ENDIF

                       CASE GoReplace
									 IF @NOTIFYCODE = 0
                               LABEL GoReplaceNow
                               STOPTIMER w1,10000
                               int WasOnLine = getscrollpos(w1,16)
										 int lvr = CONTROLCMD(w6,ListViewResult,@LVGETCOUNT)
										 for a = 0 to lvr
											  CONTROLCMD(w6,ListViewResult,@LVGETTEXT,a,1,text)
											  if Instr(ucase$(text),ucase$(getcontroltext(w6,ReplaceWhat)))
												  int Rpos = Instr(ucase$(text),ucase$(getcontroltext(w6,ReplaceWhat)))
												  string Before = mid$(text,1,Rpos-1)
												  string After =  mid$(text,(Rpos + len(getcontroltext(w6,ReplaceWhat))),len(text))
												  text = Before + getcontroltext(w6,ReplaceWith) + After
												  CONTROLCMD(w6,ListViewResult,@LVSETTEXT,a,1,text)
                                      CONTROLCMD(w6,ListViewResult,@LVGETTEXT,a,0,text)

												  int textV = val(text)-1
												  CONTROLCMD(w1,1,@RTGETLINE,textV,line$,512)
												  int ROffset = SendMessage(rHandle,EM_LINEINDEX,textV,0)
												  int REnd = (ROffset + len(line$))-2
												  Rpos = Instr(ucase$(line$),ucase$(getcontroltext(w6,ReplaceWhat)))
												  Before = mid$(line$,1,Rpos-1)
												  After =  mid$(line$,(Rpos + len(getcontroltext(w6,ReplaceWhat))),len(line$))
												  if instr(After,chr$(13))
													  After = mid$(After,1,instr(After,chr$(13))-1)
												  endif
												  line2$ = Before + getcontroltext(w6,ReplaceWith) + After
												  CONTROLCMD w1,1,@RTSETSELECTION,ROffset,REnd
												  CONTROLCMD w1,1,@RTREPLACESEL,line2$
												  ColourLineZ(rHandle,textV,line2$,ROffset)

												  Undo2Count[OnTab] ++
												  Undo2[OnTab].Press[Undo2Count[OnTab]] = 7
												  Undo2[OnTab].Typed[Undo2Count[OnTab]] = Line2$ 'Changed line
												  Undo2[OnTab].Pos[Undo2Count[OnTab]] = ROffset
												  Undo2[OnTab].Offset[Undo2Count[OnTab]] = ROffset
												  Undo2[OnTab].Was[Undo2Count[OnTab]] = mid$(Line$,1,len(Line$)-2) 'Line was
												  Undo2[OnTab].LineNo[Undo2Count[OnTab]] = textV

											endif
										 next a
                               setcontroltext(w1,EDIT_11,ltrim$(str$(WasOnLine)))
                               closewindow w6
                               showwindow w1,@SWHIDE,ListView
                               starttimer w1,TimerSpeed,10000
                            endif

							  case 2
									 if @NOTIFYCODE = 0
                               closewindow w6
                            endif

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub MaskedEditHandler(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam),LRESULT
  pointer mask = GetWindowLong(hwnd, GWL_USERDATA)
  SELECT uMsg
    case WM_NCDESTROY
      delete mask
    CASE @IDCHAR
      if #<int>mask[wParam & 0xff] = FALSE
        return 0
      endif
    ENDSELECT
  RETURN CallWindowProcA(#<int>mask[256],hWnd,uMsg,wParam,lParam)
ENDSUB


SUB MaskEditControl(WINDOW parent, INT id, string szMask)
   HWND hEdit = GETCONTROLHANDLE(parent,id)
   LONG lpFn = GetWindowLong(hEdit, GWL_WNDPROC)
   pointer mask
   int i

   if lpFn <> &MaskedEditHandler
     mask = new(int, 257)
   else
     mask = GetWindowLong(hEdit, GWL_USERDATA)
   endif

   for i = 0 to 255
     #<int>mask[i] = FALSE
   next i

   for i = 0 to len(szMask)
     #<INT>mask[szMask[i]] = TRUE
   NEXT i

   IF lpFn <> &MaskedEditHandler
     #<INT>mask[256] = SetWindowLongA(hEdit,GWL_WNDPROC,&MaskedEditHandler)
     SetWindowLong(hEdit, GWL_USERDATA, mask)
   ENDIF
ENDSUB

SUB ResetScroll()
	 SENDMESSAGE(w1.hWnd,EM_GETSCROLLPOS,0,sRange,1)
    StoreLine = cLine
	 OldsRange = (sRange.Low / 16) + 30
	 Once = 0
RETURN
ENDSUB

SUB WindowDetails(INT Switch)
SwitchIn = Switch
IF Switch = 2
   STRING TheCaption = "Subroutine details - multi select option"
ENDIF

IF Switch = 4
   TheCaption = "Window details - multi select option"
ENDIF

OPENWINDOW w8,0,0,470,400,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,TheCaption,&DetailsHandler
  SETWINDOWCOLOR w8,BackColour

  CONTROL w8,@BUTTON,"",10,340,25,25,@CTLBTNBITMAP,CopySubButton
          SETCONTROLTEXT w8,CopySubButton,GETSTARTPATH() + "\\Res\\copy2.bmp"

  CONTROL w8,@BUTTON,"",40,340,25,25,@CTLBTNBITMAP,CopySubBlockButton
          SETCONTROLTEXT w8,CopySubBlockButton,GETSTARTPATH() + "\\Res\\block2.bmp"

  CONTROL w8,@BUTTON,"Close",377,340,80,25,0,2
          SETFONT w8,"Arial",10,500,0,2
          SETCONTROLCOLOR w8,2,RGB(0,0,0),RGB(255,255,255)

IF Switch = 2
  CONTROL w8,@LISTVIEW,"",10,10,446,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w8,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,0,"Subroutine"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,0,226
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,1,"Starts"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,1,100
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,2,"Ends"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,2,100
          SENDMESSAGE w8,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w8,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w8,"Arial",11,400,0,ListViewResult

          STRING text2,text4
			 INT lvcountIn = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
			 FOR a = 0 TO lvcountIn - 1
				  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text2)
				  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text4)
				  CONTROLCMD w8,ListViewResult,@LVINSERTITEM,a,text
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,1,text2
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,2,text4
          NEXT a
ENDIF

IF Switch = 4
  CONTROL w8,@LISTVIEW,"",10,10,446,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w8,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,0,"Window"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,0,226
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,1,"Starts"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,1,110
			 CONTROLCMD w8,ListViewResult,@LVINSERTCOLUMN,2,"Ends"
			 CONTROLCMD w8,ListViewResult,@LVSETCOLWIDTH,2,110
          SENDMESSAGE w8,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w8,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w8,"Arial",11,400,0,ListViewResult
          text2 = ""
          text4 = ""
			 lvcountIn = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
			 FOR a = 0 TO lvcountIn - 1
				  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text2)
				  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text4)
				  CONTROLCMD w8,ListViewResult,@LVINSERTITEM,a,text
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,1,text2
				  CONTROLCMD w8,ListViewResult,@LVSETTEXT,a,2,text4
          NEXT a
ENDIF

WAITUNTIL ISWINDOWCLOSED(w8)

RETURN
ENDSUB

SUB DetailsHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w8

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w8

           CASE @IDCONTROL
                SELECT @CONTROLID

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK
										 label ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w8,ListViewResult,@LVGETTEXT,lvpos,0,text)
										 'setcontroltext(w1,EDIT_1,text)
									 endif

							  case 2
									 if @NOTIFYCODE = 0
                               closewindow w8
                            endif

                       case CopySubButton
                            if @NOTIFYCODE = 0
                               if SwitchIn = 2
                                  int cnt2 = CopyMultiSubs(w1,ListView2)
                               endif
                               if SwitchIn = 4
                                  cnt2 = CopyMultiSubs(w1,ListView4)
                               endif
                               if cnt2
                                  if iswindowclosed(w8) = 0
                                     ShowConfirm(1)
                                  endif
                               endif
                               setfocus w8
                            endif

                       case CopySubBlockButton
                            if @NOTIFYCODE = 0
                               if SwitchIn = 2
                                  cnt2 = CopyMultiSubs(w1,ListView2,1)
                               ENDIF
                               IF SwitchIn = 4
                                  cnt2 = CopyMultiSubs(w1,ListView4,1)
                               ENDIF
                               IF cnt2
                                  IF ISWINDOWCLOSED(w8) = 0
                                     ShowConfirm(2)
                                  ENDIF
                               ENDIF
                               SETFOCUS w8
                            ENDIF

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

SUB CopyMultiSubs(WINDOW WinIn,INT id,OPT INT Bin),INT
	 lvcountIn = CONTROLCMD(w8,ListViewResult,@LVGETCOUNT)
	 INT cnt = SENDMESSAGE(w8,LVM_GETSELECTEDCOUNT,0,0,ListViewResult)
    LineCount = 0
		  IF cnt > 0
			  CutLine = ""
			  FOR x = 0 TO lvcountIn - 1
					IF CONTROLCMD(w8,ListViewResult,@LVGETSELECTED,x)
						STRING text2
						CONTROLCMD(WinIn,id,@LVGETTEXT,x,0,text)
						CONTROLCMD(WinIn,id,@LVGETTEXT,x,1,text)
						CONTROLCMD(WinIn,id,@LVGETTEXT,x,2,text2)
						INT StartOfSub = VAL(text)
						INT EndOfSub = VAL(text2)
						FOR a = StartOfSub TO EndOfSub
                      LineCount ++
							 CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
							 CutLine = CutLine + line$
						LABEL CheckNextLine
						NEXT a
						CutLine = CutLine + CHR$(13)
                  LineCount ++
					ENDIF
			  NEXT x
			  CopyStringToClipboard(CutLine)
           IF Bin
              SendToBlock()
           ENDIF
		  ENDIF

RETURN cnt
ENDSUB

SUB ShowConfirm(INT Switch)
    IF ConfirmMessage = 0 AND Switch > 0 THEN RETURN
    STRING TheCaption = ""
	 STRING TheMessage = ""
	 IF Switch = -1
       TheCaption = "Selection"
		 TheMessage = "Select code first please"
	 ENDIF
	 IF Switch = -2
       TheCaption = "Selection"
		 TheMessage = "Select a subroutine first please"
	 ENDIF
	 IF Switch = -4
       TheCaption = "Selection"
		 TheMessage = "Select a window first please"
	 ENDIF
	 IF Switch = -6
       TheCaption = "Selection"
		 TheMessage = "Select a bookmark first please"
	 ENDIF
	 IF Switch = -11
       TheCaption = "Select a line"
		 TheMessage = "Click where you want to insert code first please"
	 ENDIF
	 IF Switch = -16
       TheCaption = "Selection"
		 TheMessage = "Pick a Select first please"
	 ENDIF
	 if Switch = -40
       TheCaption = "Not allowed"
		 TheMessage = "Saving to your IWBDev include folder is not allowed"
	 endif
	 if Switch = -66
       TheCaption = "Select a line"
		 TheMessage = "Click the line you want to bookmark first please"
	 endif
	 if Switch = -100
       TheCaption = "Done"
		 TheMessage = "File has been re-indexed"
	 endif
	 if Switch = -110
       TheCaption = "Done"
		 TheMessage = "Undos and redos have been cleared"
	 endif
	 if Switch = 1
       TheCaption = "Done"
		 TheMessage = "Copied to clipboard"
	 endif
	 if Switch = 2
       TheCaption = "Done"
		 TheMessage = "Copied to block"
	 endif
	 if Switch = 6
       TheCaption = "Done"
		 TheMessage = "Line bookmarked"
	 endif
	 if Switch = 18
       TheCaption = "Done"
		 TheMessage = "Added to navigation"
	 endif
	 if Switch = 66
       TheCaption = "Already done"
		 TheMessage = "Line already bookmarked"
	 endif
	 if Switch = 99
       TheCaption = "Please wait"
		 TheMessage = "Please wait confirmation message..."
	 endif
    OPENWINDOW w10,0,0,470,200,@TOPMOST|@CAPTION,0,TheCaption,&ConfirmHandler
    Setwindowcolor w10,WindowBackColour
    CONTROL w10,@STATIC,TheMessage,0,65,470,25,@CTEDITCENTER|0x200,4
            SETCONTROLCOLOR w10,4,RGB(0,0,0),WindowBackColour
            SETFONT w10,"Arial",12,500,0,4
            if Switch < 1
               sleep(2000)
            else
               sleep(1000)
            endif
    closewindow w10
return
endsub

SUB ConfirmHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w10

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w10

    ENDSELECT
RETURN 0
ENDSUB

sub BookmarkWindow()
    OPENWINDOW w12,0,0,470,200,@TOPMOST|@CAPTION,0,"Description",&BookmarkHandler
    Setwindowcolor w12,WindowBackColour

    CONTROL w12,@STATIC,"Add a description - optional",12,40,470,25,@CTEDITLEFT|0x200,4
            SETCONTROLCOLOR w12,4,RGB(0,0,0),WindowBackColour
            SETFONT w12,"Arial",12,500,0,4

    CONTROL w12,@EDIT,"",10,70,440,25,@CTEDITLEFT,EDIT_1
            SETCONTROLCOLOR w12,EDIT_1,RGB(0,0,0),rgb(255,255,255)
            SETFONT w12,"Arial",12,500,0,EDIT_1
            setcontrolnotify(w12,EDIT_1,1,1)

    CONTROL w12,@BUTTON,"OK",10,140,80,25,0,1
            SETCONTROLCOLOR w12,1,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",10,500,0,1

    CONTROL w12,@BUTTON,"Close",377,140,80,25,0,2
            SETCONTROLCOLOR w12,2,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",10,500,0,2

    SETFOCUS w12,EDIT_1
    WAITUNTIL ISWINDOWCLOSED(w12)

RETURN
ENDSUB

SUB BookmarkHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w12

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w12

           CASE @IDCONTROL
                SELECT @CONTROLID
                       CASE EDIT_1
                            IF @NOTIFYCODE = @ENENTERKEY
                               BookMarkDesc = GETCONTROLTEXT(w12,EDIT_1)
                               CLOSEWINDOW w12
                            ENDIF

                       CASE 1
                            IF @NOTIFYCODE = 0
                               BookMarkDesc = GETCONTROLTEXT(w12,EDIT_1)
                               CLOSEWINDOW w12
                            ENDIF

                       CASE 2
                            if @NOTIFYCODE = 0
                               closewindow w12
                            endif

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub WindowDelete(int Switch)

OPENWINDOW w12,0,0,470,200,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Please confirm",&DeleteHandler

if Switch = 6
    Setwindowcolor w12,WindowBackColour
ENDIF

  UINT Theme = 0
  IF !CloseDown
     Theme = ScreenColour
  ELSE
     Theme = BackColour
  ENDIF

IF Switch <> 6
  SETWINDOWCOLOR w12,Theme
ENDIF

  CONTROL w12,@STATIC,"",0,25,470,25,@CTEDITCENTER|0x200,1
          SETFONT w12,"Arial",12,500,0,1
          IF Switch <> 6
             SETCONTROLCOLOR w12,1,RGB(0,0,0),Theme
          ELSE
             SETCONTROLCOLOR w12,1,RGB(0,0,0),WindowBackColour
          ENDIF

  CONTROL w12,@STATIC,"",0,60,470,25,@CTEDITCENTER|0x200,2
          SETFONT w12,"Arial",12,500,0,2
          IF Switch <> 6
             SETCONTROLCOLOR w12,2,RGB(0,0,0),Theme
          ELSE
             SETCONTROLCOLOR w12,2,RGB(0,0,0),WindowBackColour
          ENDIF

          IF CloseDown
			    SETCONTROLTEXT(w12,1,"Do you want to save the changes for")
			    SETCONTROLTEXT(w12,2,RealTabName)
		    ENDIF

		    IF Switch = 2
			    SETCONTROLTEXT(w12,1,"Are you sure you want to delete the subroutine")
			    SETCONTROLTEXT(w12,2,GETSTRING(w1,Combo2,GETSELECTED(w1,Combo2)) + "?")
		    ENDIF

		    IF Switch = 4
			    SETCONTROLTEXT(w12,1,"Are you sure you want to delete the window")
			    SETCONTROLTEXT(w12,2,GETSTRING(w1,Combo4,GETSELECTED(w1,Combo4)) + "?")
		    ENDIF

		    IF Switch = 6
			    SETCONTROLTEXT(w12,2,"Are you sure you want to clear undos and redos?")
		    ENDIF

  CONTROL w12,@BUTTON,"Yes",140,110,80,25,0,4
          SETFONT w12,"Arial",12,500,0,4
          IF Switch <> 6
             SETCONTROLCOLOR w12,4,RGB(0,0,0),Theme
          ELSE
             SETCONTROLCOLOR w12,4,RGB(0,0,0),WindowBackColour
          ENDIF

  CONTROL w12,@BUTTON,"No",240,110,80,25,0,8
          SETFONT w12,"Arial",12,500,0,8
          if Switch <> 6
             SETCONTROLCOLOR w12,8,RGB(0,0,0),Theme
          else
             SETCONTROLCOLOR w12,8,RGB(0,0,0),WindowBackColour
          endif

			 if CloseDown > 0
			    setfocus w12,4
			 else
			    setfocus w12,8
			 endif

WAITUNTIL IsWindowClosed(w12)

return
endsub

SUB DeleteHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w12

           CASE @IDCLOSEWINDOW
                DelConfirm = 0
                CLOSEWINDOW w12

	        case @IDKEYDOWN
		          if @CODE = 37
                   setfocus w12,4
                endif
		          if @CODE = 39
                   setfocus w12,8
                endif

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case 4 'Yes
                            if @NOTIFYCODE = 0
                               DelConfirm = 1
                               closewindow w12
                            endif

                       case 8 'No
                            if @NOTIFYCODE = 0
                               DelConfirm = 0
                               closewindow w12
                            endif

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

sub WindowBookmarks()
OPENWINDOW w14,0,0,525,400,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Bookmarks full list & descriptions",&BookmarksHandler
  Setwindowcolor w14,BackColour

  CONTROL w14,@BUTTON,"Close",430,340,80,25,0,2
          SETFONT w14,"Arial",10,500,0,2
          SETCONTROLCOLOR w14,2,RGB(0,0,0),RGB(255,255,255)

  CONTROL w14,@LISTVIEW,"",10,10,500,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w14,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w14,ListViewResult,@LVINSERTCOLUMN,0,"Line"
			 CONTROLCMD w14,ListViewResult,@LVSETCOLWIDTH,0,100
			 CONTROLCMD w14,ListViewResult,@LVINSERTCOLUMN,1,"Description"
			 CONTROLCMD w14,ListViewResult,@LVSETCOLWIDTH,1,400
          SENDMESSAGE w14,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w14,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w14,"Arial",11,400,0,ListViewResult

          STRING text2
			 INT lvcountIn = CONTROLCMD(w1,ListView6,@LVGETCOUNT)
			 FOR a = 0 TO lvcountIn - 1
				  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView6,@LVGETTEXT,a,1,text2)
				  CONTROLCMD w14,ListViewResult,@LVINSERTITEM,a,text
				  CONTROLCMD w14,ListViewResult,@LVSETTEXT,a,1,text2
          NEXT a

WAITUNTIL ISWINDOWCLOSED(w14)

RETURN
ENDSUB

SUB BookmarksHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w14

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w14

           CASE @IDCONTROL
                SELECT @CONTROLID

							  case ListViewResult
									 if @NOTIFYCODE=@NMCLICK
										 label ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w14,ListViewResult,@LVGETTEXT,lvpos,0,text)
                               if text <> ""
										    setcontroltext(w1,EDIT_1,text)
                               endif
									 ENDIF

							  CASE 2
									 IF @NOTIFYCODE = 0
                               CLOSEWINDOW w14
                            ENDIF

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

SUB WindowCases()

IF GETSELECTED(w1,Combo8) = -1
   ShowConfirm(-16)
   SETFOCUS w1,Combo16
   RETURN
ENDIF

STRING SelectName = GETSTRING(w1,Combo8,GETSELECTED(w1,Combo8))
SelectName = MID$(SelectName,1,INSTR(SelectName,"-")-1)
OPENWINDOW w14,0,0,525,400,@MINBOX|@MAXBOX|@TOPMOST|@CAPTION,0,"Cases for SELECT " + SelectName,&CasesHandler
  SETWINDOWCOLOR w14,BackColour

  CONTROL w14,@BUTTON,"Close",430,340,80,25,0,2
          SETFONT w14,"Arial",10,500,0,2
          SETCONTROLCOLOR w14,2,RGB(0,0,0),RGB(255,255,255)

  CONTROL w14,@LISTVIEW,"",10,10,500,320,@BORDER|@LVSSHOWSELALWAYS|@LVSREPORT|@LVSALIGNTOP|@VSCROLL,ListViewResult
			 SENDMESSAGE w14,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListViewResult
			 CONTROLCMD w14,ListViewResult,@LVINSERTCOLUMN,0,"Name"
			 CONTROLCMD w14,ListViewResult,@LVSETCOLWIDTH,0,400
			 CONTROLCMD w14,ListViewResult,@LVINSERTCOLUMN,1,"Line"
			 CONTROLCMD w14,ListViewResult,@LVSETCOLWIDTH,1,100
          SENDMESSAGE w14,LVM_SETBKCOLOR,0,ScreenColour,ListViewResult
          SENDMESSAGE w14,LVM_SETTEXTBKCOLOR,0,ScreenColour,ListViewResult
          SETFONT w14,"Arial",11,400,0,ListViewResult

          STRING text2
			 INT lvcountIn = CONTROLCMD(w1,ListView10,@LVGETCOUNT)
			 FOR a = 0 TO lvcountIn - 1
				  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,0,text)
				  CONTROLCMD(w1,ListView10,@LVGETTEXT,a,1,text2)
				  CONTROLCMD w14,ListViewResult,@LVINSERTITEM,a,text
				  CONTROLCMD w14,ListViewResult,@LVSETTEXT,a,1,text2
          NEXT a

WAITUNTIL ISWINDOWCLOSED(w14)

RETURN
ENDSUB

SUB CasesHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w14

           CASE @IDCLOSEWINDOW
                CLOSEWINDOW w14

           CASE @IDCONTROL
                SELECT @CONTROLID

							  CASE ListViewResult
									 IF @NOTIFYCODE=@NMCLICK
										 LABEL ClickListViewResult
										 lvpos=*<NMLISTVIEW>@LPARAM.iItem
										 CONTROLCMD(w14,ListViewResult,@LVGETTEXT,lvpos,1,text)
										 SETCONTROLTEXT(w1,EDIT_1,text)
									 ENDIF

							  CASE 2
									 IF @NOTIFYCODE = 0
                               CLOSEWINDOW w14
                            ENDIF

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

SUB AddToCombo16()
	 INT lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 FOR a = 0 TO lvcountIn - 1
		  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,3,text)
		  INT combocountIn = GETSTRINGCOUNT(w1,Combo16)
		  INT alreadyadded = 0
		  FOR b = 0 TO combocountin - 1
				IF GETSTRING(w1,Combo16,b) = text
					alreadyadded = 1
					BREAKFOR
				ENDIF
		  NEXT b
		  IF alreadyadded = 0
			  ADDSTRING w1,Combo16,text
		  ENDIF
	 NEXT a
RETURN
ENDSUB


sub JumpLineUser(int EditIn,opt int Bin)
	 FocusMain()
	 if Bin
		 int bm = val(getstring(w1,Combo6,getselected(w1,Combo6)))
		 sRange.Low = (bm * 16) - 16
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
		 setscrollpos(w1,16,bm)
	 else
		 sRange.Low = ((val(getcontroltext w1,EditIn)) * 16) '- 16
		 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
		 setscrollpos(w1,16,val(getcontroltext w1,EditIn))
	 endif

	 StartAt = CONTROLCMD(w1,1,@RTCHARFROMLINE,sRange)
	 setfocus w1,1
	 CONTROLCMD w1,1,@RTSETSELECTION,StartAt,StartAt
	 ppos = GETCARETPOSITION w1,AcrossX,DownY
	 lvX = AcrossX
	 lvY = DownY
	 if kw = 0
		 setsize w1,lvX+58,lvY+98,300,38,ListView
	 endif
	 AcrossX --
	 AcrossX = AcrossX / 8
	 AcrossX ++
	 EditPos = CONTROLCMD(w1,1,@RTCHARFROMLINE,cLine-1)
	 EditPos = EditPos + AcrossX
	 ColourText()

	 StoreLine = val(getcontroltext w1,EditIn)
	 setscrollpos(w1,16,StoreLine)
	 'cLine = val(text)
	 sRange.Low = (getscrollpos(w1,16) * 16) - 16
	 SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
	 FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0) + 1

	 for a = 1 to 30
		  setcontroltext(w1,a+1000,str$(FirstVisLine+(a-1)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 NEXT a

	 IF GETCONTROLTEXT(w1,EditIn) = ""
		 FOR a = 1 TO 30
			  SETCONTROLTEXT(w1,a+1000,STR$(a))
		 NEXT a
	 ENDIF

	 IF !Bin
		 SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
		 SETCONTROLCOLOR w1,1001,Red,BackColour
		 SETFOCUS w1,EditIn
	 ENDIF
RETURN
ENDSUB

SUB StartUp()
	 WordCount = 0
	 y = 0
    x = GetLines()
PRINT "Load 2"
	 SETSCROLLRANGE w1,16,0,x
	 SETSCROLLPOS w1, -2, 0

    'Load controls
    SETCONTROLTEXT w1,1,ClipText 'Load file into the rich edit
    IF INSTR(GETCONTROLTEXT(w1,1001),">") = 0
       SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
    ENDIF
    GetFileName(w1,0,ProgPath,1)
    SETCAPTION w1,FileNameIs
    FileNameIs = getcaption(w1)
    SETCONTROLCOLOR w1,1001,Red,BackColour
    setcontroltext(w1,EDIT_1,ltrim$(str$(StartUpAt)))
	 setcaption w1,FileNameIs
    setfocus w1,1

	 ConDrawOff(w1,ListView2)
	 ConDrawOff(w1,Combo2)
    DoGetSubRoutines(w1,ListView2,"SUB") 'Load sub routine details
    int lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
    if lvcount2 > 0
       StoreSubs()
       PopulateSubRoutines()
    endif
    ConDrawOn(w1,ListView2)
    ConDrawOn(w1,Combo2)

    ConDrawOff(w1,ListView4)
    ConDrawOff(w1,Combo4)
    DoGetWindows(w1,ListView4,"OPENWINDOW") 'Load window details
    lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
    IF lvcount2 > 0
       PopulateWindows()
    ENDIF
    ConDrawOn(w1,ListView4)
    ConDrawOn(w1,Combo4)

    'DoGetIncludes(w1,Combo20,"$INCLUDE") 'Load include details
    DoGetSelect(w1,ListView8,"SELECT",ListView2,Combo8) 'Load select details
    lvcount2 = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
    ConDrawOff(w1,Combo16)
    IF lvcount2 > 0
       AddToCombo16()
    ENDIF
    ConDrawOn(w1,Combo16)
    StoreLine = cLine
    Skip = 1
    CreateDetailsFile()
RETURN
ENDSUB

SUB ClearEditor()

    SETCONTROLTEXT(w1,1,"")

	 FOR a = 1 TO 30
        SETCONTROLTEXT(w1,a+1000,"")
	 NEXT a

    SETSCROLLPOS(w1,16,0)

    SETCAPTION w1,""

    CONTROLCMD(w1,ListView2,@LVDELETEALL)
    CONTROLCMD(w1,ListView4,@LVDELETEALL)
    CONTROLCMD(w1,ListView6,@LVDELETEALL)
    CONTROLCMD(w1,ListView8,@LVDELETEALL)
    CONTROLCMD(w1,ListView10,@LVDELETEALL)

    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo6),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo8),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo10),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo12),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo14),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo16),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo18),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo20),CB_RESETCONTENT,0,0)

return
endsub

sub DoMinimise(opt int Switch)
	 string CloseLine = ltrim$(getcontroltext(w1,1001))
	 if instr(CloseLine,">")
		 CloseLine = mid$(CloseLine,instr(CloseLine,">")+3,len(CloseLine))
	 endif
    if Switch = 1 then ProgPath = RecentProgs[1]
    if Switch = 2 then ProgPath = RecentProgs[2]
    if Switch = 3 then ProgPath = RecentProgs[3]
    if Switch = 4 then ProgPath = RecentProgs[4]
    if Switch = 5 then ProgPath = RecentProgs[5]
    if Switch = 6 then ProgPath = RecentProgs[6]
    GetFileName(w1,0,ProgPath,1)
    CreateDetailsFile()
	 ClearEditor()
    if !Switch
	    DoSaveToTab()
    endif
	 ClearEditor()
return
endsub

sub DoRestore(int Switch,opt int TabName)
Loading = 1
    if Switch = 1 then goto LoadFromFile
    if InitialLoad = 1
       setcontroltext(w1,1,buffer1)
       goto LoadFromFile
    endif
    if TabName = 1
       setcontroltext(w1,1,buffer1)
    endif
    if TabName = 2
       setcontroltext(w1,1,buffer2)
    endif
    IF TabName = 3
       SETCONTROLTEXT(w1,1,buffer3)
    ENDIF
    IF TabName = 4
       SETCONTROLTEXT(w1,1,buffer4)
    ENDIF
    IF TabName = 5
       SETCONTROLTEXT(w1,1,buffer5)
    ENDIF
    IF TabName = 6
       SETCONTROLTEXT(w1,1,buffer6)
    ENDIF

    LABEL LoadFromFile
	 STRING MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
	 STRING StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 IF OPENFILE(MyFile2,StoreBookFileD,"R") = 0
		 READ MyFile2,dIn
	 ENDIF
	 CLOSEFILE MyFile2
	 ProgPath = dIn

	 GetFileName(w1,0,ProgPath,1)
	 SETCAPTION w1,FileNameIs

	 MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
	 StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
    INT AddBackIn = 0
    INT LineRead = 0
    STRING text2,text3,text4
	 IF OPENFILE(MyFile2,StoreBookFileD,"R") = 0
       DO
          read Myfile2,dIn

             'Get Sub routines
				 if instr(dIn,":lv2")
					 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
             endif

             if AddBackIn = 0
                break
             endif

             if AddBackIn > 0
					  LineRead ++
					  read MyFile,dIn
					  text  = mid$(dIn,1,instr(dIn,"|")-1)
					  text2 = mid$(dIn,instr(dIn,"|")+1,len(dIn))
					  text2 = mid$(text2,1,instr(text2,"!")-1)
					  text3 = mid$(dIn,instr(dIn,"!")+1,len(dIn))

                 ConDrawOff(w1,ListView2)
                 ConDrawOff(w1,Combo2)
					  if !instr(text,":")
						  CONTROLCMD w1,ListView2,@LVINSERTITEM,a,text
						  int position = CONTROLCMD(w1,ListView2,@LVFINDITEM,text)
						  CONTROLCMD w1,ListView2,@LVSETTEXT,position,1,text2
						  CONTROLCMD w1,ListView2,@LVSETTEXT,position,2,text3
						  ADDSTRING w1,Combo2,text
					  endif
                 ConDrawOn(w1,ListView2)
                 ConDrawOn(w1,Combo2)
             endif

       until LineRead > AddBackIn or EOF(MyFile2)

       'Get Windows
       if !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
			 do
				 read Myfile2,dIn
					 if instr(dIn,":lv4")
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						  LineRead ++
						  read MyFile,dIn
						  text  = mid$(dIn,1,instr(dIn,"|")-1)
						  text2 = mid$(dIn,instr(dIn,"|")+1,len(dIn))
						  text2 = mid$(text2,1,instr(text2,"!")-1)
						  text3 = mid$(dIn,instr(dIn,"!")+1,len(dIn))
						  text3 = mid$(text3,1,instr(text3,"#")-1)
						  text4 = mid$(dIn,instr(dIn,"#")+1,len(dIn))
                    ConDrawOff(w1,ListView4)
                    ConDrawOff(w1,Combo4)
						  if !instr(text,":")
							  CONTROLCMD w1,ListView4,@LVINSERTITEM,a,text
							  position = CONTROLCMD(w1,ListView4,@LVFINDITEM,text)
							  CONTROLCMD w1,ListView4,@LVSETTEXT,position,1,text2
							  CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,text3
							  CONTROLCMD w1,ListView4,@LVSETTEXT,position,3,text4
							  ADDSTRING w1,Combo4,text
						  endif
                    ConDrawOn(w1,ListView4)
                    ConDrawOn(w1,Combo4)
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
       endif

       'Get Selects
       if !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
          string LastEntry = ""
			 do
				 read Myfile2,dIn
					 if instr(dIn,":lv8")
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                IF AddBackIn = 0
                   BREAK
                ENDIF

					 IF AddBackIn > 0
						  LineRead ++
						  READ MyFile,dIn
						  text  = MID$(dIn,1,INSTR(dIn,"|")-1)
						  text2 = MID$(dIn,INSTR(dIn,"|")+1,LEN(dIn))
						  text2 = MID$(text2,1,INSTR(text2,"!")-1)
						  text3 = MID$(dIn,INSTR(dIn,"!")+1,LEN(dIn))
						  text3 = MID$(text3,1,INSTR(text3,"#")-1)
						  text4 = MID$(dIn,INSTR(dIn,"#")+1,LEN(dIn))
                    ConDrawOff(w1,ListView8)
                    ConDrawOff(w1,Combo8)
						  IF !instr(text,":")
							  CONTROLCMD w1,ListView8,@LVINSERTITEM,a,text
							  position = CONTROLCMD(w1,ListView8,@LVFINDITEM,text)
							  CONTROLCMD w1,ListView8,@LVSETTEXT,position,1,text2
							  CONTROLCMD w1,ListView8,@LVSETTEXT,position,2,text3
							  CONTROLCMD w1,ListView8,@LVSETTEXT,position,3,text4
						  ENDIF
                    ConDrawOn(w1,ListView8)
                    ConDrawOn(w1,Combo8)
					 ENDIF
			 UNTIL LineRead > AddBackIn OR EOF(MyFile2)
          AddToCombo16()
       ENDIF

       'Get Bookmarks
       IF !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
			 DO
				 READ Myfile2,dIn
					 IF INSTR(dIn,":bmk")
						 AddBackIn = VAL(MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn)))
					 ENDIF

                IF AddBackIn = 0
                   BREAK
                ENDIF

					 IF AddBackIn > 0
						  LineRead ++
						  READ MyFile,dIn
                    ConDrawOff(w1,ListView6)
					     IF !instr(dIn,":")
                       ADDSTRING w1,Combo6,dIn
                       IF INSTR(dIn," ")
                          STRING StringLineNo = MID$(dIn,1,INSTR(dIn," ")-1)
                          STRING BookMarkDesc = MID$(dIn,INSTR(dIn," ")+1,LEN(dIn))
                       ELSE
                          StringLineNo = dIn
                          BookMarkDesc = ""
                       endif
					        CONTROLCMD w1,ListView6,@LVINSERTITEM,LineRead-1,StringLineNo
							  position = CONTROLCMD(w1,ListView6,@LVFINDITEM,StringLineNo)
							  CONTROLCMD w1,ListView6,@LVSETTEXT,position,1,BookMarkDesc
                    endif
                    ConDrawOn(w1,ListView6)
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
          if AddBackIn > 2
             SortBookMarks()
          endif
       endif

       'Get Includes
       if !EOF(MyFile2)
			 AddBackIn = 0
			 LineRead = 0
          ConDrawOff(w1,Combo20)
			 do
				 read Myfile2,dIn
					 if instr(dIn,":inc")
						 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
					 endif

                if AddBackIn = 0
                   break
                endif

					 if AddBackIn > 0
						  LineRead ++
						  read MyFile,dIn
					     if !instr(dIn,":")
                       ADDSTRING w1,Combo20,dIn
                    endif
					 endif
			 until LineRead > AddBackIn or EOF(MyFile2)
          ConDrawOff(w1,Combo20)
       endif

       'Get scroll range
       int scMin,scMax
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":sr")
				 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
				 read MyFile,dIn
				 scMin = AddBackIn
				 scMax = val(mid$(dIn,instr(dIn,"!")+1,len(dIn)))
             if scMax = 0
                scMax = CONTROLCMD(w1,1,@RTGETLINECOUNT)
                setscrollrange(w1,16,scMin,scMax)
             else
                setscrollrange(w1,16,scMin,scMax)
             endif
			 endif
       endif

       'User go to lines
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":u1")
				 STRING AddBackInS = MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn))
				 READ MyFile,dIn
             IF AddBackInS <> "0"
                SETCONTROLTEXT(w1,EDIT_11,LTRIM$(AddBackInS))
                SHOWWINDOW w1,@SWSHOW,BUTTON_4
             ELSE
                SETCONTROLTEXT(w1,EDIT_11,"")
             ENDIF
			 ENDIF
       ENDIF

       IF !EOF(MyFile2)
          READ Myfile2,dIn
			 IF INSTR(dIn,":u2")
				 AddBackInS = MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn))
				 READ MyFile,dIn
             IF AddBackInS <> "0"
                SETCONTROLTEXT(w1,EDIT_111,LTRIM$(AddBackInS))
                SHOWWINDOW w1,@SWSHOW,BUTTON_44
             ELSE
                SETCONTROLTEXT(w1,EDIT_111,"")
             ENDIF
			 ENDIF
       ENDIF

       'Sub routines selections etc
       IF !EOF(MyFile2)
          READ Myfile2,dIn
			 IF INSTR(dIn,":c2")
				 AddBackInS = MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn))
				 READ MyFile,dIn
             IF AddBackInS <> "!"
                setselected(w1,Combo2,val(AddBackInS))
             else
                setselected(w1,Combo2,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c4")
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn
             if AddBackInS <> "!"
                setselected(w1,Combo4,val(AddBackInS))
             else
                setselected(w1,Combo4,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c6")
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn
             if AddBackInS <> "!"
                setselected(w1,Combo6,val(AddBackInS))
             else
                setselected(w1,Combo6,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c8")
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn
             if AddBackInS <> "!"
                setselected(w1,Combo8,val(AddBackInS))
             else
                setselected(w1,Combo8,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":c10")
				 AddBackInS = mid$(dIn,instr(dIn,"-")+1,len(dIn))
				 read MyFile,dIn
             if AddBackInS <> "!"
                setselected(w1,Combo10,val(AddBackInS))
             else
                setselected(w1,Combo10,-1)
             endif
			 endif
       endif

       if !EOF(MyFile2)
          read Myfile2,dIn
			 IF INSTR(dIn,":c12")
				 AddBackInS = MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn))
				 READ MyFile,dIn
             IF AddBackInS <> "!"
                SETSELECTED(w1,Combo12,VAL(AddBackInS))
             ELSE
                SETSELECTED(w1,Combo12,-1)
             ENDIF
			 ENDIF
       ENDIF

       IF !EOF(MyFile2)
          READ Myfile2,dIn
			 IF INSTR(dIn,":c14")
				 AddBackInS = MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn))
				 READ MyFile,dIn
             IF AddBackInS <> "!"
                SETSELECTED(w1,Combo14,VAL(AddBackInS))
             ELSE
                SETSELECTED(w1,Combo14,-1)
             ENDIF
			 ENDIF
       ENDIF

       IF !EOF(MyFile2)
          READ Myfile2,dIn
			 IF INSTR(dIn,":c16")
             SETCONTROLTEXT(w1,CaseStatic,"Cases")
				 AddBackInS = MID$(dIn,INSTR(dIn,"-")+1,LEN(dIn))
				 READ MyFile,dIn
             IF AddBackInS <> "!"
                SETSELECTED(w1,Combo16,VAL(AddBackInS))
                DoSelect16()
                DoCombo8()
             else
                setselected(w1,Combo16,-1)
             endif
			 endif
       endif

       'Get scroll position
       int scPos
       if !EOF(MyFile2)
          read Myfile2,dIn
			 if instr(dIn,":sp")
				 AddBackIn = val(mid$(dIn,instr(dIn,"-")+1,len(dIn)))
				 READ MyFile,dIn
				 scPos = AddBackIn
             SETCONTROLTEXT(w1,EDIT_1,LTRIM$(STR$(scPos)))
             cLine = scPos
             StoreLine = cLine
             ScrollPoint = cLine
          ELSE
             SETCONTROLTEXT(w1,EDIT_1,"1")
             cLine = 1
             StoreLine = cLine
             ScrollPoint = 1
			 ENDIF
       ENDIF

    ENDIF
    CLOSEFILE MyFile2

	 'Load text and controls
	 IF INSTR(GETCONTROLTEXT(w1,1001),">") = 0
		 SETCONTROLTEXT(w1,1001,"> " + GETCONTROLTEXT(w1,1001))
	 ENDIF
	 GetFileName(w1,0,ProgPath,1)
	 SETCAPTION w1,FileNameIs
	 SETCONTROLCOLOR w1,1001,Red,BackColour
	 SETCAPTION w1,FileNameIs
    SETFOCUS w1,1
	 StoreLine = cLine
	 Skip = 1
    Mod = 0
Loading = 0
RETURN
ENDSUB

SUB FileOpenedBefore(),INT
    GetFileName(w1,0,ProgPath,1)
    INT OpenedBefore = 0
	 STRING MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
	 STRING StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
    INT AddBackIn = 0
    INT LineRead = 0
	 IF OPENFILE(MyFile2,StoreBookFileD,"R") = 0
       CLOSEFILE MyFile2
       OpenedBefore = 1
    ENDIF

RETURN OpenedBefore
ENDSUB

SUB RecentFiles()
    ProgCount = 0
	 IF OPENFILE(MyFile2,GETSTARTPATH + "\\Res\\"+ "xeditor4.ini","R") = 0
       DO
           READ MyFile2,dIn
           IF dIn <> ""
              ProgCount ++
              RecentProgs[ProgCount] = dIn
           ENDIF
       UNTIL EOF(MyFile2)
    ENDIF
    CLOSEFILE MyFile2

    'setcaption w1,RecentProgs[1]

    STRING StoreFileName = FileNameIs
    STRING StoreProgPath = ProgPath
    IF ProgCount > 0
       IF RecentProgs[1] <> ""
          ProgPath = RecentProgs[1]
          GetFileName(w1,0,ProgPath,1)
          RecentName[1] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             SHOWWINDOW w1,@SWSHOW,FileTab1
             SETCONTROLTEXT(w1,FileTab1,FileNameIs)
PRINT "Load 3"
		       x = GetLines(1)
             buffer1 = ClipText
          'endif
       ENDIF
       IF RecentProgs[2] <> ""
          ProgPath = RecentProgs[2]
          GetFileName(w1,0,ProgPath,1)
          RecentName[2] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             SHOWWINDOW w1,@SWSHOW,FileTab2
             SETCONTROLTEXT(w1,FileTab2,FileNameIs)
PRINT "Load 4"
		       x = GetLines(1)
             buffer2 = ClipText
          'endif
       ENDIF
       IF RecentProgs[3] <> ""
          ProgPath = RecentProgs[3]
          GetFileName(w1,0,ProgPath,1)
          RecentName[3] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             SHOWWINDOW w1,@SWSHOW,FileTab3
             SETCONTROLTEXT(w1,FileTab3,FileNameIs)
		       x = GetLines(1)
PRINT "Load 5"
             buffer3 = ClipText
          'endif
       ENDIF
       if RecentProgs[4] <> ""
          ProgPath = RecentProgs[4]
          GetFileName(w1,0,ProgPath,1)
          RecentName[4] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             showwindow w1,@SWSHOW,FileTab4
             setcontroltext(w1,FileTab4,FileNameIs)
		       x = GetLines(1)
print "Load 6"
             buffer4 = ClipText
          'endif
       endif
       if RecentProgs[5] <> ""
          ProgPath = RecentProgs[5]
          GetFileName(w1,0,ProgPath,1)
          RecentName[5] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             SHOWWINDOW w1,@SWSHOW,FileTab5
             SETCONTROLTEXT(w1,FileTab5,FileNameIs)
		       x = GetLines(1)
PRINT "Load 7"
             buffer5 = ClipText
          'endif
       ENDIF
       IF RecentProgs[6] <> ""
          ProgPath = RecentProgs[6]
          GetFileName(w1,0,ProgPath,1)
          RecentName[6] = FileNameIs
          'if !instr(getcaption(w1),getcontroltext(w1,FileTab1)) and !instr(getcaption(w1),getcontroltext(w1,FileTab2)) and !instr(getcaption(w1),getcontroltext(w1,FileTab3)) and !instr(getcaption(w1),getcontroltext(w1,FileTab4))
             SHOWWINDOW w1,@SWSHOW,FileTab6
             SETCONTROLTEXT(w1,FileTab6,FileNameIs)
		       x = GetLines(1)
PRINT "Load 8"
             buffer6 = ClipText
          'endif
       ENDIF
    ENDIF

    ProgPath = StoreProgPath
    FileNameIs = StoreFileName
    TabTaken = ProgCount

RETURN
ENDSUB

SUB BackupWindow()
    Confirm = 0
    STRING TimeString = MID$(TIME$,1,2)
    TimeString = Timestring + "-" + MID$(TIME$,4,2)
    BackupDesc = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1) + "-" + DATE$ + "-at-" + TimeString + MID$(FileNameIs,INSTR(FileNameIs,"."),LEN(FileNameIs))
    OPENWINDOW w12,0,0,470,200,@TOPMOST|@CAPTION,0,"Backup file name",&BackupHandler
    SETWINDOWCOLOR w12,WindowBackColour

    CONTROL w12,@STATIC,"Backup file name",12,40,470,25,@CTEDITLEFT|0x200,4
            SETCONTROLCOLOR w12,4,RGB(0,0,0),WindowBackColour
            SETFONT w12,"Arial",12,500,0,4

    CONTROL w12,@EDIT,"",10,70,440,25,@CTEDITLEFT,EDIT_1
            SETCONTROLCOLOR w12,EDIT_1,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",12,500,0,EDIT_1
            SETCONTROLNOTIFY(w12,EDIT_1,1,1)
            SETCONTROLTEXT(w12,EDIT_1,BackupDesc)

    CONTROL w12,@BUTTON,"Save",10,140,80,25,0,1
            SETCONTROLCOLOR w12,1,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",10,500,0,1

    CONTROL w12,@BUTTON,"Cancel",377,140,80,25,0,2
            SETCONTROLCOLOR w12,2,RGB(0,0,0),RGB(255,255,255)
            SETFONT w12,"Arial",10,500,0,2

    setfocus w12,EDIT_1
    WAITUNTIL IsWindowClosed(w12)

return
endsub

SUB BackupHandler(),INT
	 SELECT @MESSAGE
           CASE @IDCREATE
                CENTERWINDOW w12

           CASE @IDCLOSEWINDOW
                Confirm = 0
                CLOSEWINDOW w12

           CASE @IDCONTROL
                SELECT @CONTROLID
                       case EDIT_1
                            if @NOTIFYCODE = @ENENTERKEY
                               if rtrim$(ltrim$(getcontroltext(w12,EDIT_1))) <> ""
											 Confirm = 1
											 BackupDesc = getcontroltext(w12,EDIT_1)
											 closewindow w12
                               else
                                  setfocus w12,EDIT_1
                               endif
                            endif

                       case 1
                            if @NOTIFYCODE = 0
                               if rtrim$(ltrim$(getcontroltext(w12,EDIT_1))) <> ""
											 Confirm = 1
											 BackupDesc = getcontroltext(w12,EDIT_1)
											 closewindow w12
                               else
                                  setfocus w12,EDIT_1
                               ENDIF
                            ENDIF

                       CASE 2
                            IF @NOTIFYCODE = 0
                               Confirm = 0
                               CLOSEWINDOW w12
                            ENDIF

                ENDSELECT
    ENDSELECT
RETURN 0
ENDSUB

SUB DoSelect16()
	 SENDMESSAGE(GetDlgItem(w1.hwnd,Combo8),CB_RESETCONTENT,0,0)
	 INT SelectThis = 0
	 INT AddStringCount = -1
	 lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 FOR a = 0 TO lvcountIn - 1
		  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,3,text)
		  IF text = GETSTRING(w1,Combo16,GETSELECTED(w1,Combo16))
			  STRING text2
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text2)
			  ADDSTRING(w1,Combo8,text2 + " - " + LTRIM$(STR$(a)))
			  AddStringCount ++
			  IF UCASE$(text2) = DefaultSelect AND SelectThis = 0
				  SelectThis = AddStringCount
			  ENDIF
		  ENDIF
	 NEXT a

	 SETSELECTED w1,Combo8,SelectThis

	 SETCONTROLTEXT(w1,EDIT_4,"")
	 SETSELECTED(w1,Combo14,-1)
	 STRING SelectedSelect = GETSTRING(w1,Combo8,GETSELECTED(w1,Combo8))
	 STRING Combo14String = SelectedSelect
	 INT Combo14Select = INSTR(Combo14String,"-") + 2
	 STRING Combo10Pos$ = MID$(Combo14String,Combo14Select,LEN(Combo14String))
	 INT GetThis = VAL(Combo10Pos$)
	 lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 IF lvcountIn > 0
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,0,TextInName)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,1,TextIn1)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,2,TextIn2)
		 SETSELECTED(w1,Combo10,-1)
		 Combo10Add()
	 ENDIF
	 SETFOCUS w1
RETURN
ENDSUB

SUB DoCombo8()
	 SETCONTROLTEXT(w1,EDIT_4,"")
	 setselected(w1,Combo14,-1)
	 string SelectedSelect = getstring(w1,Combo8,getselected(w1,Combo8))
	 string Combo14String = SelectedSelect
	 int Combo14Select = instr(Combo14String,"-") + 2
	 string Combo10Pos$ = mid$(Combo14String,Combo14Select,len(Combo14String))
	 int GetThis = val(Combo10Pos$)
	 int lvcountIn = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
	 if lvcountIn > 0
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,0,TextInName)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,1,TextIn1)
		 CONTROLCMD(w1,ListView8,@LVGETTEXT,GetThis,2,TextIn2)
	 'endif
	 setselected(w1,Combo10,-1)
	 Combo10Add()
	 setselected(w1,Combo10,0)
	 ENDIF
	 SETFOCUS w1
RETURN
ENDSUB

SUB LoadTab(INT Switch)
ENABLECONTROL (w1,FileTab1,0)
ENABLECONTROL (w1,FileTab2,0)
ENABLECONTROL (w1,FileTab3,0)
ENABLECONTROL (w1,FileTab4,0)
ENABLECONTROL (w1,FileTab5,0)
ENABLECONTROL (w1,FileTab6,0)

ResetScroll()

IF cLine = 0
   cLine = 1
   StoreLine = 1
ENDIF

    IF Switch = 1
		 IF GETCONTROLTEXT(w1,FileTab1) <> ""
			 OnTab = 1
			 IF !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab1))
				 STOPTIMER w1,10000
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab2))
					 buffer2 = ""
					 buffer2 = GETCONTROLTEXT(w1,1)
					 DoMinimise(2)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3))
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,1)
					 DoMinimise(3)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab4))
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,1)
					 DoMinimise(4)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab5))
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,1)
					 DoMinimise(5)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab6))
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,1)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab1)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab1Loaded = 0
					 ProgPath = RecentProgs[1]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab1,FileNameIs)
					 DoOpen(1)
					 Tab1Loaded = 1
					 setcontroltext(w1,FileTab3,FileNameIs)
                buffer1 = ""
                buffer1 = getcontroltext(w1,1)
                OnTab = 1
				 else
                OnTab = 1
                Tab1Loaded = 1
					 DoRestore(0,1)
				 endif
			 endif
		 endif
    endif
    if Switch = 2
		 if getcontroltext(w1,FileTab2) <> ""
			 OnTab = 2
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab2))
				 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,1)
					 DoMinimise(1)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab3))
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,1)
					 DoMinimise(3)
				 endif
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab4))
					 buffer4 = ""
					 buffer4 = GETCONTROLTEXT(w1,1)
					 DoMinimise(4)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab5))
					 buffer5 = ""
					 buffer5 = GETCONTROLTEXT(w1,1)
					 DoMinimise(5)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab6))
					 buffer6 = ""
					 buffer6 = GETCONTROLTEXT(w1,1)
					 DoMinimise(6)
				 ENDIF
				 FileNameIs = GETCONTROLTEXT(w1,FileTab2)
             IF INSTR(FileNameIs,"*")
                FileNameIs = MID$(FileNameIs,1,INSTR(FileNameIs,"*")-1)
             ENDIF
				 SETCONTROLCOLOR w1,FileTab2,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 IF Tab2Loaded = 0
					 ProgPath = RecentProgs[2]
					 GetFileName(w1,0,ProgPath,1)
					 SETCONTROLTEXT(w1,FileTab2,FileNameIs)
					 DoOpen(1)
					 Tab2Loaded = 1
					 SETCONTROLTEXT(w1,FileTab2,FileNameIs)
                buffer2 = ""
                buffer2 = GETCONTROLTEXT(w1,1)
                OnTab = 2
				 ELSE
                OnTab = 2
                Tab2Loaded = 1
					 DoRestore(0,2)
				 ENDIF
			 ENDIF
		 ENDIF
    ENDIF
    IF Switch = 3
		 IF GETCONTROLTEXT(w1,FileTab3) <> ""
			 OnTab = 3
			 IF !instr(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3))
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab1))
					 buffer1 = ""
					 buffer1 = GETCONTROLTEXT(w1,1)
					 DoMinimise(1)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab2))
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,1)
					 DoMinimise(2)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab4))
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,1)
					 DoMinimise(4)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab5))
					 buffer5 = ""
					 buffer5 = getcontroltext(w1,1)
					 DoMinimise(5)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab6))
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,1)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab3)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab3,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab3Loaded = 0
					 ProgPath = RecentProgs[3]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab3,FileNameIs)
					 DoOpen(1)
					 Tab3Loaded = 1
					 setcontroltext(w1,FileTab3,FileNameIs)
                buffer3 = ""
                buffer3 = getcontroltext(w1,1)
                OnTab = 3
				 else
                OnTab = 3
                Tab3Loaded = 1
					 DoRestore(0,3)
				 endif
			 endif
		 endif
    endif
    if Switch = 4
		 if getcontroltext(w1,FileTab4) <> ""
			 OnTab = 4
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab4))
				 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,1)
					 DoMinimise(1)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab2))
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,1)
					 DoMinimise(2)
				 endif
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3))
					 buffer3 = ""
					 buffer3 = GETCONTROLTEXT(w1,1)
					 DoMinimise(3)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab5))
					 buffer5 = ""
					 buffer5 = GETCONTROLTEXT(w1,1)
					 DoMinimise(5)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab6))
					 buffer6 = ""
					 buffer6 = GETCONTROLTEXT(w1,1)
					 DoMinimise(6)
				 ENDIF
				 FileNameIs = GETCONTROLTEXT(w1,FileTab4)
             IF INSTR(FileNameIs,"*")
                FileNameIs = MID$(FileNameIs,1,INSTR(FileNameIs,"*")-1)
             ENDIF
				 SETCONTROLCOLOR w1,FileTab4,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 IF Tab4Loaded = 0
					 ProgPath = RecentProgs[4]
					 GetFileName(w1,0,ProgPath,1)
					 SETCONTROLTEXT(w1,FileTab4,FileNameIs)
					 DoOpen(1)
					 Tab4Loaded = 1
					 setcontroltext(w1,FileTab4,FileNameIs)
                buffer4 = ""
                buffer4 = getcontroltext(w1,1)
                OnTab = 4
				 else
                OnTab = 4
                Tab4Loaded = 1
					 DoRestore(0,4)
				 endif
			 endif
		 endif
    endif
    if Switch = 5
		 if getcontroltext(w1,FileTab5) <> ""
			 OnTab = 5
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab5))
				 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,1)
					 DoMinimise(1)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab2))
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,1)
					 DoMinimise(2)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab3))
					 buffer3 = ""
					 buffer3 = getcontroltext(w1,1)
					 DoMinimise(3)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab4))
					 buffer4 = ""
					 buffer4 = getcontroltext(w1,1)
					 DoMinimise(4)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab6))
					 buffer6 = ""
					 buffer6 = getcontroltext(w1,1)
					 DoMinimise(6)
				 endif
				 FileNameIs = getcontroltext(w1,FileTab5)
             if instr(FileNameIs,"*")
                FileNameIs = mid$(FileNameIs,1,instr(FileNameIs,"*")-1)
             endif
				 SETCONTROLCOLOR w1,FileTab5,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab6,RGB(0,0,0),BackColour
				 ClearEditor()
				 if Tab5Loaded = 0
					 ProgPath = RecentProgs[5]
					 GetFileName(w1,0,ProgPath,1)
					 setcontroltext(w1,FileTab5,FileNameIs)
					 DoOpen(1)
					 Tab5Loaded = 1
					 setcontroltext(w1,FileTab5,FileNameIs)
                buffer5 = ""
                buffer5 = getcontroltext(w1,1)
                OnTab = 5
				 else
                OnTab = 5
                Tab5Loaded = 1
					 DoRestore(0,5)
				 endif
			 endif
		 endif
    endif
    if Switch = 6
		 if getcontroltext(w1,FileTab6) <> ""
			 OnTab = 6
			 if !instr(getcaption(w1),getcontroltext(w1,FileTab6))
				 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
					 buffer1 = ""
					 buffer1 = getcontroltext(w1,1)
					 DoMinimise(1)
				 endif
				 if instr(getcaption(w1),getcontroltext(w1,FileTab2))
					 buffer2 = ""
					 buffer2 = getcontroltext(w1,1)
					 DoMinimise(2)
				 endif
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab3))
					 buffer3 = ""
					 buffer3 = GETCONTROLTEXT(w1,1)
					 DoMinimise(3)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab4))
					 buffer4 = ""
					 buffer4 = GETCONTROLTEXT(w1,1)
					 DoMinimise(4)
				 ENDIF
				 IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab5))
					 buffer5 = ""
					 buffer5 = GETCONTROLTEXT(w1,1)
					 DoMinimise(5)
				 ENDIF
				 FileNameIs = GETCONTROLTEXT(w1,FileTab6)
             IF INSTR(FileNameIs,"*")
                FileNameIs = MID$(FileNameIs,1,INSTR(FileNameIs,"*")-1)
             ENDIF
				 SETCONTROLCOLOR w1,FileTab6,RGB(255,255,255),Green
				 SETCONTROLCOLOR w1,FileTab1,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab2,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab3,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab4,RGB(0,0,0),BackColour
				 SETCONTROLCOLOR w1,FileTab5,RGB(0,0,0),BackColour
				 ClearEditor()
				 IF Tab6Loaded = 0
					 ProgPath = RecentProgs[6]
					 GetFileName(w1,0,ProgPath,1)
					 SETCONTROLTEXT(w1,FileTab6,FileNameIs)
					 DoOpen(1)
					 Tab6Loaded = 1
					 setcontroltext(w1,FileTab6,FileNameIs)
                buffer6 = ""
                buffer6 = getcontroltext(w1,1)
                OnTab = 6
				 else
                OnTab = 6
                Tab6Loaded = 1
					 DoRestore(0,6)
				 endif
			 endif
		 endif
    endif
    if cLine = 0
       cLine = 1
       StoreLine = 1
       ScrollPoint = 1
       'ScrollDown()
       'ScrollUp()
    ENDIF

ENABLECONTROL (w1,FileTab1,1)
ENABLECONTROL (w1,FileTab2,1)
ENABLECONTROL (w1,FileTab3,1)
ENABLECONTROL (w1,FileTab4,1)
ENABLECONTROL (w1,FileTab5,1)
ENABLECONTROL (w1,FileTab6,1)

	 IF GETSELECTED(w1,Combo2) > -1
		 ShowSubroutineButtons(1)
	 ELSE
		 ShowSubroutineButtons(0)
	 ENDIF
	 IF GETSELECTED(w1,Combo4) > -1
		 ShowWindowButtons(1)
	 ELSE
		 ShowWindowButtons(0)
	 ENDIF

STARTTIMER w1,TimerSpeed,10000
RETURN
ENDSUB

SUB CreateDetailsFile()
	 STRING MainNameD
	 STRING StoreBookFileD
	 MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
	 StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".txt"
	 IF OPENFILE(MyFile2,StoreBookFileD,"W") = 0
       STRING text2,text3,text4
		 INT lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
		 lvcount2 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
       WRITE MyFile2,":lv2-" + LTRIM$(STR$(lvcount2))
		 FOR a = 0 TO lvcount2 -1
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,1,text2)
			  CONTROLCMD(w1,ListView2,@LVGETTEXT,a,2,text3)
           WRITE MyFile2,text + "|" + text2 + "!" + text3
		 NEXT a

		 lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
		 lvcount2 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
       WRITE MyFile2,":lv4-" + LTRIM$(STR$(lvcount2))
		 FOR a = 0 TO lvcount2 -1
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,1,text2)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,2,text3)
			  CONTROLCMD(w1,ListView4,@LVGETTEXT,a,3,text4)
           WRITE MyFile2,text + "|" + text2 + "!" + text3 + "#" + text4
		 NEXT a

		 lvcount2 = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
		 lvcount2 = CONTROLCMD(w1,ListView8,@LVGETCOUNT)
       write MyFile2,":lv8-" + ltrim$(str$(lvcount2))
		 for a = 0 to lvcount2 -1
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,0,text)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,1,text2)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,2,text3)
			  CONTROLCMD(w1,ListView8,@LVGETTEXT,a,3,text4)
           write MyFile2,text + "|" + text2 + "!" + text3 + "#" + text4
		 next a

       'Bookmarks
       write MyFile2,":bmk-" + ltrim$(str$(getstringcount(w1,Combo6)))
		 for a = 0 to getstringcount(w1,Combo6) - 1
			  write MyFile2,getstring(w1,Combo6,a)
		 next a

       'Includes
       write MyFile2,":inc-" + ltrim$(str$(getstringcount(w1,Combo20)))
		 for a = 0 to getstringcount(w1,Combo20) - 1
			  write MyFile2,getstring(w1,Combo20,a)
		 next a

       'Scroll range
       int scMin,scMax
       scMin = 0
       scMax = CONTROLCMD(w1,1,@RTGETLINECOUNT)
       write MyFile2,":sr-" + ltrim$(str$(scMin)) + "!" + ltrim$(str$(scMax))

       'User go to lines
       if rtrim$(ltrim$(getcontroltext(w1,EDIT_11))) <> ""
          write MyFile2,":u1-" + rtrim$(ltrim$(getcontroltext(w1,EDIT_11)))
       else
          write MyFile2,":u1-0"
       endif
       if rtrim$(ltrim$(getcontroltext(w1,EDIT_111))) <> ""
          write MyFile2,":u2-" + rtrim$(ltrim$(getcontroltext(w1,EDIT_111)))
       ELSE
          WRITE MyFile2,":u2-0"
       ENDIF

       'Sub routines etc
       IF (GETSELECTED(w1,Combo2)) > - 1
          WRITE MyFile2,":c2-" + LTRIM$(STR$(GETSELECTED(w1,Combo2)))
       ELSE
          WRITE MyFile2,":c2-!"
       ENDIF

       IF (GETSELECTED(w1,Combo4)) > - 1
          WRITE MyFile2,":c4-" + LTRIM$(STR$(GETSELECTED(w1,Combo4)))
       ELSE
          WRITE MyFile2,":c4-!"
       ENDIF

       IF (GETSELECTED(w1,Combo6)) > - 1
          WRITE MyFile2,":c6-" + LTRIM$(STR$(GETSELECTED(w1,Combo6)))
       ELSE
          WRITE MyFile2,":c6-!"
       ENDIF

       IF (GETSELECTED(w1,Combo8)) > - 1
          WRITE MyFile2,":c8-" + LTRIM$(STR$(GETSELECTED(w1,Combo8)))
       ELSE
          WRITE MyFile2,":c8-!"
       ENDIF

       IF (GETSELECTED(w1,Combo10)) > - 1
          WRITE MyFile2,":c10-" + LTRIM$(STR$(GETSELECTED(w1,Combo10)))
       ELSE
          write MyFile2,":c10-!"
       endif

       if (getselected(w1,Combo12)) > - 1
          write MyFile2,":c12-" + ltrim$(str$(getselected(w1,Combo12)))
       else
          write MyFile2,":c12-!"
       endif

       if (getselected(w1,Combo14)) > - 1
          write MyFile2,":c14-" + ltrim$(str$(getselected(w1,Combo14)))
       else
          write MyFile2,":c14-!"
       endif

       if (getselected(w1,Combo16)) > - 1
          write MyFile2,":c16-" + ltrim$(str$(getselected(w1,Combo16)))
       else
          write MyFile2,":c16-!"
       endif

       write MyFile2,":sp-" + ltrim$(str$(getscrollpos(w1,16)))

    endif
    closefile MyFile2
return
endsub

sub DoMinimiseAll()
	 if OnTab = 1
		 if instr(getcaption(w1),getcontroltext(w1,FileTab1))
			 buffer1 = ""
			 buffer1 = getcontroltext(w1,1)
			 DoMinimise(1)
			 Tab1Loaded = 1
		 endif
	 endif
	 if OnTab = 2
		 if instr(getcaption(w1),getcontroltext(w1,FileTab2))
			 buffer2 = ""
			 buffer2 = getcontroltext(w1,1)
			 DoMinimise(2)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
		 endif
	 endif
	 if OnTab = 3
		 if instr(getcaption(w1),getcontroltext(w1,FileTab3))
			 buffer3 = ""
			 buffer3 = getcontroltext(w1,1)
			 DoMinimise(3)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
		 endif
	 endif
	 if OnTab = 4
		 if instr(getcaption(w1),getcontroltext(w1,FileTab4))
			 buffer4 = ""
			 buffer4 = getcontroltext(w1,1)
			 DoMinimise(4)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
			 Tab4Loaded = 1
		 endif
	 endif
	 if OnTab = 5
		 if instr(getcaption(w1),getcontroltext(w1,FileTab5))
			 buffer5 = ""
			 buffer5 = getcontroltext(w1,1)
			 DoMinimise(5)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
			 Tab4Loaded = 1
			 Tab5Loaded = 1
		 endif
	 endif
	 if OnTab = 6
		 if instr(getcaption(w1),getcontroltext(w1,FileTab6))
			 buffer6 = ""
			 buffer6 = getcontroltext(w1,1)
			 DoMinimise(6)
			 Tab1Loaded = 1
			 Tab2Loaded = 1
			 Tab3Loaded = 1
			 Tab4Loaded = 1
			 Tab5Loaded = 1
			 Tab6Loaded = 1
		 ENDIF
	 ENDIF
RETURN
ENDSUB

SUB CreatePathFile()
	 GetFileName(w1,0,ProgPath,1)
	 STRING MainNameD = MID$(FileNameIs,1,INSTR(FileNameIs,".")-1)
	 STRING StoreBookFileD = GETSTARTPATH() + "\\Res\\" + MainNameD + ".pth"
	 IF OPENFILE(MyFile2,StoreBookFileD,"W") = 0
		 WRITE MyFile2,LTRIM$(ProgPath)
	 ENDIF
	 CLOSEFILE MyFile2
RETURN
ENDSUB

SUB LoadIncludePath()
	 IF OPENFILE(MyFile,GETSTARTPATH + "\\Res\\" + "IncludeFilesPath.ini","R") = 0
		 READ MyFile,IncludePath
	 ENDIF
	 CLOSEFILE MyFile
	 IF OPENFILE(MyFile,GETSTARTPATH + "\\Res\\" + "IncludeFilesPath.ini","R") = 1
		 LocateIniFile()
		 IF StopNow = 1
			 IncludePath = FrontPath + IncludePath
			 IF OPENFILE(MyFile,GETSTARTPATH + "\\Res\\" + "IncludeFilesPath.ini","W") = 0
		 		 WRITE MyFile,IncludePath
			 ENDIF
			 CLOSEFILE MyFile
		 ENDIF
		 IF StopNow = 0
			 IF OPENFILE(MyFile,GETSTARTPATH + "\\Res\\" + "IncludeFilesPath.ini","W") = 0
				 WRITE MyFile,"C:" + CHR$(92) + "IWBDev" + CHR$(92) + "Include" + CHR$(92)
			 ENDIF
			 CLOSEFILE MyFile
		 ENDIF
	 ENDIF
	 CLOSEFILE MyFile
RETURN
ENDSUB

SUB DoInitialLoad()
    RecentFiles()
    IF ProgPath <> ""
       IF FileOpenedBefore()
		    DoOpen(1)
		    TabTaken = 1
		    SETCONTROLTEXT(w1,FileTab1,FileNameIs)
		    SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
          Tab1Loaded = 1
       else
          StartUp()
          buffer1 = ClipText
          CreatePathFile()
			 TabTaken = 1
			 setcontroltext(w1,FileTab1,FileNameIs)
			 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
			 Tab1Loaded = 1
			 setfocus w1,1
       endif
       if ProgCount = 0
          ProgCount = 1
          RecentProgs[1] = ProgPath
       endif
    ENDIF
    OnTab = 1
    TabTaken = ProgCount
    IF ProgCount > 0
       LoadTab(1)
    ELSE
       FileNameIs = "Untitled.iwb"
       ProgPath = GETSTARTPATH + FileNameIs
       ProgCount = 1
       RecentProgs[1] = ProgPath
       RecentName[1] = "Untitled.iwb"
       SETCAPTION w1,FileNameIs
       SETCONTROLTEXT(w1,1,"")
		 SETCONTROLTEXT(w1,FileTab1,FileNameIs)
		 SETCONTROLCOLOR w1,FileTab1,RGB(255,255,255),Green
       DoOpen(1)
       TabTaken = 1
       Tab1Loaded = 1
       FOR a = 1 TO 29
           IF a = 1
              SETCONTROLTEXT(w1,a+1000,"> " + LTRIM$(STR$(a)))
           ELSE
              SETCONTROLTEXT(w1,a+1000,LTRIM$(STR$(a)))
           ENDIF
       NEXT a
       SETSCROLLPOS(w1,16,0)
       SENDMESSAGE(GETCONTROLHANDLE(w1,1),EM_SETSEL,1,1)
       SETFOCUS w1,1
    ENDIF
    IF RecentProgs[1] <> ""
       SETCONTROLTEXT(w1,FileTab1,RecentName[1])
    ENDIF
    if RecentProgs[2] <> ""
       setcontroltext(w1,FileTab2,RecentName[2])
    endif
    if RecentProgs[3] <> ""
       setcontroltext(w1,FileTab3,RecentName[3])
    endif
    if RecentProgs[4] <> ""
       setcontroltext(w1,FileTab4,RecentName[4])
    endif
    if RecentProgs[5] <> ""
       setcontroltext(w1,FileTab5,RecentName[5])
    endif
    if RecentProgs[6] <> ""
       setcontroltext(w1,FileTab6,RecentName[6])
    endif
return
endsub

sub CloseFiles()
    Loading = 1
    RealTabName = ""
    string CloseLine = ltrim$(getcontroltext(w1,1001))
    if instr(CloseLine,">")
	    CloseLine = mid$(CloseLine,instr(CloseLine,">")+3,len(CloseLine))
    endif
    showwindow w1,@SWHIDE,1

    if instr(getcaption(w1),getcontroltext(w1,FileTab1))
       CreateDetailsFile()
       if instr(getcontroltext(w1,FileTab1),"*")
          RealTabName = getcontroltext(w1,FileTab1)
          RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)
          CloseDown = 1
          WindowDelete(0)
          If DelConfirm = 1
             DoSave(1)
          endif
       endif
       setcontroltext(w1,FileTab1,RealTabName)
	    RealTabName = ""
    endif
    if instr(getcaption(w1),getcontroltext(w1,FileTab2))
       CreateDetailsFile()
       if instr(getcontroltext(w1,FileTab2),"*")
          RealTabName = getcontroltext(w1,FileTab2)
          RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)
          CloseDown = 1
          WindowDelete(0)
          If DelConfirm = 1
             DoSave(2)
          endif
       endif
       setcontroltext(w1,FileTab2,RealTabName)
	    RealTabName = ""
    endif
    if instr(getcaption(w1),getcontroltext(w1,FileTab3))
       CreateDetailsFile()
       if instr(getcontroltext(w1,FileTab3),"*")
          RealTabName = getcontroltext(w1,FileTab3)
          RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)
          CloseDown = 1
          WindowDelete(0)
          If DelConfirm = 1
             DoSave(3)
          endif
       endif
       setcontroltext(w1,FileTab3,RealTabName)
	    RealTabName = ""
    endif
    if instr(getcaption(w1),getcontroltext(w1,FileTab4))
       CreateDetailsFile()
       if instr(getcontroltext(w1,FileTab4),"*")
          RealTabName = getcontroltext(w1,FileTab4)
          RealTabName = mid$(RealTabName,1,instr(RealTabName,"*")-1)
          CloseDown = 1
          WindowDelete(0)
          If DelConfirm = 1
             DoSave(4)
          endif
       endif
       setcontroltext(w1,FileTab4,RealTabName)
	    RealTabName = ""
    endif
    if instr(getcaption(w1),getcontroltext(w1,FileTab5))
       CreateDetailsFile()
       IF INSTR(GETCONTROLTEXT(w1,FileTab5),"*")
          RealTabName = GETCONTROLTEXT(w1,FileTab5)
          RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
          CloseDown = 1
          WindowDelete(0)
          IF DelConfirm = 1
             DoSave(5)
          ENDIF
       ENDIF
       SETCONTROLTEXT(w1,FileTab5,RealTabName)
	    RealTabName = ""
    ENDIF
    IF INSTR(GETCAPTION(w1),GETCONTROLTEXT(w1,FileTab6))
       CreateDetailsFile()
       IF INSTR(GETCONTROLTEXT(w1,FileTab6),"*")
          RealTabName = GETCONTROLTEXT(w1,FileTab6)
          RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
          CloseDown = 1
          WindowDelete(0)
          IF DelConfirm = 1
             DoSave(6)
          ENDIF
       ENDIF
       SETCONTROLTEXT(w1,FileTab6,RealTabName)
	    RealTabName = ""
    ENDIF

    IF AutoSaveOnExit = 1
	    IF GETCONTROLTEXT(w1,FileTab1) <> ""
          IF INSTR(GETCONTROLTEXT(w1,FileTab1),"*")
             RealTabName = GETCONTROLTEXT(w1,FileTab1)
             RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
             CloseDown = 1
             WindowDelete(0)
             IF DelConfirm = 1
                DelConfirm = 0
                GOTO s1
             ELSE
                GOTO l2
             ENDIF
          ELSE
             GOTO l2
          ENDIF
          LABEL s1
		    ProgPath = RecentProgs[1]
		    GetFileName(w1,0,ProgPath,1)
		    IF !instr(ProgPath,IncludePath)
			    DoSaveOnExit(1)
		    ENDIF
	    ENDIF
       LABEL l2
       RealTabName = ""
	    IF GETCONTROLTEXT(w1,FileTab2) <> ""
          IF INSTR(GETCONTROLTEXT(w1,FileTab2),"*")
             RealTabName = GETCONTROLTEXT(w1,FileTab2)
             RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
             CloseDown = 2
             WindowDelete(0)
             IF DelConfirm = 1
                DelConfirm = 0
                GOTO s2
             ELSE
                GOTO l3
             ENDIF
          ELSE
             GOTO l3
          ENDIF
          LABEL s2
          FOR a = 1 TO MaxTabs
              IF INSTR(RecentProgs[a],RealTabName)
		           ProgPath = RecentProgs[a]
                 BREAKFOR
              ENDIF
          NEXT a
		    GetFileName(w1,0,ProgPath,1)
		    IF !instr(ProgPath,IncludePath)
			    DoSaveOnExit(2)
		    ENDIF
	    ENDIF
       LABEL l3
       RealTabName = ""
	    IF GETCONTROLTEXT(w1,FileTab3) <> ""
          IF INSTR(GETCONTROLTEXT(w1,FileTab3),"*")
             RealTabName = GETCONTROLTEXT(w1,FileTab3)
             RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
             CloseDown = 3
             WindowDelete(0)
             IF DelConfirm = 1
                DelConfirm = 0
                GOTO s3
             ELSE
                GOTO l4
             ENDIF
          ELSE
             GOTO l4
          ENDIF
          LABEL s3
          FOR a = 1 TO MaxTabs
              IF INSTR(RecentProgs[a],RealTabName)
		           ProgPath = RecentProgs[a]
                 BREAKFOR
              ENDIF
          NEXT a
		    GetFileName(w1,0,ProgPath,1)
		    IF !instr(ProgPath,IncludePath)
			    DoSaveOnExit(3)
		    ENDIF
	    ENDIF
       LABEL l4
       RealTabName = ""
	    IF GETCONTROLTEXT(w1,FileTab4) <> ""
          IF INSTR(GETCONTROLTEXT(w1,FileTab4),"*")
             RealTabName = GETCONTROLTEXT(w1,FileTab4)
             RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
             CloseDown = 4
             WindowDelete(0)
             IF DelConfirm = 1
                DelConfirm = 0
                GOTO s4
             ELSE
                GOTO l5
             ENDIF
          ELSE
             GOTO l5
          endif
          label s4
          for a = 1 to MaxTabs
              if instr(RecentProgs[a],RealTabName)
		           ProgPath = RecentProgs[a]
                 breakfor
              endif
          next a
		    GetFileName(w1,0,ProgPath,1)
		    if !instr(ProgPath,IncludePath)
			    DoSaveOnExit(4)
		    endif
	    endif
       label l5
       RealTabName = ""
	    IF GETCONTROLTEXT(w1,FileTab5) <> ""
          IF INSTR(GETCONTROLTEXT(w1,FileTab5),"*")
             RealTabName = GETCONTROLTEXT(w1,FileTab5)
             RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
             CloseDown = 5
             WindowDelete(0)
             IF DelConfirm = 1
                DelConfirm = 0
                GOTO s5
             ELSE
                GOTO l6
             ENDIF
          ELSE
             GOTO l6
          ENDIF
          LABEL s5
          FOR a = 1 TO MaxTabs
              IF INSTR(RecentProgs[a],RealTabName)
		           ProgPath = RecentProgs[a]
                 BREAKFOR
              ENDIF
          NEXT a
		    GetFileName(w1,0,ProgPath,1)
		    IF !instr(ProgPath,IncludePath)
			    DoSaveOnExit(5)
		    ENDIF
	    ENDIF
       LABEL l6
       RealTabName = ""
	    IF GETCONTROLTEXT(w1,FileTab6) <> ""
          IF INSTR(GETCONTROLTEXT(w1,FileTab6),"*")
             RealTabName = GETCONTROLTEXT(w1,FileTab6)
             RealTabName = MID$(RealTabName,1,INSTR(RealTabName,"*")-1)
             CloseDown = 6
             WindowDelete(0)
             IF DelConfirm = 1
                DelConfirm = 0
                GOTO s6
             ELSE
                GOTO l7
             ENDIF
          ELSE
             GOTO l7
          ENDIF
          LABEL s6
          FOR a = 1 TO MaxTabs
              IF INSTR(RecentProgs[a],RealTabName)
		           ProgPath = RecentProgs[a]
                 BREAKFOR
              ENDIF
          NEXT a
		    GetFileName(w1,0,ProgPath,1)
		    IF !instr(ProgPath,IncludePath)
			    DoSaveOnExit(6)
		    ENDIF
          LABEL l7
          RealTabName = ""
	    ENDIF
    ENDIF
    IF OPENFILE(MyFile2,GETSTARTPATH + "\\Res\\" + "xeditor4.ini","W") = 0
	    FOR a = 1 TO ProgCount
			  IF RTRIM$(LTRIM$(RecentProgs[a])) <> ""
				  WRITE MyFile2,RecentProgs[a]
			  ENDIF
	    NEXT a
	    CLOSEFILE MyFile2
    ENDIF
RETURN
ENDSUB

SUB ScrollWheel(INT Direction)
	 INT z1
    IF Direction = 1
		 FOR z1 = 1 TO WheelScrollLines
			  DoLineUp()
		 NEXT z1
    ENDIF
    if Direction = 2
		 for z1 = 1 to WheelScrollLines
			  DoLineDown()
		 next z1
    endif
return
endsub

sub DoToolTips()
	 uint hTooltip
	 hTooltip=TOOLTIPCONTROL(w1,@TTS_ALWAYSTIP|@TTS_NOANIMATE|@TTS_NOFADE|@TTS_BALLOON,0)
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CloseButton),w1.hWnd,"Close file"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NewButton),w1.hWnd,"New file"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SaveButton),w1.hWnd,"Save file"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,OpenButton),w1.hWnd,"Open file"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SaveAsButton),w1.hWnd,"Save file as..."
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BackupButton),w1.hWnd,"Backup file"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CogButton),w1.hWnd,"Re-index file"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BinButton),w1.hWnd,"Clear undo - redos"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,AutoButton),w1.hWnd,"Turn auto complete of key words on or off"

	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowCode),w1.hWnd,"Show main code"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock1),w1.hWnd,"Show block 1 code"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock2),w1.hWnd,"Show block 2 code"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock3),w1.hWnd,"Show block 3 code"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBlock4),w1.hWnd,"Show block 4 code"

	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopyBlockButton),w1.hWnd,"Copy block code to clipboard"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DeleteBlockButton),w1.hWnd,"Clear code from block"

    'Subroutines
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BUTTON_4),w1.hWnd,"Go to this line"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BUTTON_44),w1.hWnd,"Go to this line"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SubJump),w1.hWnd,"Go to this subroutine"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,EndSubb),w1.hWnd,"Go to subroutine end"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopySubButton),w1.hWnd,"Copy subroutine to clipboard"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopySubBlockButton),w1.hWnd,"Copy subroutine to a block"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,MoveSubButton),w1.hWnd,"Move subroutine to clicked position"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DeleteSubButton),w1.hWnd,"Delete subroutine"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowSubButton),w1.hWnd,"Subroutine multi-select option"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ClearSubs),w1.hWnd,"Clear subroutine selection"

    'Windows
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,WinJump),w1.hWnd,"Go to this window / dialog"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,EndWin),w1.hWnd,"Go to end of window / dialog"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,WinHandler),w1.hWnd,"Go to handler"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopyWinButton),w1.hWnd,"Copy window to clipboard"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CopyWinBlockButton),w1.hWnd,"Copy window to a block"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,MoveWinButton),w1.hWnd,"Move window to clicked position"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,DeleteWinButton),w1.hWnd,"Delete window"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowWindowButton),w1.hWnd,"Window multi-select option"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ClearWins),w1.hWnd,"Clear window selection"

    'Bookmarks
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookJump),w1.hWnd,"Go to this bookmark"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookAdd),w1.hWnd,"Add to bookmarks"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookDel),w1.hWnd,"Remove bookmark"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BookDelAll),w1.hWnd,"Clear bookmarks"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowBookmarksButton),w1.hWnd,"Bookmark multi-select"

    'Selects
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,SelectJump),w1.hWnd,"Go to this section"

    'Cases
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CaseJump),w1.hWnd,"Go to this case"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,ShowCasesButton),w1.hWnd,"Show all selects"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CaseFind),w1.hWnd,"Search for a case"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CaseDelete),w1.hWnd,"Clear case search results"

    'Navigarion
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavBackButton),w1.hWnd,"Go back"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavForwardButton),w1.hWnd,"Go forward"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavButton),w1.hWnd,"Add location to navigation"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,NavDeleteButton),w1.hWnd,"Remove location from navigation"

    'AutoJump
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,Check1),w1.hWnd,"Automatically jump to a selection"

    'Searches
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,KeyFind),w1.hWnd,"Seach list of key words"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,KeyDelete),w1.hWnd,"Clear key word search"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordSearch),w1.hWnd,"Search code for one or two words"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordDelete),w1.hWnd,"Clear search words"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordAnd),w1.hWnd,"Show both words on same line"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodeWordOr),w1.hWnd,"Show either word on same line"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhraseExact),w1.hWnd,"Search for exact match"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhraseWords),w1.hWnd,"Search code for words - maximum of four"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,CodePhraseSearch),w1.hWnd,"Search code for words on the same line"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,PhraseDeleteButton),w1.hWnd,"Clear search words"

    'Top / Bottom
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,TopButton),w1.hWnd,"Go to the first line"
	 TTADDTOOL hTooltip,@TTF_SUBCLASS|@TTF_IDISHWND|@TTF_CENTERTIP,GETCONTROLHANDLE(w1,BottomButton),w1.hWnd,"Go to the last line"

    '58 toolstips
	 height = 11
	 weight = 400
	 ZeroMemory(lf,LEN(LOGFONT))
	 lstrcpynA(lf.lfFaceName,"Segoe UI",height)
	 hdc = GetHDC(win)
	 lf.lfHeight = -MulDiv(height,GetDeviceCaps(hdc,90 /*LOGPIXELSY*/),72)
	 lf.lfWeight = weight
	 lf.lfQuality = 1 /*DRAFT_QUALITY*/
	 lf.lfPitchAndFamily = 0 /*DRAFT_PITCH*/
	 lf.lfItalic = 0
	 lf.lfUnderline = 0
	 lf.lfStrikeOut = 0
	 font = CreateFontIndirectA(lf)
	 oldfont = SendMessageA(hTooltip,WM_GETFONT,0,0)
	 SendMessageA(hTooltip,WM_SETFONT,NULL,0)
	 SendMessageA(hTooltip,WM_SETFONT,font,1)
	 IF(oldfont) THEN DeleteObject(oldfont)
	 RELEASEHDC(win,hdc)
	 SENDMESSAGE hTooltip,TTM_SETMAXTIPWIDTH,0,500
RETURN
ENDSUB

SUB ShowSubRoutineButtons(OPT INT Switch)
Switch = 1
    IF Switch = 0
		 SHOWWINDOW w1,@SWHIDE,SubJump
		 SHOWWINDOW w1,@SWHIDE,EndSubb
		 SHOWWINDOW w1,@SWHIDE,CopySubButton
		 SHOWWINDOW w1,@SWHIDE,CopySubBlockButton
		 SHOWWINDOW w1,@SWHIDE,MoveSubButton
		 SHOWWINDOW w1,@SWHIDE,DeleteSubButton
		 SHOWWINDOW w1,@SWHIDE,ShowSubButton
		 SHOWWINDOW w1,@SWHIDE,ClearSubs
    ELSE
		 SHOWWINDOW w1,@SWSHOW,SubJump
		 SHOWWINDOW w1,@SWSHOW,EndSubb
		 SHOWWINDOW w1,@SWSHOW,CopySubButton
		 SHOWWINDOW w1,@SWSHOW,CopySubBlockButton
		 SHOWWINDOW w1,@SWSHOW,MoveSubButton
		 SHOWWINDOW w1,@SWSHOW,DeleteSubButton
		 SHOWWINDOW w1,@SWSHOW,ShowSubButton
		 SHOWWINDOW w1,@SWSHOW,ClearSubs
   ENDIF
RETURN
ENDSUB

sub ShowWindowButtons(opt int Switch)
    if Switch = 0
		 showwindow w1,@SWHIDE,WinJump
		 showwindow w1,@SWHIDE,EndWin
		 showwindow w1,@SWHIDE,WinHandler
		 showwindow w1,@SWHIDE,CopyWinButton
		 showwindow w1,@SWHIDE,CopyWinBlockButton
		 showwindow w1,@SWHIDE,MoveWinButton
		 showwindow w1,@SWHIDE,DeleteWinButton
		 showwindow w1,@SWHIDE,ShowWindowButton
		 showwindow w1,@SWHIDE,ClearWins
    else
		 showwindow w1,@SWSHOW,WinJump
		 SHOWWINDOW w1,@SWSHOW,EndWin
		 SHOWWINDOW w1,@SWSHOW,WinHandler
		 SHOWWINDOW w1,@SWSHOW,CopyWinButton
		 SHOWWINDOW w1,@SWSHOW,CopyWinBlockButton
		 SHOWWINDOW w1,@SWSHOW,MoveWinButton
		 SHOWWINDOW w1,@SWSHOW,DeleteWinButton
		 SHOWWINDOW w1,@SWSHOW,ShowWindowButton
		 SHOWWINDOW w1,@SWSHOW,ClearWins
    ENDIF
RETURN
ENDSUB

SUB ColourScreenPageDown(OPT INT Switch)
    STOPTIMER w1,10000
    INT FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 INT StorecLine = cLine
	 showcursor(FALSE)
	 eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
	 SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

	 FOR a = (FirstVisLine + 28) TO (FirstVisLine + 29) + 29
		  cLine = a + 1
		  StoreLine = cLine
		  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
		  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLineA
		  Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineZ(rHandle,a-1,line$,Offset)
	 LABEL CheckNextLineA
	 NEXT a

	 cLine = StorecLine
    StoreLine = cLine
	 OldLine = OnLine

	 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
	 InvalidateRect(rHandle,0,true)
	 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	 showcursor(TRUE)
    STARTTIMER w1,TimerSpeed1,10000
RETURN
ENDSUB

SUB ColourScreenPageUp(OPT INT Switch)
    STOPTIMER w1,10000
    INT b2 = 0
    INT LineHasBeenColoured = 0
    INT FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 INT StorecLine = cLine
	 showcursor(FALSE)
	 eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
	 SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

	 FOR a = FirstVisLine - 29 TO FirstVisLine
		  cLine = a + 1
		  StoreLine = cLine
		  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
		  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLineA
		  Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineZ(rHandle,a-1,line$,Offset)

	 LABEL CheckNextLineA
    LineHasBeenColoured = 0
	 NEXT a

	 cLine = FirstVisLine - 28
    StoreLine = cLine
	 OldLine = OnLine

	 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
	 InvalidateRect(rHandle,0,true)
	 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	 showcursor(TRUE)
    STARTTIMER w1,TimerSpeed1,10000
RETURN
ENDSUB

SUB ColourScreenVisableUp(OPT INT Switch)
    STOPTIMER w1,10000
    INT FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
	 int StorecLine = cLine
	 showcursor(FALSE)
	 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
	 SendMessage(rHandle,WM_SETREDRAW,false,0)

    int StoreFvis = FirstVisLine
	 for a = FirstVisLine - 34 to FirstVisLine
		  cLine = a + 1
		  StoreLine = cLine
		  CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
		  if !len(ltrim$(line$)) then goto CheckNextLineA
		  Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
		  ColourLineZ(rHandle,a-1,line$,Offset)
	 label CheckNextLineA
	 NEXT a

	 cLine = StorecLine
    StoreLine = cLine

	 Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,cLine-1,0)
	 SENDMESSAGE(rHandle,EM_SETSEL,Offset,Offset)
	 OldLine = OnLine
	 StoreLine = cLine

	 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
	 InvalidateRect(rHandle,0,true)
	 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	 showcursor(TRUE)

    sRange.Low = StoreFvis
    sRange.Low = sRange.Low * 16

    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
	 SETSCROLLPOS(w1,16,sRange.Low/16)
    STARTTIMER w1,TimerSpeed1,10000
RETURN
ENDSUB

SUB StringToVal(STRING StringIn),INT
    STRING StringOut = ""
    STRING StringBit = ""
    INT TheValue = 0
    INT Loop = 0
    FOR Loop = 1 TO LEN(StringIn)
        StringBit = MID$(StringIn,Loop,1)
        IF StringBit >= CHR$(48) AND StringBit <= CHR$(57)
           StringOut = StringOut + StringBit
        endif
    next Loop
    TheValue = val(StringOut)
return TheValue
endsub

sub ColourScreenVisableDown(opt int Switch)
    stoptimer w1,10000
    int FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
    int StorecLine = cLine
    showcursor(FALSE)
    eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
    SendMessage(rHandle,WM_SETREDRAW,false,0)

    for a = FirstVisLine to FirstVisLine + 34
        cLine = a + 1
        StoreLine = cLine
        CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,255)
        if !len(ltrim$(line$)) then goto CheckNextLineA
        Offset = SendMessage(rHandle,EM_LINEINDEX,a-1,0)
        ColourLineZ(rHandle,a-1,line$,Offset)
    label CheckNextLineA
    next a

    cLine = StorecLine
    StoreLine = cLine

    Offset = SendMessage(rHandle,EM_LINEINDEX,cLine-1,0)
    SendMessage(rHandle,EM_SETSEL,Offset,Offset)
    OldLine = OnLine
    StoreLine = cLine

    SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
    InvalidateRect(rHandle,0,true)
    SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
    showcursor(TRUE)

    FOR a = 1 TO 29
        IF INSTR(GETCONTROLTEXT(w1,a+1000),">")
           sRange.Low = StringToVal(GETCONTROLTEXT(w1,a+1000))
           sRange.Low = (sRange.Low - 28) * 16
           BREAKFOR
        ENDIF
    NEXT a
    SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
    SETSCROLLPOS(w1,16,sRange.Low/16)
    STARTTIMER w1,TimerSpeed1,10000
RETURN
ENDSUB

SUB DoCloseProgram()
    CLOSECONSOLE
    SHOWWINDOW w1,@SWMINIMIZED
    CloseFiles()
    UnSubclassRichEdit(w1,1)
    CLOSEWINDOW w14
    CLOSEWINDOW w8
    CLOSEWINDOW w6
    CLOSEWINDOW w4
    CLOSEWINDOW w2
    CLOSEWINDOW w1
RETURN
ENDSUB

SUB DoGetSubRoutinesE(WINDOW WinIn,INT ListViewIn,STRING BlockWord),INT
    BlockType = 1
    QuotesOn = 0
    QuotesOff = 0
    SubCount = 0
    WindowCount = 0
    SubNutNoWindow = 0
    WindowButNoSub = 0
    BlockFound = 0
    WordCount = 0
    STRING EndWithThis = ""

    IF EditorType = 3
      EndWithThis = "RETURN"
    ELSE
      EndWithThis = "ENDSUB"
    ENDIF

    dIn = ""
    x = 0
    y = 0
       'IF ClipText <> ""

	 int CountLines = CONTROLCMD(w1,1,@RTGETLINECOUNT)
	 int b2 = 0
		 LABEL ReadFileAgain
		 dIn = ""
		 y = 0
		 QuotesOn = 0
		 QuotesOff = 0
		 SubNutNoWindow = 0
		 WindowButNoSub = 0
		 BlockFound = 0
		 WordCount = 0

		 DO
			 label CheckNextLine
			 b2++
			 label ReReadSubs
			 CONTROLCMD(w1,1,@RTGETLINE,b2-1,dIn,512)
			 if !len(ltrim$(line$)) then goto CheckNextLine
			 Offset = SendMessage(rHandle,EM_LINEINDEX,b2-1,0)
			 dIn = LTRIM$(dIn)
			 WordCount = 0
			 WordIn = ""
			 x ++
			   DO
				  INT amatch = 0
				  INT smatch = 0
				  y ++
				  Letter = MID$(dIn,y,1)
				  IF LEN(dIn) = 0
                          BREAK
                       ENDIF
                       IF INSTR(CheckLetter,Letter) > 0 'Delimiter found.
                          amatch = 1
                       ENDIF

                       'No delimiter found, so add to the word.
                       IF amatch = 0
                          WordIn = WordIn + MID$(dIn,y,1)
                       ELSE
                          'End of word.
                        IF WordIn <> ""
                             WordCount ++
                             #w[WordCount].aWord = WordIn
                        ENDIF

                        WordIn = ""
                     ENDIF
                  UNTIL y = LEN(dIn) OR WordCount = 2

                  y = 0

                  'After the end of each line, add the final word.
                  WordCount ++
                  #w[WordCount].aWord = WordIn
                  #d[WordCount].Delimiter = ""


						if instr(#w[1].aWord,chr$(13))
							#w[1].aWord = mid$(#w[1].aWord,1,instr(#w[1].aWord,chr$(13))-1)
						endif

						if instr(#w[2].aWord,chr$(13))
							#w[2].aWord = mid$(#w[2].aWord,1,instr(#w[2].aWord,chr$(13))-1)
						endif

                  'Subs only...
                  IF UCASE$(#w[1].aWord) = UCASE$(BlockWord)
						   INT WordOne = INSTR(dIn,#w[1].aWord) - 1
						   STRING AnythingBefore = MID$(dIn,1,WordOne)
						   IF INSTR(AnythingBefore,"'") = 0
							   SubCount ++
							   SubRoutines[SubCount] = #w[2].aWord
							   SubRoutineStart[SubCount] = x
						   ENDIF
                  ENDIF

						IF UCASE$(#w[1].aWord) = UCASE$(EndWithThis)
							SubRoutineEnd[SubCount] = x
						ENDIF

						IF UCASE$(#w[1].aWord) = "END" AND UCASE$(#w[2].aWord) = "SUB"
							SubRoutineEnd[SubCount] = x
						ENDIF

                  IF UCASE$(#w[1].aWord) = "OPENWINDOW" OR UCASE$(#w[1].aWord) = "CREATEDIALOG"
                     WindowCount ++
                     SearchWindow[WindowCount] = #w[2].aWord
                     WindowStart[WindowCount] = x
                  ENDIF

						IF UCASE$(#w[1].aWord) = "WAITUNTIL" OR UCASE$(#w[1].aWord) = "DOMODAL"
							WindowEnd[WindowCount] = x
						ENDIF

                  IF UCASE$(#w[1].aWord) = "$INCLUDE"
                     ADDSTRING w1,Combo20,#w[2].aWord
                  ENDIF

          UNTIL b2 >= CountLines

          INT CloseNow = 0
          BlockFound = 0
          IF b2 > CountLines THEN GOTO JumpOutLoop
          GOTO ReadFileAgain

          IF CloseNow = 0
             LABEL JumpOutLoop
             FOR a = 0 TO SubCount - 1
                 CONTROLCMD WinIn,ListViewIn,@LVINSERTITEM,a,SubRoutines[a+1]
                 INT position = CONTROLCMD(WinIn,ListViewIn,@LVFINDITEM,SubRoutines[a+1])
                 CONTROLCMD WinIn,ListViewIn,@LVSETTEXT,position,1,LTRIM$(STR$(SubRoutineStart[a+1]))
                 CONTROLCMD WinIn,ListViewIn,@LVSETTEXT,position,2,LTRIM$(STR$(SubRoutineEnd[a+1]))
             NEXT a

             FOR a = 0 TO WindowCount - 1
                 CONTROLCMD w1,ListView4,@LVINSERTITEM,a,SearchWindow[a+1]
                 position = CONTROLCMD(w1,ListView4,@LVFINDITEM,SearchWindow[a+1])
                 CONTROLCMD w1,ListView4,@LVSETTEXT,position,1,LTRIM$(STR$(WindowStart[a+1]))
                 CONTROLCMD w1,ListView4,@LVSETTEXT,position,2,LTRIM$(STR$(WindowEnd[a+1]))
                 CONTROLCMD w1,ListView4,@LVSETTEXT,position,3,HandleName[a+1]
             NEXT a

          ENDIF

RETURN 0
ENDSUB

sub DoRebuild()
RebuildCount ++
print "  REBUILD ",RebuildCount
    int c2Restore = getselected(w1,Combo2)
    int c4Restore = getselected(w1,Combo4)
    CONTROLCMD(w1,ListView2,@LVDELETEALL)
    CONTROLCMD(w1,ListView4,@LVDELETEALL)
    SendMessage(GetDlgItem(w1.hwnd,Combo2),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo4),CB_RESETCONTENT,0,0)
    SENDMESSAGE(GetDlgItem(w1.hwnd,Combo20),CB_RESETCONTENT,0,0)
    DoGetSubRoutinesE(w1,ListView2,"SUB")
    INT lvcount22 = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
    IF lvcount22 > 0
       StoreSubs()
       PopulateSubRoutines()
    ENDIF
    SETSELECTED(w1,Combo2,c2Restore)

    lvcount22 = CONTROLCMD(w1,ListView4,@LVGETCOUNT)
    IF lvcount22 > 0
       PopulateWindows()
    ENDIF
    SETSELECTED(w1,Combo4,c4Restore)
PRINT "  REBUILD DONE"
RETURN
ENDSUB

SUB DoPasteKeyBoard()

	  'ReadClipBoard()
	  StorecLine = cLine

	  'CONTROLCMD w1,1,@RTPASTE

'print "Press key"
'do:until inkey$ <> ""

PRINT "Do Paste KeyBoard"
PRINT
PRINT ClipText2


							  IF LEN(ClipText2)

								  SENDMESSAGE(rHandle,EM_EXGETSEL,0,cr)


                          Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,cLine-1,0)

PRINT "Loading ? ",Loading

								  Undo2Count[OnTab] ++
								  Undo2[OnTab].Press[Undo2Count[OnTab]]  = 5
								  Undo2[OnTab].Length[Undo2Count[OnTab]]  = LEN(ClipText2)
								  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = ClipText2
								  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]  = (Offset + ppos) -1 'cr.cpMin
								  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]  = (Offset + LEN(ClipText2)) -1  'cr.cpMax
								  UndoBlock[OnTab].Length[Undo2Count[OnTab]]  = LEN(ClipText2)

							  ENDIF

							  rHandle = GETCONTROLHANDLE(w1,1)
							  SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,0)
							  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

							  PRINT "Len = ",LEN(CutLine)
							  SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
							  CONTROLCMD w1,1,@RTDELETESEL
							  SENDMESSAGE(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
							  CONTROLCMD w1,1,@RTREPLACESEL,ClipText2

	  FOR a = cLine-(LineCount-1)-1 TO StorecLine + (LineCount-1)
			char_index = CONTROLCMD (w1,1,@RTCHARFROMLINE,a-1)
			CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			ColourLineZ(rHandle,a-1,line$,char_index)
	  NEXT a

	  SENDMESSAGE(rHandle,WM_SETREDRAW,true,0)
	  InvalidateRect(rHandle,0,true)
	  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
	  ShowCursor(TRUE)
     MoveBlocks(cLine,LineCount,1)
	  SENDMESSAGE(rHandle,EM_SETSEL,1+char_index,1 + char_index)

RETURN
ENDSUB

SUB DoUndo(hwnd:INT,uMsg:INT,wParam:INT,lParam:POINTER)
	 IF Undo2[OnTab].Typed[Undo2Count[OnTab]]  = CHR$(13) + CHR$(10)
		 SENDMESSAGE(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] ,Undo2[OnTab].pos[Undo2Count[OnTab]]+2)
		 CONTROLCMD w1,1,@RTDELETESEL
	 ELSE
		 'Ignore these chars
		 IF ASC(Undo2[OnTab].Typed[Undo2Count[OnTab]]) = 22 OR ASC(Undo2[OnTab].Typed[Undo2Count[OnTab]]) = 24
			  GOTO RedoIncrement
		 ENDIF
		 SELECT Undo2[OnTab].Press[Undo2Count[OnTab]]
				  CASE  1 'Char Undo
						  Loading = 1
						  SENDMESSAGE(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] ,Undo2[OnTab].pos[Undo2Count[OnTab]] +1)
						  CONTROLCMD w1,1,@RTDELETESEL
						  CONTROLCMD(w1,1,@RTGETLINE,cLine-1,line$,512)
						  Offset = Undo2[OnTab].Offset[Undo2Count[OnTab]]
						  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
						  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
						  ColourLineZ(rHandle,cLine-1,line$,Offset)
						  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SENDMESSAGE(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] ,Undo2[OnTab].pos[Undo2Count[OnTab]] )
						  Loading = 0

				  CASE  2 'Backspace Undo
				  CASE& 3 'Delete Undo
						  IF ASC(MID$(Undo2[OnTab].Was[Undo2Count[OnTab]-1],1,1)) = 13 AND ASC(MID$(Undo2[OnTab].Was[Undo2Count[OnTab]],1,1)) = 13
							  Undo2Count[OnTab] --
							  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)
						  ENDIF

						  Loading = 1
						  IF Undo2[OnTab].Press[Undo2Count[OnTab]]  = 2
							  'Insert before the carriage return
							  SENDMESSAGE(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] -1,Undo2[OnTab].pos[Undo2Count[OnTab]] -1)
						  ELSE
							  SENDMESSAGE(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] ,Undo2[OnTab].pos[Undo2Count[OnTab]] )
						  ENDIF

						  IF LEN(Undo2[OnTab].Was[Undo2Count[OnTab]]) = 1 AND ASC(MID$(Undo2[OnTab].Was[Undo2Count[OnTab]],1,1)) = 13
							  CONTROLCMD w1,1,@RTREPLACESEL,CHR$(10) '+ chr$(10)
						  ELSE
							  CONTROLCMD w1,1,@RTREPLACESEL,Undo2[OnTab].Was[Undo2Count[OnTab]]
						  ENDIF
						  CONTROLCMD(w1,1,@RTGETLINE,cLine-1,line$,512)
						  Offset = Undo2[OnTab].Offset[Undo2Count[OnTab]]
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)
						  GetTheScrollPos(w1,0,rHandle)
						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)

						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].pos[Undo2Count[OnTab]] ,Undo2[OnTab].pos[Undo2Count[OnTab]] )
						  Loading = 0

				  case  4 'Cut Undo
						  Loading = 1
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
						  CONTROLCMD w1,1,@RTREPLACESEL,UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]
						  Redo2Count[OnTab] ++
						  Redo2[OnTab].Press[Redo2Count[OnTab]] = Undo2[OnTab].Press[Undo2Count[OnTab]]

						  setscrollpos(w1,16,UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]-10)
						  sRange.Low = GETSCROLLPOS(w1,16) * 16
						  cLine = GETSCROLLPOS(w1,16) + 1
						  StoreLine = cLine
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)

						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)
						  GetTheScrollPos(w1,0,rHandle)
						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]],UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] )
						  setfocus w1,1

						  RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]    = UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]
						  RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]     = UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]       = UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].Length[Redo2Count[OnTab]]       = UndoBlock[OnTab].Length[Undo2Count[OnTab]]
						  RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]       = UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]
						  RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]  = UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]

						  Undo2Count[OnTab] --
						  if Undo2Count[OnTab] < 0 then Undo2Count[OnTab] = 0
						  Loading = 0
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

					case 5 'Paste Undo
						  Loading = 1
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] +1)
						  CONTROLCMD w1,1,@RTDELETESEL
						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  GetTheScrollPos(w1,1,rHandle)
						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
						  setfocus w1,1

						  Redo2Count[OnTab] ++
						  Redo2[OnTab].Press[Redo2Count[OnTab]]            = Undo2[OnTab].Press[Undo2Count[OnTab]]
						  RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]    = UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]
						  RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]     = UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]       = UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].Length[Redo2Count[OnTab]]       = UndoBlock[OnTab].Length[Undo2Count[OnTab]]
						  RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]       = UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]
						  RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]  = UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]
						  Undo2Count[OnTab] --
						  if Undo2Count[OnTab] < 0 then Undo2Count[OnTab] = 0

						  Loading = 0
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

					case 6 'Tab Undo
						  Loading = 1
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].EndPos[Undo2Count[OnTab]] )
						  CONTROLCMD w1,1,@RTDELETESEL
						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  GetTheScrollPos(w1,1,rHandle)
						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SendMessage(rHandle,EM_SETSEL,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] ,UndoBlock[OnTab].StartPos[Undo2Count[OnTab]] )
						  setfocus w1,1

						  Redo2Count[OnTab] ++
						  Redo2[OnTab].Press[Redo2Count[OnTab]]            = Undo2[OnTab].Press[Undo2Count[OnTab]]
						  RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]    = UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]
						  RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]     = UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]       = UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]
						  RedoBlock[OnTab].Length[Redo2Count[OnTab]]       = UndoBlock[OnTab].Length[Undo2Count[OnTab]]
						  RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]       = UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]
						  RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]  = UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]

						  Undo2Count[OnTab] --
						  if Undo2Count[OnTab] < 0 then Undo2Count[OnTab] = 0
						  Loading = 0
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

				  case  7 'Replace Undo
						  Loading = 1
						  int eendpos = len(Undo2[OnTab].Typed[Undo2Count[OnTab]])
						  eendpos = (eendpos + Undo2[OnTab].Offset[Undo2Count[OnTab]])

						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)

						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].Offset[Undo2Count[OnTab]],eendpos)
						  CONTROLCMD w1,1,@RTREPLACESEL,""

						  SendMessage(rHandle,EM_SETSEL,Undo2[OnTab].Offset[Undo2Count[OnTab]],Undo2[OnTab].Offset[Undo2Count[OnTab]])
						  CONTROLCMD w1,1,@RTREPLACESEL,Undo2[OnTab].Was[Undo2Count[OnTab]]

						  setscrollpos(w1,16,Undo2[OnTab].LineNo[Undo2Count[OnTab]]-2)
						  FirstVisLine = Undo2[OnTab].LineNo[Undo2Count[OnTab]] -2

                    int RedLine = CONTROLCMD w1,1,@RTLINEFROMCHAR,Undo2[OnTab].Offset[Undo2Count[OnTab]] + 1

						  for a = 1 to 30
							   setcontroltext(w1,a+1000,str$((FirstVisLine+2) + (a+1)))
							   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
                        if RedLine = (FirstVisLine+2) + (a+1)
							      setcontroltext(w1,a+1000,"> " +str$((FirstVisLine+2) + (a+1)))
							      SETCONTROLCOLOR w1,a+1000,Red,BackColour
                        endif
						  next a

						  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
						  cLine = GETSCROLLPOS(w1,16) + 1
						  StoreLine = cLine

						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)
						  GetTheScrollPos(w1,0,rHandle)
						  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SENDMESSAGE(rHandle,EM_SETSEL,eendpos,eendpos)
						  SETFOCUS w1,1

		 ENDSELECT
	 ENDIF

	 IF Undo2[OnTab].Press[Undo2Count[OnTab]] <> 0
		 LABEL RedoIncrement
		 Redo2Count[OnTab] ++
		 Redo2[OnTab].Press[Redo2Count[OnTab]]   = Undo2[OnTab].Press[Undo2Count[OnTab]]
		 Redo2[OnTab].Typed[Redo2Count[OnTab]]   = Undo2[OnTab].Typed[Undo2Count[OnTab]]
		 Redo2[OnTab].Pos[Redo2Count[OnTab]]     = Undo2[OnTab].Pos[Undo2Count[OnTab]]
		 Redo2[OnTab].LineNo[Redo2Count[OnTab]]  = Undo2[OnTab].LineNo[Undo2Count[OnTab]]
		 Redo2[OnTab].Offset[Redo2Count[OnTab]]  = Undo2[OnTab].Offset[Undo2Count[OnTab]]
		 Redo2[OnTab].Was[Redo2Count[OnTab]]     = Undo2[OnTab].Was[Undo2Count[OnTab]]
		 Redo2[OnTab].Colour[Redo2Count[OnTab]]  = Undo2[OnTab].Colour[Undo2Count[OnTab]]
		 Redo2[OnTab].Length[Redo2Count[OnTab]]  = Undo2[OnTab].Length[Undo2Count[OnTab]]
		 Undo2Count[OnTab] --
		 IF Undo2Count[OnTab] < 0 THEN Undo2Count[OnTab] = 0
	 ENDIF
	 Loading = 0

ENDSUB

sub DoRedo(hwnd:int,uMsg:int,wParam:int,lParam:pointer)
	 'Ignore these chars
	 if asc(Redo2[OnTab].Typed[Redo2Count[OnTab]] ) = 22 or asc(Redo2[OnTab].Typed[Redo2Count[OnTab]] ) = 24
		  goto UndoIncrement
	 endif

	 select Redo2[OnTab].Press[Redo2Count[OnTab]]
			  case 1 'Char Redo
					 SendMessage(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]] ,Redo2[OnTab].pos[Redo2Count[OnTab]] )
					 CONTROLCMD w1,1,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]
					 CONTROLCMD(w1,1,@RTGETLINE,cLine-1,line$,512)
					 Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]
					 eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
					 SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
					 ColourLineZ(rHandle,cLine-1,line$,Offset)
					 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
					 InvalidateRect(rHandle,0,true)
					 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					 SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]] +1,Redo2[OnTab].pos[Redo2Count[OnTab]] +1)

			  CASE 2 'Backspace Redo
					 SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]] -1,Redo2[OnTab].pos[Redo2Count[OnTab]] )
					 CONTROLCMD w1,1,@RTDELETESEL

			  CASE 3 'Delete Redo
					 SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]] ,Redo2[OnTab].pos[Redo2Count[OnTab]] +1)
					 CONTROLCMD w1,1,@RTDELETESEL

					 CONTROLCMD(w1,1,@RTGETLINE,cLine-1,line$,512)
					 Offset = Redo2[OnTab].Offset[Redo2Count[OnTab]]
					 eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
					 SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
					 ColourLineZ(rHandle,cLine-1,line$,Offset)
					 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
					 InvalidateRect(rHandle,0,true)
					 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					 SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].pos[Redo2Count[OnTab]] ,Redo2[OnTab].pos[Redo2Count[OnTab]] )

			  CASE 4 'Cut Redo
					 Loading = 1
					 eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
					 SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)
					 SENDMESSAGE(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] )
					 CONTROLCMD w1,1,@RTDELETESEL
					 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
					 InvalidateRect(rHandle,0,true)
					 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
					 Undo2Count[OnTab] ++
					 Undo2[OnTab].Press[Undo2Count[OnTab]]            = Redo2[OnTab].Press[Redo2Count[OnTab]]
					 UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]    = RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]
					 UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]     = RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]
					 UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]       = RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]
					 UndoBlock[OnTab].Length[Undo2Count[OnTab]]       = RedoBlock[OnTab].Length[Redo2Count[OnTab]]
					 UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]       = RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]
					 UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]
					 SENDMESSAGE(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] )
					 SETFOCUS w1,1
					 Redo2Count[OnTab]  --
					 IF Redo2Count[OnTab] < 0 THEN Redo2Count[OnTab] = 0
					 Loading = 0
					 RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

					CASE 5 'Paste Redo
						  Loading = 1
						  SENDMESSAGE(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] )
						  CONTROLCMD w1,1,@RTREPLACESEL,RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]
						  SENDMESSAGE(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] )

						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  GetTheScrollPos(w1,1,rHandle)
						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SendMessage(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] +1,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] +1)
						  setfocus w1,1

						  Undo2Count[OnTab] ++
						  Undo2[OnTab].Press[Undo2Count[OnTab]]            = Redo2[OnTab].Press[Redo2Count[OnTab]]
						  UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]    = RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]
						  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]     = RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]
						  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]       = RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]
						  UndoBlock[OnTab].Length[Undo2Count[OnTab]]       = RedoBlock[OnTab].Length[Redo2Count[OnTab]]
						  UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]       = RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]
						  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]

						  Redo2Count[OnTab]  --
						  'Redo2Count[OnTab]  --
						  if Redo2Count[OnTab] < 0 then Redo2Count[OnTab] = 0

						  Loading = 0
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam)

					case 6 'Tab Redo
						  Loading = 1
						  SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] )
						  CONTROLCMD w1,1,@RTREPLACESEL,RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]
						  SendMessage(rHandle,EM_SETSEL,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].StartPos[Redo2Count[OnTab]] )

						  eventMask = SendMessage(rHandle,EM_SETEVENTMASK,0,mask)
						  SendMessage(rHandle,WM_SETREDRAW,false,0)
						  FirstVisLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
						  GetTheScrollPos(w1,1,rHandle)
						  SendMessage(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SENDMESSAGE(rHandle,EM_SETSEL,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] ,RedoBlock[OnTab].EndPos[Redo2Count[OnTab]] )
						  SETFOCUS w1,1

						  Undo2Count[OnTab] ++
						  Undo2[OnTab].Press[Undo2Count[OnTab]]            = Redo2[OnTab].Press[Redo2Count[OnTab]]
						  UndoBlock[OnTab].UndoCount[Undo2Count[OnTab]]    = RedoBlock[OnTab].UndoCount[Redo2Count[OnTab]]
						  UndoBlock[OnTab].StartPos[Undo2Count[OnTab]]     = RedoBlock[OnTab].StartPos[Redo2Count[OnTab]]
						  UndoBlock[OnTab].EndPos[Undo2Count[OnTab]]       = RedoBlock[OnTab].EndPos[Redo2Count[OnTab]]
						  UndoBlock[OnTab].Length[Undo2Count[OnTab]]       = RedoBlock[OnTab].Length[Redo2Count[OnTab]]
						  UndoBlock[OnTab].LineNo[Undo2Count[OnTab]]       = RedoBlock[OnTab].LineNo[Redo2Count[OnTab]]
						  UndoBlock[OnTab].BlockText[0,Undo2Count[OnTab]]  = RedoBlock[OnTab].BlockText[0,Redo2Count[OnTab]]

						  Redo2Count[OnTab]  --
						  IF Redo2Count[OnTab] < 0 THEN Redo2Count[OnTab] = 0

						  Loading = 0
						  RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)

				  CASE  7 'Replace Redo
						  Loading = 1
						  INT eendpos = LEN(Redo2[OnTab].Typed[Redo2Count[OnTab]])
						  eendpos = (eendpos + Redo2[OnTab].Offset[Redo2Count[OnTab]])

						  eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
						  SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

						  SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].Offset[Redo2Count[OnTab]],eendpos)
						  CONTROLCMD w1,1,@RTREPLACESEL,""

						  SENDMESSAGE(rHandle,EM_SETSEL,Redo2[OnTab].Offset[Redo2Count[OnTab]],Redo2[OnTab].Offset[Redo2Count[OnTab]])
						  CONTROLCMD w1,1,@RTREPLACESEL,Redo2[OnTab].Typed[Redo2Count[OnTab]]

						  setscrollpos(w1,16,Redo2[OnTab].LineNo[Redo2Count[OnTab]]-2)
						  FirstVisLine = Redo2[OnTab].LineNo[Redo2Count[OnTab]] -2

                    int RedLine = CONTROLCMD w1,1,@RTLINEFROMCHAR,Redo2[OnTab].Offset[Redo2Count[OnTab]] + 1

						  for a = 1 to 30
							   setcontroltext(w1,a+1000,str$((FirstVisLine) + (a+1)))
							   SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
                        if RedLine + 1 = (FirstVisLine) + (a+1)
							      setcontroltext(w1,a+1000,"> " +str$((FirstVisLine) + (a+1)))
							      SETCONTROLCOLOR w1,a+1000,Red,BackColour
                        endif
						  next a

						  sRange.Low = (GETSCROLLPOS(w1,16) * 16) - 16
						  cLine = GETSCROLLPOS(w1,16) + 1
						  StoreLine = cLine
						  SENDMESSAGE(w1.hWnd,EM_SETSCROLLPOS,0,sRange,1)

						  GetTheScrollPos(w1,0,rHandle)
						  SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
						  InvalidateRect(rHandle,0,true)
						  SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
						  SENDMESSAGE(rHandle,EM_SETSEL,eendpos,eendpos)
						  SETFOCUS w1,1

	 ENDSELECT

	 IF Redo2[OnTab].Press[Redo2Count[OnTab]]  <> 0
		 LABEL UndoIncrement
		 Undo2Count[OnTab] ++
		 Undo2[OnTab].Press[Undo2Count[OnTab]]   = Redo2[OnTab].Press[Redo2Count[OnTab]]
		 Undo2[OnTab].Typed[Undo2Count[OnTab]]   = Redo2[OnTab].Typed[Redo2Count[OnTab]]
		 Undo2[OnTab].Pos[Undo2Count[OnTab]]     = Redo2[OnTab].Pos[Redo2Count[OnTab]]
		 Undo2[OnTab].LineNo[Undo2Count[OnTab]]  = Redo2[OnTab].LineNo[Redo2Count[OnTab]]
		 Undo2[OnTab].Offset[Undo2Count[OnTab]]  = Redo2[OnTab].Offset[Redo2Count[OnTab]]
		 Undo2[OnTab].Was[Undo2Count[OnTab]]     = Redo2[OnTab].Was[Redo2Count[OnTab]]
		 Undo2[OnTab].Colour[Undo2Count[OnTab]]  = Redo2[OnTab].Colour[Redo2Count[OnTab]]
		 Undo2[OnTab].Length[Undo2Count[OnTab]]  = Redo2[OnTab].Length[Redo2Count[OnTab]]
		 Redo2Count[OnTab]  --
		 IF Redo2Count[OnTab] < 0 THEN Redo2Count[OnTab] = 0
	 ENDIF

ENDSUB


SUB ColourTextScroll()

	 FirstVisLine = VAL(GETCONTROLTEXT w1,EDIT_1)-1

	 FOR a = 1 TO 30
		  SETCONTROLTEXT(w1,a+1000,STR$(FirstVisLine+(a)))
        SETCONTROLCOLOR w1,a+1000,RGB(0,0,0),BackColour
	 NEXT a

	 eventMask = SENDMESSAGE(rHandle,EM_SETEVENTMASK,0,mask)
	 SENDMESSAGE(rHandle,WM_SETREDRAW,false,0)

	 'GetTheScrollPos(w1,1,rHandle)
    NoNotify = 1
    showcursor(FALSE)
		 OnLine = FirstVisLine
		 FOR a = FirstVisLine -1 TO FirstVisLine + 29
           CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,512)
			  IF !len(LTRIM$(line$)) THEN GOTO CheckNextLine
			  Offset = SENDMESSAGE(rHandle,EM_LINEINDEX,a-1,0)
			  ColourLineX(rHandle,a-1,line$,Offset)
		 LABEL CheckNextLine
		 NEXT a
    showcursor(TRUE)
    NoNotify = 0

	 SENDMESSAGE(rHandle,WM_SETREDRAW,TRUE,0)
	 InvalidateRect(rHandle,0,true)
	 SENDMESSAGE(rHandle,EM_SETEVENTMASK,TRUE,ENM_CHANGE)
    IF FirstVisLine = 0
	    SETCONTROLTEXT(w1,4,"1")
    ELSE
	    SETCONTROLTEXT(w1,4,LTRIM$(STR$(FirstVisLine)))
    ENDIF

RETURN
ENDSUB




