October 28, 2025, 05:00:19 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


TCCEdit, a Tiny C Compiler IDE with RAEdit

Started by WayneA, June 16, 2010, 12:52:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

WayneA

The RAEdit include:
'$Use "RAEdit.lib"
$Define EN_SELCHANGE 0x702
'Header converted for version 1.1.0.7
'Default colors
$Define DEFBCKCOLOR 0x00FFFFFF
$Define DEFTXTCOLOR 0x00000000
$Define DEFSELBCKCOLOR 0x00800000
$Define DEFSELTXTCOLOR 0x00FFFFFF
$Define DEFCMNTCOLOR 0x02008000
$Define DEFSTRCOLOR 0x00A00000
$Define DEFOPRCOLOR 0x000000A0
$Define DEFHILITE1 0x00F0C0C0
$Define DEFHILITE2 0x00C0F0C0
$Define DEFHILITE3 0x00C0C0F0
$Define DEFSELBARCOLOR 0x00C0C0C0
$Define DEFSELBARPEN 0x00808080
$Define DEFLNRCOLOR 0x00800000
$Define DEFNUMCOLOR 0x00808080

'Window styles
$Define STYLE_NOSPLITT 0x001 'No splitt button
$Define STYLE_NOLINENUMBER 0x002 'No linenumber button
$Define STYLE_NOCOLLAPSE 0x004 'No expand/collapse buttons
$Define STYLE_NOHSCROLL 0x008 'No orizontal scrollbar
$Define STYLE_NOVSCROLL 0x010 'No vertical scrollbar
$Define STYLE_NOHILITE 0x020 'No color iliting
$Define STYLE_NOSIZEGRIP 0x040 'No size grip
$Define STYLE_NODBLCLICK 0x080 'No action on double clicks
$Define STYLE_READONLY 0x100 'Text is locked
$Define STYLE_NODIVIDERLINE 0x200 'Blocks are not divided by line
$Define STYLE_NOBACKBUFFER 0x400 'Drawing directly to screen DC
$Define STYLE_NOSTATE 0x800 'No state indicator
$Define STYLE_DRAGDROP 0x1000 'Drag & Drop support, app must load ole
$Define STYLE_SCROLLTIP 0x2000 'Scrollbar tooltip
$Define STYLE_HILITECOMMENT 0x4000 'Comments are hilited
$Define STYLE_AUTOSIZELINENUM 0x8000 'Line number column autosizes

'Edit modes
$Define MODE_NORMAL 0 'Normal
$Define MODE_BLOCK 1 'Block select
$Define MODE_OVERWRITE 2 'Overwrite

'REM_COMMAND commands
$Define CMD_LEFT 1
$Define CMD_RIGHT 2
$Define CMD_LINE_UP 3
$Define CMD_LINE_DOWN 4
$Define CMD_PAGE_UP 5
$Define CMD_PAGE_DOWN 6
$Define CMD_HOME 7
$Define CMD_END 8
$Define CMD_INSERT 9
$Define CMD_DELETE 10
$Define CMD_BACKSPACE 11
'REM_COMMAND modifyers
$Define CMD_ALT 256
$Define CMD_CTRL 512
$Define CMD_SHIFT 1024

$Define WM_USER 0x400
$Define EM_REDO WM_USER+84

