SUB ProcessMessages(Hwnd%, Msg%, wParam%, lParam%)
'Process messages sent to the form... 
'Check message sent first... 
IF HotkeyFlag = True THEN
	EXIT SUB
END IF
SELECT CASE Msg%
	CASE WM_HOTKEY
		HotkeyFlag = True
		'Hotkey detected... 
		IF ConsoleState = cUp THEN
			LastWindow = GetForeGroundWindow
			SetForeGroundWindow(Form.Handle)
			AnimateDown
		ELSE
			AnimateUp
			SetForeGroundWindow(LastWindow)
		END IF
		HotkeyFlag = False
	CASE WM_TRAYICON
		HotkeyFlag = True
		IF (lParam% AND &HFFFF) = WM_LBUTTONDBLCLK THEN 'Dbl click... 
			'Show our thingy... 
			'Provided it's not already down... 
			IF ConsoleState = cUp THEN
				LastWindow = 0
				SetForeGroundWindow(Form.Handle)
				AnimateDown
			ELSE
				AnimateUp
			END IF
		END IF
		IF (lParam% AND &HFFFF) = WM_RBUTTONDOWN THEN 'Right click... 
			'Show the menu! 
			TrayPopup.Popup(Screen.MouseX,Screen.MouseY)
		END IF
		HotkeyFlag = False
END SELECT
HotkeyFlag = False
END SUB

SUB Initialise
'Set up everything, so it's all ready to go... 

SetDefaultSettings

'Choose file to load from, and load the options/bindings... 
IF Command$(1) = "" THEN
	'No file to load, use default... 
	IF FileExists(BaseDir$ + "default.cfw") THEN
		'Read in... 
		SaveFile$ = BaseDir$ + "default.cfw"
		LoadFile(BaseDir$ + "default.cfw")
	ELSE
		'Just set the default options... 
		CMessageBox("Welcome! You are new! This is the first time you have run Console for Windows, or you deleted the file DEFAULT.CFW. In any event, the default options are being used, and there are no bindings. To bring down the console, simply press CTRL+SHIFT+Q, and from there you can type options to customise the Console for Windows. This message will not show next time you run Console for Windows, unless something happens (like your computer crashes before you save the options).",bmMessage,btOk)
		SaveFile$ = BaseDir$ + "default.cfw"
	END IF
ELSE
	'File specified... try it! 
	IF FileExists(Command$(1)) THEN
		'Goody! Check it, then load... 
		Files.Open(Command$(1),fmOpenRead)
		IF Files.EOF THEN
			'Blank file... 
			CMessageBox("Welcome! You are new! This is the first time you have used this profile! Just to make sure you know, the default options are being used, and there are no bindings. To bring down the console, simply press CTRL+SHIFT+Q, and from there you can type OPTIONS to customise the Console for Windows. This message will not show next time you use this profile.",bmMessage,btOk)
			SaveFile$ = Commands$(1)
			Files.Close
		ELSE
			'Open the file! 
			Files.Close
			LoadFile(Command$(1))
			SaveFile$ = Commands$(1)
		END IF
	ELSE
		'Oh dear... does not exist! 
		IF CMessageBox("Oh no! The file you specified through the command line options to load the settings and bindings from does not exist! Was it your intention to create one? I can make one for you. Do you want me to?",bmError,btYesNo) = mrYes THEN
			'Do create one, and open it... 
			Files.Open(Command$(1),fmCreate)
			Files.Close
		END IF	
	END IF
END IF

'Load the control panel applet list... 
IF FileExists(BaseDir$ + "cpl.lst") THEN
	'Load control panel applet list... 
	Files.Open(BaseDir$ + "cpl.lst",fmOpenRead)
	Dummy$ = Files.ReadLine
	Dummy$ = Files.ReadLine
	FOR Dummy = 1 TO 50
		IF Files.EOF THEN
			CPTot = Dummy-1
			EXIT FOR
		END IF
		CPanels(Dummy).Name = Files.ReadLine
		CPanels(Dummy).File = Files.ReadLine
	NEXT Dummy
	Files.Close
END IF

'Apply the settings... 

'Appearance settings first... Don't ask me why! 
CLI.Color = Options.CLIBackColour
CLI.Font.Color = Options.CLIForeColour
CLI.Font.Name = RTRIM$(Options.Font)
CLI.Font.Size = Options.FontSize

Buffer.Font.Name = RTRIM$(Options.Font)
Buffer.Font.Size = Options.FontSize

Form.Width = Screen.Width
Form.Top = -(Options.DropPercentScreen)
Form.Left = 0
Form.Height = Options.DropPercentScreen

IF FileExists(RTRIM$(Options.BackGroundImage)) THEN
	Image.Handle = NViewLibLoad(RTRIM$(Options.BackGroundImage),0)
ELSE
	'Use black background... 
	Image.Tag = 1 'Ie. no image... 
END IF

'The hotkey... 
HKMods = 0
IF Options.KeyModCTRL = True THEN HKMods = HKMods OR MOD_CTRL : MsgStr$ = "CTRL+"
IF Options.KeyModALT = True THEN HKMods = HKMods OR MOD_ALT : MsgStr$ = MsgStr$ + "ALT+"
IF Options.KeyModSHIFT = True THEN HKMods = HKMods OR MOD_SHFT : MsgStr$ = MsgStr$ + "SHIFT+"
MsgStr$ = MsgStr$ + Options.Key

