here's my new attempt for an "oxy editor" and only the files are "empty" after saving. perhaps anybody can check this code example for correction.
I've used a simple winapi+scintilla example and oxide example plus include files.
$ filename "t.exe"
includepath "inc/"
'#include "../../inc/RTL32.inc"
'#include "../../inc/RTL64.inc"
'include "inc/MinWin.inc"
include "scintilla.inc"
include "OxideUtil.inc"
'include "WinUtil.inc"
DECLARE FUNCTION GetDlgItem LIB "User32.dll" ALIAS "GetDlgItem" _
(BYVAL hDlg AS DWORD, BYVAL nIDDlgItem AS LONG) AS DWORD
%Buttoni = 1001
%Buttoni2 = 1002
%scintilla = 1003
%saveFile = 1004
%execFile = 1005
%load = 1006
#lookahead ' for procedures
s=error()
'
if s then
print s
goto endprog
end if
'==================
'GLOBAL DEFINITIONS
'==================
'=========
'MAIN CODE
'=========
dim cmdline as asciiz ptr, inst as sys
&cmdline=GetCommandLine
inst=GetModuleHandle 0
'
'WINDOWS
'-------
'
WinMain inst,0,cmdline,SW_NORMAL
endprog:
'RELEASE SYSTEM RESOURCES
'---------------------
'FreeMinWinLibraries
'===========
'END OF MAIN
'===========
'--------------------------------------------------------------------
Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
'====================================================================
WndClass wc
MSG wm
sys hwnd, wwd, wht, wtx, wty, tax, myButton, hFont
wc.style = CS_HREDRAW or CS_VREDRAW
wc.lpfnWndProc = @WndProc
wc.cbClsExtra =0
wc.cbWndExtra =0
wc.hInstance =inst
wc.hIcon=LoadIcon 0, IDI_APPLICATION
wc.hCursor=LoadCursor 0,IDC_ARROW
wc.hbrBackground = GetStockObject WHITE_BRUSH
wc.lpszMenuName =null
wc.lpszClassName = strptr "Demo"
RegisterClass (@wc)
Wwd = 640 : Wht = 480
Tax = GetSystemMetrics SM_CXSCREEN
Wtx = (Tax - Wwd) /2
Tax = GetSystemMetrics SM_CYSCREEN
Wty = (Tax - Wht) /2
hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
myButton = CreateWindowEx(0, _
"Button", _
"push me!", _
%WS_CHILD OR %WS_VISIBLE OR _
%BS_PUSHBUTTON OR %BS_FLAT, _
22, 20, _
80, 24, _
hWnd, %Buttoni, _
inst, 0)
SendMessage myButton, WM_SETFONT, hFont, TRUE '1
ShowWindow hwnd,SW_SHOW
UpdateWindow hwnd
'
sys bRet
'
do while bRet := GetMessage (@wm, 0, 0, 0)
if bRet = -1 then
'show an error message
else
TranslateMessage @wm
DispatchMessage @wm
end if
wend
End Function
dim as rect crect 'for WndProc and TimerProc
'------------------------------------------------------------------
function WndProc ( sys hWnd, wMsg, wParam, lparam ) as sys callback
'==================================================================
static as sys hdc,hw,ps,sx,sy
static as String txt,cr,o2dir,f,fi,fo,dir
static as PaintStruct Paintst
dim as sys mySci,hlibsci,i,nLen,myButton ',hwnd,inst
dim as string st, buffer
static char buf[256]
'==========
select wMsg
'==========
'----------------
case WM_CREATE
'================
hlibsci = LoadLibrary "SciLexer.dll"
GetClientRect hWnd,&cRect
'hlibsci = LoadLibrary "SciLexer.dll"
'print str(hlibsci)
'---------------------------------------// buttons ---------- //
mySci = CreateWindowEx(0, _
"Scintilla", _
"", _
%WS_CHILD OR %WS_VISIBLE OR _
%BS_PUSHBUTTON OR %BS_FLAT, _
10, 60, _
360, 320, _
hWnd, %scintilla, _
inst, 0)
'st="test me"
SendMessage mySci, %SCI_SetText, 0, StrPtr(st)
SendMessage mySci, %SCI_SetMarginWidthN, 0, 20
myButton = CreateWindowEx(0, _
"Button", _
"gettext", _
%WS_CHILD OR %WS_VISIBLE OR _
%BS_PUSHBUTTON OR %BS_FLAT, _
122, 22, _
80, 24, _
hWnd, %Buttoni2, _
inst, 0)
myButton = CreateWindowEx(0, _
"Button", _
"saveFile", _
%WS_CHILD OR %WS_VISIBLE OR _
%BS_PUSHBUTTON OR %BS_FLAT, _
242, 22, _
80, 24, _
hWnd, %saveFile, _
inst, 0)
myButton = CreateWindowEx(0, _
"Button", _
"Execution", _
%WS_CHILD OR %WS_VISIBLE OR _
%BS_PUSHBUTTON OR %BS_FLAT, _
332, 22, _
80, 24, _
hWnd, %execfile, _
inst, 0)
'myButton = CreateWindowEx(0, _
' "Button", _
' "load", _
' %WS_CHILD OR %WS_VISIBLE OR _
' %BS_PUSHBUTTON OR %BS_FLAT, _
' 422, 22, _
' 80, 24, _
' hWnd, %load, _
' inst, 0)
'-------------------- //
CASE WM_COMMAND
'-------------------- //
IF wparam = %Buttoni THEN
print "hello button"
END IF
'TexTbuffer ---
'only a test for getting the buffer ------------ //
IF wparam = %Buttoni2 THEN
print "hello button2"
mySci = GetDlgItem(hWnd, %scintilla)'
IF mySci = 0 THEN EXIT FUNCTION
nLen = SendMessage(mySci, %SCI_GETTEXTLENGTH, 0, 0)
Buffer = SPACE(nLen + 1)
SendMessage mySci, %SCI_GETTEXT, BYVAL LEN(Buffer), BYVAL STRPTR(Buffer)
mbox buffer 'only for test
a=compile buffer
b=0
b=call a
print "buffer compiling by command `compile` "+b
END IF
'--------- SAVE FILE ------------------ //
'SAVE FILE
IF wparam = %saveFile THEN
print "hello saveFile"
f=fo
if ShiftKey() or f=""
f=GetFileName fo,1
end if
if f then
fo=f
fi=f
'------------ PROBLEM ZONE ------------------ ? //
s=GetText mySci 'hchw[0]
putfile fo,s
SetWindowText hWnd, "Saved "+ClipName(f)
end if
print "execution: " + f
print f
print str(mySci)
Exec o2dir+"gxo2.exe","gxo2 "+f
END IF
'error 3: file empty or not found
'--------- SAVE FILE END ------------------ //
'
'--------- EXECUTION THE FILE ------------------ //
' EXECUTE
IF wparam = %execFile THEN
print "hello execution File!"
print "error 3: file is empty after saving, why?"
if fi=""
SendMessage hwnd,WM_COMMAND,%saveFile,0
else
'problem zone --------------------- ?
s=GetText mySci '%scintilla ' hw
'problem zone --------------------- ?
if len(s) then
putfile fi,s
f=fi
string m="!"
if CtrlKey
'CREATE INDEPENDENT BINARY
if ShiftKey
t="inc/RTL64.inc" 'CTRL-SHIFT-F5
else
t="inc/RTL32.inc" 'CTRL-F5
end if
s="$filename "+qu+o2dir+"_.exe"+qu+cr+
"include "+qu+o2dir+t+qu+cr+s
f=o2dir+"_.o2bas"
'------------ HOW TO SAVE THE TeXT TO THIS FILE ? ------- //
putfile f,s
'------------ HOW TO SAVE THE TeXT TO THIS FILE ? ------- //
m=""
elseif ShiftKey
'f="-c "+f 'SHIFT-F5 CREATE DEPENDENT BINARY
s="#file "+qu+o2dir+"_.exe"+qu+cr+s
f=o2dir+"_.o2bas"
putfile f,s
m=""
end if
print "exec follows"
'Exec o2dir+"co2.exe","co2 "+m+f
'------------------------------- EXECUTE ------- //
Exec o2dir+"gxo2.exe","gxo2 "+f
'------------------------------- EXECUTE ------- //
end if
end if
END IF
'--------------------- EXECUTION FILE END ------------- //
'---------------------- followed code only for test purpose ------ //
IF wparam = %load THEN
print "hello load File!"
case %load '1008 'F8
f=GetFileName fi,0
if f then
fi=f
fo=f
s=GetFile fi
le=len s
'SendMessage hchw[0],WM_SETTEXT,le,s
SendMessage mySci,WM_SETTEXT,le,s '%scintilla
end if
SetWindowText hwnd,"Loaded " ClipName(f)
END IF
'--------------
case WM_DESTROY
'===============
PostQuitMessage 0
'------------
case WM_PAINT
'============
'--------------
case WM_KEYDOWN
'==============
'============
Select wParam
'============
Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0 'ESCAPE
End Select
'--------
case else
'========
function=DefWindowProc hWnd,wMsg,wParam,lParam
end select
end function ' WndProc
1) type a code in the scintilla editor: for example
mbox "Hello oxygen friends"
go to savefile and do it.
the error file shows that the file is empty after execution.
the problem zones I have marked too in code example.
best regards, frank
X