'Private edit messages
$Define REM_RAINIT WM_USER+9999 'wParam=0, lParam=pointer to controls DIALOG struct
$Define REM_BASE WM_USER+1000
$Define REM_SETHILITEWORDS REM_BASE+0 'wParam=Color, lParam=lpszWords
$Define REM_SETFONT REM_BASE+1 'wParam=nLineSpacing, lParam=lpRAFONT
$Define REM_GETFONT REM_BASE+2 'wParam=0, lParam=lpRAFONT
$Define REM_SETCOLOR REM_BASE+3 'wParam=0, lParam=lpRACOLOR
$Define REM_GETCOLOR REM_BASE+4 'wParam=0, lParam=lpRACOLOR
$Define REM_SETHILITELINE REM_BASE+5 'wParam=Line, lParam=Color
$Define REM_GETHILITELINE REM_BASE+6 'wParam=Line, lParam=0
$Define REM_SETBOOKMARK REM_BASE+7 'wParam=Line, lParam=Type
$Define REM_GETBOOKMARK REM_BASE+8 'wParam=Line, lParam=0
$Define REM_CLRBOOKMARKS REM_BASE+9 'wParam=0, lParam=Type
$Define REM_NXTBOOKMARK REM_BASE+10 'wParam=Line, lParam=Type
$Define REM_PRVBOOKMARK REM_BASE+11 'wParam=Line, lParam=Type
$Define REM_FINDBOOKMARK REM_BASE+12 'wParam=BmID, lParam=0
$Define REM_SETBLOCKS REM_BASE+13 'wParam=[lpLINERANGE], lParam=lpRABLOCKDEF
$Define REM_ISLINE REM_BASE+14 'wParam=Line, lParam=lpszDef
$Define REM_GETWORD REM_BASE+15 'wParam=BuffSize, lParam=lpBuff
$Define REM_COLLAPSE REM_BASE+16 'wParam=Line, lParam=lpRABLOCKDEF
$Define REM_COLLAPSEALL REM_BASE+17 'wParam=0, lParam=lpRABLOCKDEF
$Define REM_EXPAND REM_BASE+18 'wParam=Line, lParam=0
$Define REM_EXPANDALL REM_BASE+19 'wParam=0, lParam=0
$Define REM_LOCKLINE REM_BASE+20 'wParam=Line, lParam=TRUE/FALSE
$Define REM_ISLINELOCKED REM_BASE+21 'wParam=Line, lParam=0
$Define REM_HIDELINE REM_BASE+22 'wParam=Line, lParam=TRUE/FALSE
$Define REM_ISLINEHIDDEN REM_BASE+23 'wParam=Line, lParam=0
$Define REM_AUTOINDENT REM_BASE+24 'wParam=0, lParam=TRUE/FALSE
$Define REM_TABWIDTH REM_BASE+25 'wParam=nCars, lParam=TRUE/FALSE (Expand tabs)
$Define REM_SELBARWIDTH REM_BASE+26 'wParam=nWidt, lParam=0
$Define REM_LINENUMBERWIDTH REM_BASE+27 'wParam=nWidt, lParam=0
$Define REM_MOUSEWHEEL REM_BASE+28 'wParam=nLines, lParam=0
$Define REM_SUBCLASS REM_BASE+29 'wParam=0, lParam=lpWndProc
$Define REM_SETSPLIT REM_BASE+30 'wParam=nSplit, lParam=0
$Define REM_GETSPLIT REM_BASE+31 'wParam=0, lParam=0
$Define REM_VCENTER REM_BASE+32 'wParam=0, lParam=0
$Define REM_REPAINT REM_BASE+33 'wParam=0, lParam=TRUE/FALSE (Paint Now)
$Define REM_BMCALLBACK REM_BASE+34 'wParam=0, lParam=lpBmProc
$Define REM_READONLY REM_BASE+35 'wParam=0, lParam=TRUE/FALSE
$Define REM_INVALIDATELINE REM_BASE+36 'wParam=Line, lParam=0
$Define REM_SETPAGESIZE REM_BASE+37 'wParam=nLines, lParam=0
$Define REM_GETPAGESIZE REM_BASE+38 'wParam=0, lParam=0
$Define REM_GETCHARTAB REM_BASE+39 'wParam=nCar, lParam=0
$Define REM_SETCHARTAB REM_BASE+40 'wParam=nCar, lParam=nValue
$Define REM_SETCOMMENTBLOCKS REM_BASE+41 'wParam=lpStart, lParam=lpEnd
$Define REM_SETWORDGROUP REM_BASE+42 'wParam=0, lParam=nGroup (0-15)
$Define REM_GETWORDGROUP REM_BASE+43 'wParam=0, lParam=0
$Define REM_SETBMID REM_BASE+44 'wParam=nLine, lParam=nBmID
$Define REM_GETBMID REM_BASE+45 'wParam=nLine, lParam=0
$Define REM_ISCHARPOS REM_BASE+46 'wParam=CP, lParam=0, returns 1 if comment block, 2 if comment, 3 if string
$Define REM_HIDELINES REM_BASE+47 'wParam=nLine, lParam=nLines
$Define REM_SETDIVIDERLINE REM_BASE+48 'wParam=nLine, lParam=TRUE/FALSE
$Define REM_ISINBLOCK REM_BASE+49 'wParam=nLine, lParam=lpRABLOCKDEF
$Define REM_TRIMSPACE REM_BASE+50 'wParam=nLine, lParam=fLeft
$Define REM_SAVESEL REM_BASE+51 'wParam=0, lParam=0
$Define REM_RESTORESEL REM_BASE+52 'wParam=0, lParam=0
$Define REM_GETCURSORWORD REM_BASE+53 'wParam=BuffSize, lParam=lpBuff
$Define REM_SETSEGMENTBLOCK REM_BASE+54 'wParam=nLine, lParam=TRUE/FALSE
$Define REM_GETMODE REM_BASE+55 'wParam=0, lParam=0
$Define REM_SETMODE REM_BASE+56 'wParam=nMode, lParam=0
$Define REM_GETBLOCK REM_BASE+57 'wParam=0, lParam=lpBLOCKRANGE
$Define REM_SETBLOCK REM_BASE+58 'wParam=0, lParam=lpBLOCKRANGE
$Define REM_BLOCKINSERT REM_BASE+59 'wParam=0, lParam=lpText
$Define REM_LOCKUNDOID REM_BASE+60 'wParam=TRUE/FALSE, lParam=0
$Define REM_ADDBLOCKDEF REM_BASE+61 'wParam=0, lParam=lpRABLOCKDEF
$Define REM_CONVERT REM_BASE+62 'wParam=nType, lParam=0
$Define REM_BRACKETMATCH REM_BASE+63 'wParam=0, lParam=lpDef {[(,}]),_
$Define REM_COMMAND REM_BASE+64 'wParam=nCommand, lParam=0
$Define REM_CASEWORD REM_BASE+65 'wParam=0, lParam=lpWord
$Define REM_GETBLOCKEND REM_BASE+66 'wParam=Line, lParam=0