IF RegisterHotKey (Form.Handle, 0, HKMods, ASC(Options.Key)) = 0 THEN
	CMessageBox("Drat! The hotkey "+MsgStr$+" that you selected is already taken or can not be registered! This program will now exit. Drat it, again!",bmError,btOk)
	Application.Terminate
END IF

'Tray icons... 
NI.cbSize = SIZEOF(NI)
NI.hWnd = Form.Handle
NI.uID = Application.hInstance
NI.uFlags = NIM_ICON OR NIM_MESSAGE OR NIM_TIP
NI.hIcon = Application.Icon
NI.uCallBackMessage = WM_TRAYICON
NI.szTip = "Console for Windows 2"+CHR$(0)
IF Options.ShowTrayIcon = True THEN
	'Add tray icon... 
	TrayIcon = True
	Shell_NotifyIcon(NIM_ADD, NI)
ELSE
	TrayIcon = False
END IF

'Initialise History sub-system by adding items to it... 
'We should add items to it anyway... 
AddHistory("-- WELCOME TO THE CONSOLE FOR WINDOWS "+VersionNumber$,hReturn)
AddHistory("-- Written by Daniel Foote, 2000.",hReturn)
AddHistory("-- FREEWARE. Official Homepage: http://freefoote.dview.net/cfw",hreturn)
AddHistory("-- All systems are online and fully functional.",hReturn)
AddHistory("-- For help, type HELP.",hReturn)

'Finally: Unload all DLL's - only those needed will reload 
'at requirement. This will save MANY megabytes of memory. 
'Internal DLL's first... 
UNLOADLIBRARY "NVIEWLIB"

'Then Windows DLLs - around half not used at all. 
UNLOADLIBRARY "KERNEL32"
UNLOADLIBRARY "ADVAPI32"
UNLOADLIBRARY "COMCTL32"
UNLOADLIBRARY "GDI32"
UNLOADLIBRARY "ADVAPI32"
UNLOADLIBRARY "USER32"
UNLOADLIBRARY "COMDLG32"
UNLOADLIBRARY "SHLWAPI"
UNLOADLIBRARY "GDI32"
UNLOADLIBRARY "OLE32"
UNLOADLIBRARY "OLEAUT32"
UNLOADLIBRARY "SHELL32"
UNLOADLIBRARY "USER32"
UNLOADLIBRARY "WINMM"
UNLOADLIBRARY "WINSPOOL"
UNLOADLIBRARY "WSOCK32"

'That should have of fixed the initialisation... 

END SUB

SUB SetDefaultSettings
'Set all the default options... 

'Colours... 
Options.CommandMsgColour = &H0000FF
Options.ReturnedMsgColour = &H00FF00
Options.CLIBackColour = &H000000
Options.CLIForeColour = &HFFFFFF
Options.Font = "Courier New"
Options.FontSize = 10

'Background Images... 
Options.BackGroundImage = BaseDir$ + "console.gif"
Options.HowToShow = sStretch
Options.BackGroundColour = &H000000

'The hotkey... 
Options.KeyModCTRL = 1
Options.KeyModALT = 0
Options.KeyModSHIFT = 1
Options.Key = "Q"

'Animation options... 
Options.DropPercentScreen = 400
Options.DropPixelsPerIteration = 10

'General options... 
Options.AutoFillIn = True
Options.ShowTrayIcon = True
Options.ShowOnStartup = False
Options.SwapEnterForSpace = False
Options.ConfirmExit = True
Options.ConfirmShutdown = True

END SUB

SUB AnimateUp
'Animate the form up... 
Form.Top = -Options.DropPercentScreen
FOR Dummy = 0 TO (-Options.DropPercentScreen) STEP (-Options.DropPixelsPerIteration)
	Form.Top = Dummy
NEXT Dummy
ConsoleState = cUp
Form.Visible = False
END SUB

SUB AnimateDown
'Animate the form down... 
Form.Visible = True
FOR Dummy = (-Options.DropPercentScreen) TO 0 STEP (Options.DropPixelsPerIteration)
	Form.Top = Dummy
NEXT Dummy
ConsoleState = cDown
SetFocus(CLI.Handle)
END SUB

SUB AddHistory(History$ AS STRING, CType AS INTEGER)
DIM AHD AS SINGLE
DIM AHDX AS INTEGER
DIM AHDY AS INTEGER
DIM AHR AS QRECT

'Move all history up, and add the new item... 
FOR AHD = 50 TO 2 STEP -1
	History(AHD) = History(AHD-1)
NEXT AHD
History(1).History = History$
History(1).ColIndex = CType

'Draw all history... 
Buffer.Width = Canvas.Width
Buffer.Height = Canvas.Height