'Convert types
$Define CONVERT_TABTOSPACE 0
$Define CONVERT_SPACETOTAB 1
$Define CONVERT_UPPERCASE 2
$Define CONVERT_LOWERCASE 3


'Line hiliting
$Define STATE_HILITEOFF 0
$Define STATE_HILITE1 1
$Define STATE_HILITE2 2
$Define STATE_HILITE3 3
$Define STATE_HILITEMASK 3

'Bookmarks
$Define STATE_BMOFF 0x00
$Define STATE_BM1 0x10
$Define STATE_BM2 0x20
$Define STATE_BM3 0x30
$Define STATE_BM4 0x40
$Define STATE_BM5 0x50
$Define STATE_BM6 0x60
$Define STATE_BM7 0x70
$Define STATE_BM8 0x80
$Define STATE_BMMASK 0x0F0

'Line states
$Define STATE_LOCKED 0x100
$Define STATE_HIDDEN 0x200
$Define STATE_COMMENT 0x400
$Define STATE_DIVIDERLINE 0x800
$Define STATE_GARBAGE 0x80000000

'Character table types
$Define CT_NONE 0
$Define CT_CHAR 1
$Define CT_OPER 2
$Define CT_HICHAR 3
$Define CT_CMNTCHAR 4
$Define CT_STRING 5
$Define CT_CMNTDBLCHAR 6
$Define CT_CMNTINITCHAR 7

Type NMHDR
Dim hwndFrom As Int
Dim idfrom As Int
Dim code As Int
EndType

Type RAFONT
Dim hFont As UInt
Dim hIFont As UInt
Dim hLnrFont As UInt
EndType

Type RACOLOR
Dim bckcol As UInt 'Back color
Dim txtcol As UInt 'Text color
Dim selbckcol As UInt 'Sel back color
Dim seltxtcol As UInt 'Sel text color
Dim cmntcol As UInt 'Comment color
Dim strcol As UInt 'String color
Dim oprcol As UInt 'Operator color
Dim hicol1 As UInt 'Line hilite 1
Dim hicol2 As UInt 'Line hilite 2
Dim hicol3 As UInt 'Line hilite 3
Dim selbarbck As UInt 'Selection bar
Dim selbarpen As UInt 'Selection bar pen
Dim lnrcol As UInt 'Line numbers color
EndType

Type CHARRANGE
Dim cpMin As Int
Dim cpMax As Int
EndType

Type RASELCHANGE
Dim nmhdr As NMHDR
Dim chrg As CHARRANGE 'Current selection
Dim seltyp As Word 'SEL_TEXT or SEL_OBJECT
Dim nline As UInt 'Line number
Dim cpLine As UInt 'Character position of first character
Dim lpLine As UInt 'Pointer to line
Dim nlines As UInt 'Total number of lines
Dim nhidden As UInt 'Total number of hidden lines
Dim fchanged As UInt 'TRUE if changed since last
Dim npage As UInt 'Page number
Dim nWordGroup As UInt 'Hilite word group
EndType

$Define BD_NONESTING 1 'Set to true for non nested blocks
$Define BD_DIVIDERLINE 2 'Draws a divider line
$Define BD_INCLUDELAST 4 'lpszEnd line is also collapsed
$Define BD_LOOKAHEAD 8 'Look 500 lines ahead for the ending

Type RABLOCKDEF
Dim lpszStart As Pointer 'Block start
Dim lpszEnd As Pointer 'Block end
Dim lpszNot1 As Pointer 'Dont hide line containing this or set to NULL
Dim lpszNot2 As Pointer 'Dont hide line containing this or set to NULL
Dim flag As UInt
EndType

Type LINERANGE
Dim lnMin As UInt 'Starting line
Dim lnMax As UInt 'Ending line
EndType

Type BLOCKRANGE
Dim lnMin As UInt 'Starting line
Dim clMin As UInt 'Starting column
Dim lnMax As UInt 'Ending line
Dim clMax As UInt 'Ending column
EndType

$Define szRAEditClass "RAEdit"
$Define szEditClassName "RAEditChild"

'Declare Import,SetHiliteWords(hWnd As UInt,col As UInt,Words As String)
'Declare Import,SetBlockDef(hWnd As UInt,StartBlock As String,EndBlock As String,Flags As UInt)


TCCEdit

$Include "windows.inc"
$Include "RAEdit.inc"
AutoDefine "Off"
Enum menuIDs
mnuFileExit=100
mnuFileNew
mnuFileOpen
mnuFileSave
mnuFileSaveAs
mnuEditUndo
mnuEditRedo
mnuEditCut
mnuEditCopy
mnuEditPaste
mnuEditSelectAll
mnuEditFind
mnuEditReplace
mnuBuildCompile
mnuBuildRun
EndEnum
_LoadLibrary("RAEdit.dll")
Dim wndMain As Window
Dim toolArray[7] As Int
Dim crtFile As String
Dim OrigRAProc As UInt
toolArray[0]=mnuFileNew,mnuFileOpen,mnuFileSave,0,mnuEditCut,mnuEditCopy,mnuEditPaste
OpenWindow wndMain,0,0,0,0,@MinBox|@MaxBox|@Size,0,"TCC Edit - Untitled",&wndMainProc
SetWindowColor wndMain,_GetSysColor(15)
AttachMainMenu(wndMain)
SetClientSize(wndMain.hWnd,550,550)
InitControls(wndMain)
CenterWindow wndMain
WaitUntil wndMain=0
FreeLib("RAEdit.dll")
End