'Fix the background image... 
Buffer.FillRect(0,0,Buffer.Width,Buffer.Height,Options.BackGroundColour)
'Choose way to draw the background image... 
SELECT CASE Options.HowToShow
	CASE sTile
		'Tile image... 
		FOR AHDX = 0 TO Buffer.Width STEP Image.Width
			FOR AHDY = 0 TO Buffer.Height STEP Image.Height
				Buffer.Draw(AHDX,AHDY,Image.BMP)
			NEXT AHDY
		NEXT AHDX
	CASE sStretch
		'Stretch image... 
		AHR.Right = Buffer.Width
		AHR.Left = 0
		AHR.Top = 0
		AHR.Bottom = Buffer.Height
		Buffer.StretchDraw(AHR,Image.BMP)
	CASE sCenter
		'Center the image... 
		'Shrink to size if neccesary... 
		AHD = 1
		IF (Image.Width > Buffer.Width) OR (Image.Height > Buffer.Height) THEN
			'Image is too big for canvas! Shrink it! 
			'Get ready! 
			IF (Image.Width - Buffer.Width) > (Image.Height - Buffer.Height) THEN
				'Image is wider than higher... 
				AHD = 1 - ((Image.Width - Buffer.Width) / Image.Width)
			ELSE
				AHD = 1 - ((Image.Height - Buffer.Height) / Image.Height)
			END IF
		END IF
		AHR.Top = (Buffer.Height - (AHD * Image.Height)) / 2
		AHR.Left = (Buffer.Width - (AHD * Image.Width)) / 2
		AHR.Bottom = (AHD * Image.Height) + ((Buffer.Height - (AHD * Image.Height)) / 2)
		AHR.Right = (AHD * Image.Width) + ((Buffer.Width - (AHD * Image.Width)) / 2)
		IF Image.Tag <> 1 THEN
			Buffer.StretchDraw(AHR,Image.BMP)
		END IF
END SELECT

'Draw all the history onto it... 
AHD = 1
'AHDX = ((Buffer.Height-(Buffer.TextHeight("ThIs Is A tEsT")))-(CLI.Height)) 
AHDX = (Buffer.Height-CLI.Height)
FOR AHDY = AHDX TO 0 STEP (-(Buffer.TextHeight("ThIs Is A tEsT")+2))
	SELECT CASE History(AHD).ColIndex
		CASE hCommand
			AHDX = Options.CommandMsgColour
		CASE hReturn
			AHDX = Options.ReturnedMsgColour
	END SELECT
	Buffer.TextOut(0,AHDY,History(AHD).History,AHDX,-1)
	AHD = AHD+1
NEXT AHY

'Done! Repaint... 
RepaintCanvas

END SUB

SUB ProcessCommandLine(Key AS WORD, Shift AS INTEGER)
'Process anything in the command line... 
SELECT CASE Key
	CASE 13
		IF (Options.SwapEnterForSpace = True) AND (Key = 13) THEN
			CLI.Text = CLI.Text + " "
			CLI.SelStart = LEN(CLI.Text)
			EXIT SUB
		END IF
		IF (Key = 13) AND (Options.SwapEnterForSpace = False) THEN
			'User pressed enter. Process the command line... 
			ProcCmd2
		END IF
	CASE 32
		IF Options.SwapEnterForSpace = True THEN
			'User equivilent of pressed enter. 
			CLI.Text = LEFT$(CLI.Text,LEN(CLI.Text)-1)
			ProcCmd2
		END IF
	CASE 38
		CLI.Text = BFormatted$
		CLI.SelStart = LEN(BFormatted$)
	CASE 40
		IF CLI.Text = BFormatted$ THEN
			CLI.Text = ""
		END IF
	CASE ELSE
		'User did not press enter... 
		'Check to see if we can fill in blanks... 
		IF (Options.AutoFillIn = True) AND (Key <> 8) AND (Key <> 46) AND (CLI.Text <> "") THEN
			'However, don't fill in blanks if we are typing in internal 
			'commands. Why not? Think of BIND and BINDEDIT... 
			Dummy2 = CountTotalEntries(0)-1
			'Check array... 
			Dummy3 = LEN(CLI.Text)
			FOR Dummy = 1 TO Dummy2
				IF UCASE$(CLI.Text) = UCASE$(LEFT$(RTRIM$(Bound(Dummy).BoundName),Dummy3)) THEN
					'We has a match. Link it... 
					CLI.Text = CLI.Text + RIGHT$(RTRIM$(Bound(Dummy).BoundName),LEN(RTRIM$(Bound(Dummy).BoundName)) - Dummy3)
					CLI.SelStart = Dummy3
					CLI.SelLength = LEN(CLI.Text) - Dummy3
				END IF
			NEXT Dummy
			'Done! 
		END IF
		'Or see if it is a run command... 
		IF (UCASE$(LEFT$(CLI.Text,4)) = "RUN ") AND (Key <> 8) AND (Key <> 46) THEN
			RunFillOut
		END IF
		'Finally, check to see if it's an open command... 
		IF (UCASE$(LEFT$(CLI.Text,5)) = "OPEN ") AND (Key <> 8) AND (Key <> 46) THEN
			OpenFillOut
		END IF
END SELECT
END SUB

SUB ProcCmd2
'Process the command line properly... 
'Did we press enter without anything in the CLI? 
IF CLI.Text = "" THEN
	'Oops! Try typing something! 
	EXIT SUB