Sub wndMainProc
Dim l,t,w,h,tw,th,sw,sh As Int
Dim fPath As String
Select @Message
Case WM_SETFOCUS
SetFocus wndMain,1
Case @IDSize
GetClientSize wndMain,l,t,w,h
ControlCMD wndMain,999,@TBResize
ControlCMD wndMain,888,@SWResize
GetSize wndMain,l,t,tw,th,999
GetSize wndMain,l,t,sw,sh,888
SetSize wndMain,0,th,w,h-th-sh,1
Case @IDMenuPick
Select @MenuNum
Case mnuFileNew
SetCaption wndMain,"TCC Edit - Untitled"
SetControlText wndMain,1,""
crtFile=""
Case mnuFileOpen
fPath=FileRequest("Open a C file...",wndMain,True,"C Source Files(*.c)|*.c|C Header Files(*.h)|*.h|All files(*.*)|*.*||")
If fPath<>"" Then LoadFile(wndMain,1,fPath)
Case mnuFileSave
If crtFile="" Then
crtFile=FileRequest("Save As..",wndMain,False,"C Source Files(*.c)|*.c|C Header Files(*.h)|*.h|All files(*.*)|*.*||")
SaveFile(wndMain,1,crtFile)
Else
SaveFile(wndMain,1,crtFile)
EndIf
Case mnuFileSaveAs
crtFile=FileRequest("Save As..",wndMain,False,"C Source Files(*.c)|*.c|C Header Files(*.h)|*.h|All files(*.*)|*.*||")
SaveFile(wndMain,1,crtFile)
Case mnuEditCut
SendMessage(wndMain,WM_CUT,0,0,1)
Case mnuEditCopy
SendMessage(wndMain,WM_COPY,0,0,1)
Case mnuEditPaste
SendMessage(wndMain,WM_PASTE,0,0,1)
Case mnuEditSelectAll
SendMessage(wndMain,EM_SETSEL,0,-1,1)
Case mnuEditUndo
SendMessage(wndMain,EM_UNDO,0,0,1)
Case mnuEditRedo
SendMessage(wndMain,EM_REDO,0,0,1)
Case mnuBuildCompile
If crtFile="" Then
crtFile=FileRequest("Save As..",wndMain,False,"C Source Files(*.c)|*.c|C Header Files(*.h)|*.h|All files(*.*)|*.*||")
If SaveFile(wndMain,1,crtFile)=False Then Return
EndIf
SetControlText wndMain,888,"Compiling..."
_ShellExecute(wndMain.hWnd,"open","tcc.exe","\""+crtFile+"\"",GetStartPath,SW_HIDE)
SetControlText wndMain,888,"Compile done!"
Case mnuBuildRun
_ShellExecute(wndMain.hWnd,"open",ReturnName(crtFile)+".exe","",GetStartPath,SW_SHOWNORMAL)
Case mnuEditFind

Case mnuFileExit
CloseWindow wndMain
EndSelect
Case @IDControl
Select @ControlID
Case mnuFileNew
SetCaption wndMain,"TCC Edit - Untitled"
SetControlText wndMain,1,""
crtFile=""
Case mnuFileOpen
fPath=FileRequest("Open a C file...",wndMain,True,"C Source Files(*.c)|*.c|C Header Files(*.h)|*.h|All files(*.*)|*.*||")
If fPath<>"" Then LoadFile(wndMain,1,fPath)
Case mnuFileSave
If crtFile="" Then
crtFile=FileRequest("Save As..",wndMain,False,"C Source Files(*.c)|*.c|C Header Files(*.h)|*.h|All files(*.*)|*.*||")
SaveFile(wndMain,1,crtFile)
Else
SaveFile(wndMain,1,crtFile)
EndIf
Case mnuEditCut
SendMessage(wndMain,WM_CUT,0,0,1)
Case mnuEditCopy
SendMessage(wndMain,WM_COPY,0,0,1)
Case mnuEditPaste
SendMessage(wndMain,WM_PASTE,0,0,1)
Case 1
If @NotifyCode=EN_SELCHANGE Then
'If ##<RASELCHANGE>@lParam.nmhdr.code=EN_SELCHANGE Then
'SendMessage(wndMain,REM_SETBLOCKS,0,0,1)
SendMessage(wndMain,REM_BRACKETMATCH,0,0,1)
Dim szCmt="/*",szCmtEnd="*/" As String
SendMessage(wndMain,REM_SETCOMMENTBLOCKS,&szCmt,szCmtEnd,1)
EndIf
EndSelect
Case @IDCloseWindow
CloseWindow wndMain
EndSelect
EndSub

Sub RAEditHandler(hWnd As Int,uMsg As Int,wParam As Int,lParam As UInt),Int
Select uMsg
Case WM_KEYDOWN

EndSelect
Return _CallWindowProc(OrigRAProc,hWnd,uMsg,wParam,lParam)
EndSub

Sub InitControls(parent As Window)
Dim l,t,w,h,tw,th,sw,sh As Int
Dim szCmt="/*",szCmtEnd="*/" As String
'Dim BlockDef As RABLOCKDEF
Dim clr As RACOLOR
'BlockDef.lpszStart="{"
'BlockDef.lpszEnd="}"
'BlockDef.lpszNot1=0
'BlockDef.lpszNot2=0
'BlockDef.flag=BD_LOOKAHEAD
LoadToolBar(parent,GetStartPath+"Toolbar.bmp",999,toolArray,7,@TBTop|@TBTransparent|@TBFlat|@TBWrapable|@Border)
Control parent,@Status,"",0,0,0,0,0,888
GetClientSize parent,l,t,w,h
GetSize parent,l,t,tw,th,999
GetSize parent,l,t,sw,sh,888
ControlEx parent,szRAEditClass,"",0,th,w,h-th-sh,REM_AUTOINDENT|STYLE_AUTOSIZELINENUM|STYLE_DRAGDROP|STYLE_NOCOLLAPSE,0,1
SetFont parent,"Courier New",10,400,0,1
SendMessage parent,REM_SETHILITEWORDS,RGB(85,85,85),"#define #ifdef #ifndef #if #else #endif #include #pragma",1
'The following line shows that word definitions can be separated by a combination of different whitespace
SendMessage parent,REM_SETHILITEWORDS,RGB(255,0,0),"int\nlong\ndouble float\tword char unsigned void",1
SendMessage parent,REM_SETHILITEWORDS,RGB(0,0,255),"if else for while do return static global inline switch case default break struct typedef",1
'for BASIC comments use:
'SendMessage(parent,REM_SETCHARTAB,Asc("'"),CT_CMNTCHAR,1)
SendMessage(parent,REM_SETCHARTAB,Asc(";"),CT_OPER,1)
SendMessage(parent,REM_SETCHARTAB,Asc("/"),CT_CMNTDBLCHAR,1)
SendMessage(parent,REM_BRACKETMATCH,0,"[({,])},\n",1)
SendMessage(parent,REM_SETCOMMENTBLOCKS,&szCmt,szCmtEnd,1)
'SendMessage(parent,REM_ADDBLOCKDEF,null,null,1)
'SendMessage(parent,REM_ADDBLOCKDEF,null,&BlockDef,1)
SendMessage(parent,REM_GETCOLOR,0,&clr,1)
clr.bckcol=RGB(255,255,255)
SendMessage(parent,REM_SETCOLOR,0,&clr,1)
OrigRAProc=SendMessage(parent,REM_SUBCLASS,0,&RAEditHandler,1)
LoadFile(parent,1,NthField(_GetCommandLine()," ",1,True))
EndSub