END IF
'Save contents of CLI... 
BFormatted$ = CLI.Text
Formatted$ = LTRIM$(RTRIM$(CLI.Text))
'Add CLI to history... 
AddHistory(CLI.Text,hCommand)
IF LEFT$(CLI.Text,1) = "!" THEN
	CLI.Text = ""
	EXIT SUB
END IF

CLI.Text = ""

'Split up string... 
SplitString(Formatted$)

'Ok, that done, parse request... 
SELECT CASE UCASE$(Commands$(1))
	CASE "CLS"
		'Clear the history... 
		FOR Dummy = 1 TO 50
			History(Dummy).History = ""
		NEXT Dummy
		AddHistory("    ",hReturn)
	CASE "ABOUT"
		AddHistory("Displaying about dialog...",hReturn)
		AnimateUp
		AboutForm.Show
	CASE "VER"
		AddHistory("Console for Windows "+VersionNumber$,hReturn)
		AddHistory("Written by Daniel Foote, 2000",hReturn)
		AddHistory("Official homepage: http://freefoote.dview.net/cfw",hReturn)
	CASE "EXIT"
		IF Options.ConfirmExit = True THEN
			AddHistory("Quering exit...",hReturn)
			IF CMessageBox("Are you sure you want to exit?",bmWarning,btYesNo) = mrYes THEN
				AddHistory("Exiting Console for Windows...",hReturn)
				ExitProgram
			ELSE
				AddHistory("Well... I guess you chose not to quit.",hReturn)
			END IF
		ELSE
			ExitProgram
		END IF
	CASE "QUIT"
		IF Options.ConfirmExit = True THEN
			IF CMessageBox("Are you sure you want to quit?",bmWarning,btYesNo) = mrYes THEN
				AddHistory("Quiting Console for Windows...",hReturn)
				ExitProgram
			ELSE
				AddHistory("Well... I guess you chose not to quit.",hReturn)
			END IF
		ELSE
			ExitProgram
		END IF
	CASE "BIND"
		'Show the bind form... 
		'Check to see if we have entered any data... 
		IF Commands$(2) = "" THEN
			'Simply show... 
			AnimateUp
			AddHistory("Displaying bind dialog...",hReturn)
			BindTime = 0
			ShowBindForm
		ELSE
			'Do things... differently... 
			ShowBindFilled
		END IF
	CASE "BINDEDIT"
		IF UCASE$(Commands$(2)) = "SORT" THEN
			AddHistory("Sorting bindings...",hReturn)
			AnimateUp
			SecSort
			AnimateDown
		ELSE
			AddHistory("Starting the Bind Editor...",hReturn)
			AnimateUp
			ShowBindEditor
		END IF
	CASE "SHUTDOWN"
		'This is easy... 
		IF Options.ConfirmShutDown = True THEN
			IF CMessageBox("Are you really sure you want to shutdown your computer?",bmWarning,btYesNo) = mrNo THEN
				EXIT SUB
			END IF
		END IF
		SaveFile(SaveFile$)
		AnimateUp
		SELECT CASE UCASE$(Commands$(2))
			CASE "REBOOT"
				AddHistory("Rebooting your computer...",hReturn)
				ExitWindowsEx(EWX_Reboot,0)
			CASE "RESTART"
				AddHistory("Restarting your computer...",hReturn)
				ExitWindowsEx(EWX_Reboot,0)
			CASE "LOGOFF"
				AddHistory("Logging off...",hReturn)
				ExitWindowsEx(EWX_Logoff,0)
			CASE ELSE
				AddHistory("Shutting down your computer...",hReturn)
				ExitWindowsEx(EWX_Shutdown,0)
		END SELECT
	CASE "OPTIONS"
		AddHistory("Showing options dialog...",hReturn)
		AnimateUp
		ShowOptions
	CASE "UP"
		'Hide console... 
		AddHistory("Retracting console...",hReturn)
		AnimateUp
		SetForeGroundWindow(LastWindow)
	CASE "EXEC"
		AddHistory("",hReturn)
	CASE "SHELL"
		AddHistory("Opening command line...",hReturn)
		RUN "COMMAND.COM"
		AnimateUp
	CASE "LIST"
		'List some bindings... do it elsewhere... 
		ListBindings
	CASE "RUN"
		'We pressed enter with a RUN command... 
		'So Do it! 
		IF FileExists(RIGHT$(BFormatted$,LEN(BFormatted$)-4)) THEN
			'Yes, run it... 
			AddHistory("Opening "+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+"...",hReturn)
			DummyPID = SHELL("START "+CHR$(34)+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+CHR$(34),0)
			AnimateUp
		ELSE
			'Uh oh... does not exist! 
			AddHistory("That file does not exist!",hReturn)
			IF CMessageBox("That file you just specified does not exist. Would you like me to create that file, and then open it? (Note: use this at your own risk. DO NOT try to create an .EXE file.) Before you do, please note that the file that will be created is: "+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+". So, do you want me to create it?",bmMessage,btYesNo) = mrYes THEN
				Files.Open(RIGHT$(BFormatted$,LEN(BFormatted$)-4),fmCreate)
				Files.Close
				AddHistory("Creating and opening "+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+"...",hReturn)
				DummyPID = SHELL("START "+CHR$(34)+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+CHR$(34),0)
				AnimateUp
			END IF
		END IF
	CASE "OPEN"
		'We pressed enter with an OPEN command... 
		'So Do it! 
		IF DirExists(RIGHT$(BFormatted$,LEN(BFormatted$)-5)) THEN
			'Yes, open it... 
			AddHistory("Opening "+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+"...",hReturn)
			DummyPID = SHELL("START "+CHR$(34)+UCASE$(RIGHT$(BFormatted$,LEN(BFormatted$)-5))+CHR$(34),0)
			AnimateUp
		ELSE
			AddHistory("That directory does not exist!",hReturn)
			IF CMessageBox("That directory you just specified does not exist. Would you like me to create that directory, and then open it? Before you do, please note that the directory that will be created is "+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+". So, do you want me to create it?",bmMessage,btYesNo) = mrYes THEN
				MKDIR(RIGHT$(BFormatted$,LEN(BFormatted$)-4))
				AddHistory("Creating and opening "+RIGHT$(BFormatted$,LEN(BFormatted$)-4)+"...",hReturn)
				DummyPID = SHELL("START "+CHR$(34)+UCASE$(RIGHT$(BFormatted$,LEN(BFormatted$)-5))+CHR$(34),0)
				AnimateUp
			END IF
		END IF
	CASE "HELP"
		CmdLineHelp
	CASE "TIME"
		AddHistory("The time is "+TIME$,hReturn)
	CASE "DATE"
		AddHistory("The date is "+DATE$,hReturn)
	CASE "SAVE"
		SaveFile(SaveFile$)
		AddHistory("Settings and bindings saved.",hReturn)
	CASE "STATS"
		AddHistory("General statistics:",hReturn)
		AddHistory("Total bindings: "+STR$(CountTotalEntries(0)-1)+"   Number left: "+STR$(400-(CountTotalEntries(0)-1)),hReturn)
		GlobalMemoryStatus(MStats)
		Dummy$ = Commarise$(MStats.dwTotalPhys)
		Dummy2$ = Commarise$(MStats.dwAvailPhys)
		Dummy3$ = Commarise$(MStats.dwTotalPhys - MStats.dwAvailPhys)
		AddHistory("System memory - Total: "+Dummy$+"  Free: "+Dummy2$+"  Used: "+Dummy3$,hReturn)
	CASE ELSE
		'Check internal database for matching entries... 
		Dummy2 = CountTotalEntries(0)
		FOR Dummy = 1 TO (Dummy2+1)
			IF UCASE$(Commands$(1)) = UCASE$(RTRIM$(Bound(Dummy).BoundName)) THEN
				'Found one!! 
				'Run it according to type... 
				SELECT CASE Bound(Dummy).BoundType
					CASE bExec
						'An executable... 
						IF FileExists(Bound(Dummy).BoundFile) THEN
							IF LEN(RTRIM$(Bound(Dummy).BoundName)) = LEN(BFormatted$) THEN
								Dummy$ = ""
							ELSE
								Dummy$ = " "+RIGHT$(BFormatted$,LEN(BFormatted$)-(LEN(RTRIM$(Bound(Dummy).BoundName))+1))
							END IF
							Dummy2$ = ""
							Dummy2$ = LEFT$(RTRIM$(Bound(Dummy).BoundFile),RINSTR(RTRIM$(Bound(Dummy).BoundFile),"\"))
							CHDIR Dummy2$
							AddHistory(RTRIM$(Bound(Dummy).RealName)+" is being run...",hReturn)
							RUN CHR$(34)+RTRIM$(Bound(Dummy).BoundFile)+CHR$(34)+Dummy$
						ELSE
							AddHistory("The program bound to this keyword does not exist!",hReturn)
							EXIT SUB
						END IF
					CASE bFile
						'A file... 
						IF FileExists(Bound(Dummy).BoundFile) THEN
							AddHistory("Opening "+RTRIM$(Bound(Dummy).RealName)+"...",hReturn)
							DummyPID = SHELL ("START "+CHR$(34)+RTRIM$(Bound(Dummy).BoundFile)+CHR$(34),0)
						ELSE
							AddHistory("The file bound to this keyword does not exist!",hReturn)
							EXIT SUB
						END IF
					CASE bFold
						'A folder... 
						'Select how to display it... 
						IF DirExists(Bound(Dummy).BoundFile) THEN
							AddHistory("Opening "+RTRIM$(Bound(Dummy).RealName)+"...",hReturn)
							SELECT CASE Bound(Dummy).ExtraInfo
								CASE 1
									'Explore the folder... 
									RUN "EXPLORER.EXE /e,/n,"+CHR$(34)+RTRIM$(Bound(Dummy).BoundFile)+CHR$(34)
								CASE 2
									'Open in DOS command line... 
									CHDIR RTRIM$(Bound(Dummy).BoundFile)
									RUN "COMMAND.COM"
								CASE ELSE
									'Simply open the folder... 
									DummyPID = SHELL ("START "+CHR$(34)+RTRIM$(Bound(Dummy).BoundFile)+CHR$(34),0)
							END SELECT
						ELSE
							AddHistory("The folder bound to this keyword does not exist!",hReturn)
							EXIT SUB
						END IF
					CASE bWeb
						'A web page... 
						AddHistory("Visiting "+RTRIM$(Bound(Dummy).RealName)+"...",hReturn)
						DummyPID = SHELL ("START "+RTRIM$(Bound(Dummy).BoundFile),0)
					CASE bCust
						'A custom command... 
						AddHistory("Running the command string "+RTRIM$(Bound(Dummy).RealName)+"...",hReturn)
						RUN RTRIM$(Bound(Dummy).BoundFile)
					CASE bCPanel
						'A control panel applet	 
						AddHistory("Opening "+RTRIM$(Bound(Dummy).RealName)+"...",hReturn)
						FOR Dummy2 = 1 TO CPTot
							IF RTRIM$(Bound(Dummy).BoundFile) = RTRIM$(CPanels(Dummy2).Name) THEN
								Dummy$ = RTRIM$(CPanels(Dummy2).File)
								RUN "CONTROL.EXE "+Dummy$
								EXIT FOR
							END IF
						NEXT Dummy2
				END SELECT
				'Hide on sucess... 
				AnimateUp
				EXIT SUB
			END IF
		NEXT Dummy
		'I guess that's not bound... 
		AddHistory("The command you entered is not bound to anything!",hReturn)
END SELECT

END SUB

SUB LoadFile(FileName$ AS STRING)
'Load a file into memory... 
StartProgress.Position = 0
IF FileExists(FileName$) THEN
	Files.Open(FileName$,fmOpenRead)
	StartProgress.Max = Files.LineCount

	'Read lines, and process... 
	FOR Dummy = 1 TO Files.LineCount
		'Read a line, test it. 
		Dummy$ = Files.ReadLine
		StartProgress.Position = StartProgress.Position + 1
		IF (Dummy$ <> "") AND (LEFT$(Dummy$,2) <> "//") THEN
			'Proceed... 
			Dummy2$ = LEFT$(Dummy$,INSTR(Dummy$,"=")-1)
			Dummy2 = LEN(Dummy$)
			Dummy3 = Dummy2 - INSTR(Dummy$,"=")
			SELECT CASE Dummy2$
				CASE "COMMANDMSGCOLOUR"
					Options.CommandMsgColour = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "RETURNEDMSGCOLOUR"
					Options.ReturnedMsgColour = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "CLIBACKCOLOUR"
					Options.CLIBackColour = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "CLIFORECOLOUR"
					Options.CLIForeColour = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "FONT"
					Options.Font = RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"="))
				CASE "FONTSIZE"
					Options.FontSize = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))

				CASE "BACKGROUNDIMAGE"
					Options.BackGroundImage = RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"="))
				CASE "HOWTOSHOW"
					Options.HowToShow = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "BACKGROUNDCOLOUR"
					Options.BackGroundColour = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))

				CASE "KEYMODCTRL"
					Options.KeyModCTRL = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "KEYMODALT"
					Options.KeyModAlt = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "KEYMODSHIFT"
					Options.KeyModShift = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "KEY"
					Options.Key = RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"="))

				CASE "DROPPERCENTSCREEN"
					Options.DropPercentScreen = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "DROPPIXELSPERITERATION"
					Options.DropPixelsPerIteration = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))

				CASE "AUTOFILLIN"
					Options.AutoFillIn = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "SHOWTRAYICON"
					Options.ShowTrayIcon = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "SWAPENTERFORSPACE"
					Options.SwapEnterForSpace = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "SHOWONSTARTUP"
					Options.ShowOnStartup = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "CONFIRMEXIT"
					Options.ConfirmExit = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
				CASE "CONFIRMSHUTDOWN"
					Options.ConfirmShutdown = VAL(RIGHT$(Dummy$,LEN(Dummy$)-INSTR(Dummy$,"=")))
			END SELECT
			IF LEFT$(Dummy$,4) = "BIND" THEN
				'It is a binding... Add binding as such... 
				'Split it up into little pieces first... 
				SplitString(Dummy$)

				'Then actually add it... 
				Dummy2 = CountTotalEntries(0)
				Bound(Dummy2).BoundName = Commands$(2)
				Bound(Dummy2).RealName = Commands$(3)
				Bound(Dummy2).BoundType = VAL(Commands$(4))
				Bound(Dummy2).BoundFile = Commands$(5)
				Bound(Dummy2).ExtraInfo = VAL(Commands$(6))
			END IF
		END IF
	NEXT Dummy
	Files.Close