Sub Instances(source As String,test As String),Int
Dim delpos=0,nexpos=InStr(source,test),count=0 As Int
While nexpos
delpos=nexpos
nexpos=InStr(source,test,delpos+1)
count++
WEnd
Return count
EndSub

Sub Replace(source As String,target As String,with As String,Opt startpos=0 As Int),Int
Dim pos As Int
pos=InStr(source,target,startpos)
If pos Then
source=Left$(source,pos-1)+with+Mid$(source,pos)
pos+=Len(with)+1
End If
Return pos
EndSub

Sub LoadFile(parent As Window,cid As Int,fileName As String),Int
Dim f As BFile
Dim buf As Pointer
Dim LFCount,pos As Int
Dim szCmt="/*",szCmtEnd="*/" As String
If fileName="" Then Return False
If OpenFile(f,fileName,"R")=0 Then
buf=New(Char,Len(f)+1)
__Read(f,*<String>buf,Len(f))
LFCount=Instances(*<String>buf,"\x0A")
If InStr(*<String>buf,"\x0D")=0 And Instances(*<String>buf,"\x0A") Then
SetControlText parent,888,"Converting all LF to CR..."
'MessageBox null,Str$(LFCount*2+Len(*<String>buf)+1),Str$(Len(f)+1)
SendMessage(parent,REM_READONLY,0,True,cid)
ReNew(buf,LFCount*2+Len(*<String>buf)+1,1)
pos=Replace(*<String>buf,"\x0A","\x0D")
While pos
Wait(True)
pos=Replace(*<String>buf,"\x0A","\x0D",pos)
WEnd
SendMessage(parent,REM_READONLY,0,False,cid)
SetControlText parent,888,""
'MessageBox null,Str$(Len(*<String>buf)),Str$(Len(f)+1)
EndIf
SetControlText parent,cid,#<String>buf
SetCaption parent,"TCC Edit - "+fileName
crtFile=fileName
Delete(buf)
CloseFile f
SendMessage(parent,REM_SETBLOCKS,0,0,cid)
SendMessage(parent,REM_SETCOMMENTBLOCKS,&szCmt,szCmtEnd,cid)
SendMessage(wndMain,EM_SETSEL,0,-1,1)
SendMessage(wndMain,REM_CONVERT,CONVERT_SPACETOTAB,null,1)
SendMessage(wndMain,EM_SETSEL,0,0,1)
Return True
EndIf
Return False
EndSub

Sub SaveFile(parent As Window,cid As Int,fileName As String),Int
Dim f As BFile
If fileName="" Then Return False
If OpenFile(f,fileName,"W")=0 Then
Write f,GetControlText(parent,cid)
CloseFile f
SetCaption wndMain,"TCC Edit - "+fileName
Return True
EndIf
Return False
EndSub