END IF
END SUB

SUB SaveFile(FileName$ AS STRING)
'Save the file... 
IF FileExists(FileName$) THEN
	'Kill the file... 
	KILL FileName$
	'Then re-create it... 
	'Files.Close 
	Files.Open(FileName$,fmCreate)
	'Then save the options... 
	'Write the header... 
	Files.WriteLine("//Console for Windows 2 bindings and options file.")
	Files.WriteLine("//You can modify this, but don't change the format! (Not that it matters anyway...)")
	Files.WriteLine("//See the help file for more information about this file.")
	Files.WriteLine("")
	Files.WriteLine("//Note: 1 = True, 0 = False")

	'Then write the options... 
	Files.WriteLine("")
	Files.WriteLine("//OPTIONS")
	Files.WriteLine("COMMANDMSGCOLOUR="+STR$(Options.CommandMsgColour))
	Files.WriteLine("RETURNEDMSGCOLOUR="+STR$(Options.ReturnedMsgColour))
	Files.WriteLine("CLIBACKCOLOUR="+STR$(Options.CLIBackColour))
	Files.WriteLine("CLIFORECOLOUR="+STR$(Options.CLIForeColour))
	Files.WriteLine("FONT="+RTRIM$(Options.Font))
	Files.WriteLine("FONTSIZE="+STR$(Options.FontSize))

	'Background Images... 
	Files.WriteLine("")
	Files.WriteLine("BACKGROUNDIMAGE="+RTRIM$(Options.BackGroundImage))
	Files.WriteLine("HOWTOSHOW="+STR$(Options.HowToShow))
	Files.WriteLine("//How to show: 1 = Tile")
	Files.WriteLine("//             2 = Stretch")
	Files.WriteLine("//             3 = Center")
	Files.WriteLine("BACKGROUNDCOLOUR="+STR$(Options.BackGroundColour))

	'The hotkey... 
	Files.WriteLine("")
	Files.WriteLine("KEYMODCTRL="+STR$(Options.KeyModCTRL))
	Files.WriteLine("KEYMODALT="+STR$(Options.KeyModAlt))
	Files.WriteLine("KEYMODSHIFT="+STR$(Options.KeyModShift))
	Files.WriteLine("KEY="+Options.Key)

	'Animation options... 
	Files.WriteLine("")
	Files.WriteLine("DROPPERCENTSCREEN="+STR$(Options.DropPercentScreen))
	Files.WriteLine("//Note: the above item is actually pixels, not a percentage.")
	Files.WriteLine("DROPPIXELSPERITERATION="+STR$(Options.DropPixelsPerIteration))

	'General Options 
	Files.WriteLine("")
	Files.WriteLine("AUTOFILLIN="+STR$(Options.AutoFillIn))
	Files.WriteLine("SHOWTRAYICON="+STR$(Options.ShowTrayIcon))
	Files.WriteLine("SWAPENTERFORSPACE="+STR$(Options.SwapEnterForSpace))
	Files.WriteLine("SHOWONSTARTUP="+STR$(Options.ShowOnStartup))
	Files.WriteLine("CONFIRMEXIT="+STR$(Options.ConfirmExit))
	Files.WriteLine("CONFIRMSHUTDOWN="+STR$(Options.ConfirmShutdown))
	Files.WriteLine("")

	Files.WriteLine("//BINDINGS...")
	'Now the bindings... 
	Dummy2 = CountTotalEntries(0)
	FOR Dummy = 1 TO (Dummy2-1)
		'Write the bindings to file (This should be fun). 
		Files.WriteLine("BIND "+RTRIM$(Bound(Dummy).BoundName)+" "+CHR$(34)+RTRIM$(Bound(Dummy).RealName)+CHR$(34)+" "+STR$(Bound(Dummy).BoundType)+" "+CHR$(34)+RTRIM$(Bound(Dummy).BoundFile)+CHR$(34)+" "+STR$(Bound(Dummy).ExtraInfo))
	NEXT Dummy

	'Done... Write footer... 
	Files.WriteLine("")
	Files.WriteLine("//END OF .CFW FILE")
	Files.WriteLine("//PLEASE COME AGAIN!")
	Files.Close
END IF
END SUB

SUB CmdLineHelp
'All help to go in history has been moved to here. 
'This is to help with execution speed... rather than sort through 
'heaps of lines of help, just come here and fix it. 
'Simple... really... 
SELECT CASE UCASE$(Commands$(2))
	CASE "ADVANCED"
		'Show the HTML help file... 
		AddHistory("Opening HTML help file...",hReturn)
		DummyPID = SHELL("START "+CHR$(34)+BaseDir$+"help.htm"+CHR$(34),0)
		AnimateUp
	CASE "BIND"
		AddHistory("BIND SYNTAX",hReturn)
		AddHistory("The bind command syntax is hard to remember, so",hReturn)
		AddHistory("thus there is this help. It goes like this:",hReturn)
		AddHistory("BIND [alias] [real name] [bound file] [bound type] [D]",hReturn)
		AddHistory("All of this should be self explanatory. The D, if included, will",hReturn)
		AddHistory("display the bind dialog first. In case of an error,",hReturn)
		AddHistory("the bind dialog will be shown.",hReturn)
	CASE ELSE
		AddHistory("QUICK COMMAND REFERENCE",hReturn)
		AddHistory("BIND        - Bind new command",hReturn)
		AddHistory(" Note: Type HELP BIND for the syntax of the bind command.",hReturn)
		AddHistory("BINDEDIT    - Starts the bind editor",hReturn)
		AddHistory("OPTIONS     - Shows the options dialog",hReturn)
		AddHistory("QUIT/EXIT   - Exits this program",hReturn)
		AddHistory("SAVE        - Saves the bindings and options",hReturn)
		AddHistory("ABOUT       - Shows the about dialog",hReturn)
		AddHistory("STATS       - Shows some important statistics",hReturn)
		AddHistory("CLS         - Clears the history",hReturn)
		AddHistory("For a complete list of commands, type",hReturn)
		AddHistory(" HELP ADVANCED.",hReturn)