Sub AttachMainMenu(win As Window)
BeginMenu win
MenuTitle "&File"
MenuItem "&New\tCtrl+N",0,mnuFileNew
Separator
MenuItem "&Open\tCtrl+O",0,mnuFileOpen
MenuItem "&Save\tCtrl+S",0,mnuFileSave
MenuItem "Save As...",0,mnuFileSaveAs
Separator
MenuItem "E&xit\tAlt+F4",0,mnuFileExit
MenuTitle "&Edit"
MenuItem "&Undo\tCtrl+Z",0,mnuEditUndo
MenuItem "&Redo\tCtrl+Y",0,mnuEditRedo
Separator
MenuItem "&Cut\tCtrl+X",0,mnuEditCut
MenuItem "C&opy\tCtrl+C",0,mnuEditCopy
MenuItem "&Paste\tCtrl+V",0,mnuEditPaste
MenuItem "Select &All\tCtrl+A",0,mnuEditSelectAll
Separator
MenuItem "&Find\tCtrl+F",0,mnuEditFind
MenuItem "Replace\tCtrl+H",0,mnuEditReplace
MenuTitle "&Build"
MenuItem "Compile\tF5",0,mnuBuildCompile
MenuItem "Run\tF6",0,mnuBuildRun
EndMenu
AddAccelerator win,@FControl|@FVirtKey,Asc("N"),mnuFileNew
AddAccelerator win,@FControl|@FVirtKey,Asc("O"),mnuFileOpen
AddAccelerator win,@FControl|@FVirtKey,Asc("S"),mnuFileSave
'AddAccelerator win,@FControl|@FVirtKey,Asc("Z"),mnuEditUndo
'AddAccelerator win,@FControl|@FVirtKey,Asc("Y"),mnuEditRedo
AddAccelerator win,@FControl|@FVirtKey,Asc("F"),mnuEditFind
AddAccelerator win,@FControl|@FVirtKey,Asc("H"),mnuEditReplace
AddAccelerator win,@FVirtKey,0x74,mnuBuildCompile
AddAccelerator win,@FVirtKey,0x75,mnuBuildRun
EndSub

Sub NthField(Source As String,Delimiter As Char,fieldNum As Int,Opt quotes=False As Int),Heap
Dim rString As Pointer
Dim pos,field,quote As Int
field=0
rString=AllocHeap(Len(Source)+1)
quote=False
SetType rString,String
If InStr(Source,Chr$(Delimiter))=0 Then Return ""
For pos=0 To Len(Source)-1
If Source[pos]=34 Then
quote=(quote=False)
Else
If Source[pos]=Delimiter And quote=False Then
If field=fieldNum Then Return #rString
field++
#rString=""
Else
#rString+=Source[pos]
EndIf
EndIf
Next pos
Return #rString
EndSub

Sub SetClientSize(win As Int,w As Int,h As Int,Opt fmenu=0 As Int),Int
WINRECT rec
Int style,exstyle,err
style=0:exstyle=0:err=0
style=_GetWindowLong(win,GWL_STYLE)
If style
style=style & not(WS_OVERLAPPED)
exstyle=_GetWindowLong(win,GWL_EXSTYLE)
If style=0 | exstyle=0 Then Return 0
EndIf
err=_SetRect(rec,0,0,w,h)
If err
err=_AdjustWindowRectEx(rec,style,fmenu,exstyle)
If err
err=_SetWindowPos(win,0,0,0,rec.right+Int(ABS(rec.left)),rec.bottom+Int(ABS(rec.top)),SWP_NOMOVE)
EndIf
EndIf
Return err
EndSub

Sub ReNew(pnt As Int ByRef,elements As Int,Opt elesize=4 As Int),Int
Dim p As Int
'Total memory size is elesize*elements
p=_GlobalReAlloc(pnt,elesize*elements,GMEM_MOVEABLE|GMEM_ZEROINIT)
If p=0 Then
Return 0
EndIf
pnt=p
Return 1
EndSub

Sub ReturnName(Path As String),String
Dim last,late,i As Int
Dim rString As String
late=0
Do
last=late
late=InStr(Path,"\\",last+1)
Until late=0
rString=Mid$(Path,last+1)
For i=Len(rString)-1 to 0 Step -1
If rString[i]="."
rString[i]=0
i=0
EndIf
Next i
Return rString
EndSub



This app uses RAEdit, which can be obtained here (in the SimEd.zip) http://www.asmcommunity.net/board/index.php?topic=13935.0

Also, the toolbar.bmp that comes with EBasic needs to be in the same folder.

Because I didn't use the Streamin functionality supported by RAEdit, my load function does more work then it needed. I've never used streamin/out with the RichEdit control so I didn't bother using it for this test project. This was my test bed for figuring out RAEdit for possible use in my multi-language visual ide.

When I pick back up on this project, given how poorly my load function here works (handling of files without CR) I'll surely use the streamin method and will post it at that time.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.