END SELECT
END SUB

SUB RunFillout
'Ahh! This should be REAL fun!! 
'What to do? Fill out a suggested file, based on what 
'you are typing in... slow, but neat! 
Dummy$ = ""
Dummy2$ = ""
Dummy3$ = ""
Dummy4 = 0
Dummy2$ = RIGHT$(CLI.Text,LEN(CLI.Text)-4)
IF Dummy2$ = "" THEN EXIT SUB
'IF INSTR(Dummy2$,":\") = 0 THEN EXIT SUB 
Dummy4 = RINSTR(Dummy2$,"\")
IF Dummy4 <> 0 THEN Dummy3$ = LEFT$(Dummy2$,Dummy4)
Dummy$ = DIR$(Dummy2$+"*",faAnyFile OR faDirectory)
IF Dummy$ = "" THEN EXIT SUB
DO
	'Check it... 
	IF LEFT$(UCASE$(Dummy3$+Dummy$),LEN(Dummy2$)) = UCASE$(Dummy2$) THEN
		'It's a match! 
		'Jab it in... 
		Dummy3 = LEN(CLI.Text)
		CLI.Text = CLI.Text + RIGHT$(Dummy3$+Dummy$,LEN(Dummy3$+Dummy$) - (Dummy3-4))
		CLI.SelStart = Dummy3
		CLI.SelLength = LEN(CLI.Text) - Dummy3
		EXIT DO
	END IF
	'Find the next file... 
	Dummy$ = DIR$
	IF Dummy$ = "" THEN EXIT DO
LOOP
END SUB

SUB OpenFillout
'Ahh! This should be REAL fun!! 
'What to do? Fill out a suggested directory, based on what 
'you are typing in... slow, but neat! 
Dummy$ = ""
Dummy2$ = ""
Dummy3$ = ""
Dummy4 = 0
Dummy2$ = RIGHT$(CLI.Text,LEN(CLI.Text)-5)

'Make sure it's a directory... 
IF INSTR(Dummy2$,":\") = 0 THEN EXIT SUB
IF Dummy2$ = "" THEN EXIT SUB

'Split up the first and second half... 
Dummy4 = RINSTR(Dummy2$,"\")
IF Dummy4 <> 0 THEN Dummy3$ = LEFT$(Dummy2$,Dummy4)

Dummy$ = DIR$(Dummy2$+"*",faDirectory)
IF Dummy$ = "" THEN EXIT SUB
DO
	'Check it... 
	IF (Dummy$ = ".") OR (Dummy$ = "..") THEN
		'Do nothing... 
	ELSE
		IF LEFT$(UCASE$(Dummy3$+Dummy$),LEN(Dummy2$)) = UCASE$(Dummy2$) THEN
			'It's a match! 
			'Jab it in... 
			Dummy3 = LEN(CLI.Text)
			CLI.Text = CLI.Text + RIGHT$(Dummy3$+Dummy$,LEN(Dummy3$+Dummy$) - (Dummy3-5))
			CLI.SelStart = Dummy3
			CLI.SelLength = LEN(CLI.Text) - Dummy3
			EXIT DO
		END IF
	END IF
	'Find the next file... 
	Dummy$ = DIR$
	IF Dummy$ = "" THEN EXIT DO
LOOP
END SUB

SUB ListBindings
'List the bindings based on the first few letters supplied... 
Dummy2 = CountTotalEntries(0)-1
Dummy4 = False
Dummy$ = UCASE$(RIGHT$(BFormatted$,LEN(BFormatted$)-5))
AddHistory("---SEARCH MATCHES FOR "+CHR$(34)+Dummy$+CHR$(34)+" :-",hReturn)
FOR Dummy = 1 TO Dummy2
	Dummy3 = False
	IF UCASE$(LEFT$(Bound(Dummy).BoundName,LEN(Dummy$))) = Dummy$ THEN
		'Then show it! 
		AddHistory(RTRIM$(Bound(Dummy).RealName)+" - "+RTRIM$(Bound(Dummy).BoundName),hReturn)
		Dummy3 = True
		Dummy4 = True
	END IF
	IF (UCASE$(LEFT$(Bound(Dummy).RealName,LEN(Dummy$))) = Dummy$) AND (Dummy3 = False) THEN
		'Then show it! 
		AddHistory(RTRIM$(Bound(Dummy).RealName)+" - "+RTRIM$(Bound(Dummy).BoundName),hReturn)
		Dummy4 = True
	END IF
NEXT Dummy
IF Dummy4 = False THEN
	AddHistory("No matches found!",hReturn)
END IF
AddHistory("---SEARCH COMPLETED---",hReturn)
END SUB