• Welcome to PlanetSquires Forums.
 

FBR_IDE a freebasic simple editor.

Started by ron77, April 02, 2021, 11:17:00 PM

Previous topic - Next topic

ron77

hello...

i would like to try to create with WinFBE a notepad - like program (for windows) - any ideas / tips ? i'm not so new to freebasic itself yet i'm a bit newbie to WinFBE and GUI app development... i coded a GUI chatbot using WinFBE but that's mostly...

i plan to make the program under GNU licensed - i think i'll call it FB_R_WORD...

if any one wishes to join this project send me a private message :)

ron77

ron77

hello again... well i started my notepad - like program... and i got a first question - i tried to read the documentations in the help me files about WinFBE - what i miss the most is code examples like in the freebasic help files... i read searched about saving a file with a dialog box... yet no code examples... does anyone can give me an example on how can i open a dialog box?

José Roca

I don't have examples using WinFormsX. However, I have provided many examples using my WinFBX framework.


DIM wszFile AS WSTRING * 260 = "*.*"
DIM wszInitialDir AS STRING * 260 = CURDIR
DIM wszFilter AS WSTRING * 260 = "BAS files (*.BAS)|*.BAS|" & "All Files (*.*)|*.*|"
DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY
DIM cws AS CWSTR = AfxOpenFileDialog(hwnd, "", wszFile, wszInitialDir, wszFilter, "BAS", @dwFlags, NULL)
MessageBoxW(hwnd, cws, "File", MB_OK)


ron77

thanks... i looked at winfbx documentation and found some code examples like you gave...

here are a few click events code i wish to implement

Function Form1_Label1_Click( ByRef sender As wfxLabel, ByRef e As EventArgs ) As LRESULT
    dim s as HWND
    DIM wszFile AS WSTRING * 260 = "*.*"
    DIM wszInitialDir AS STRING * 260 = CURDIR
    DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
    DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY OR OFN_OVERWRITEPROMPT
    DIM cws AS CWSTR = AfxSaveFileDialog(s, "Save", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags)
    AfxMsg cws
   
   
   
    Function = 0
End Function

''
''
Function Form1_Label2_Click( ByRef sender As wfxLabel, ByRef e As EventArgs ) As LRESULT
    dim s as HWND
    DIM wszFile AS WSTRING * 260 = "*.*"
    DIM wszInitialDir AS STRING * 260 = CURDIR
    DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
    DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY
    DIM cws AS CWSTR = AfxOpenFileDialog(s, "", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags, NULL)
    MessageBoxW(s, cws, "Open", MB_OK)
   
    Function = 0
End Function


these code example works however they don't save or open nothing... i would like to use them some code that actually writes and reads text from a file text.

like this for reading a whole text file
'4 print whole text file on screen
SUB txtfile(f AS STRING)
CLS
DIM AS STRING buffer
DIM h AS LONG = FREEFILE()
OPEN f FOR BINARY AS #h
buffer = SPACE(LOF(h))
GET #h ,  , buffer
CLOSE #h
PRINT buffer
End SUB


and another one that writes to a file...

José Roca

> these code example works however they don't save or open nothing...

Of course not. The open file dialog only lets you to choose the file to open and retuns the path of the selected file. It is up to you what to do with it. In the console example that you have posted, OPEN f FOR BINARY AS #h, you will use the returned path as OPEN <selected file> FOR BINARY AS #h.

Because I always use Unicode, I don't use the FreeBasic intrinsic functions to deal with files, but classes like CTextStreamd and CFileStream:

CTextSTream: https://github.com/JoseRoca/WinFBX/blob/master/docs/File%20Management/CTextStream%20Class.md
CFileStream: https://github.com/JoseRoca/WinFBX/blob/master/docs/File%20Management/CFileStream%20Class.md

Support for Unicode is weak in FreeBasic. This is why I have provided extensive support for it in my WinFBX framework. If you don't need Unicode, then you will have to look at the FreeBasic examples and manual.

ron77

#5
here is a small DEMO of FBR_WORD

https://sendvid.com/l6z8nh93

Paul Squires

I am pretty sure that I started to create a small notepad example that ships with WinFBE. Look under \examples\Visual_Designer_Projects\Notepad

I am not at machine with WinFBE installed so I am not 100% sure that I shipped the example with the release code of WinFBE.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Yes. It is in Examples->Visual_Designer_Projects->Notepad.

ron77

hello i need some help with my notepad like program...

it seems when i open a text file and it displays on the textbox of the form i cannot edit it freely that is the curser won't make new lines out of the original text file i can't add to the text new lines it seem to be stuck...

here is the code for the frmMain.bas file where i do all of the open/save from text files - any help will be appreciated :)
SUB txtfile(f AS STRING)

' DIM AS STRING buffer
DIM h AS LONG = FREEFILE()
OPEN f FOR BINARY AS #h
' buffer = SPACE(LOF(h))
put #h ,  , text
CLOSE #h
' PRINT buffer
End SUB


function helpfile(lines as string) as string

    return lines & !"\r\n" '& !"\r\n"
'Dim As Long SelEnd = Len(Form1.Text1.Text)
'    SendMessage(form1.text1.hWindow, EM_SETSEL, SelEnd, SelEnd)
'    SendMessage form1.text1.hWindow, EM_SCROLLCARET, 0, 0
end function



function txtfileopen(f AS string) as string

DIM AS STRING buffer
DIM h AS LONG = FREEFILE()
OPEN f FOR BINARY AS #h
buffer = SPACE(LOF(h))
get #h ,  , buffer
CLOSE #h
    return buffer
End function


Function Form1_MainMenu_Click( ByRef sender As wfxMenuItem, ByRef e As EventArgs ) As LRESULT
    Select Case UCase(sender.Name)
        Case "MNUFILE"
           
        Case "MNUSAVE"
             text =  Form1.Text1.Text
            dim s as HWND
            DIM wszFile AS WSTRING * 260 = "*.*"
            DIM wszInitialDir AS STRING * 260 = CURDIR
            DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
            DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY OR OFN_OVERWRITEPROMPT
            DIM cws AS CWSTR = AfxSaveFileDialog(s, "Save", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags)
            AfxMsg cws
            txtfile(cws)
        Case "MNUOPEN"
            dim text2 as string, result as string
            dim s as HWND
            DIM wszFile AS WSTRING * 260 = "*.*"
            DIM wszInitialDir AS STRING * 260 = CURDIR
            DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
            DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY
            DIM cws AS CWSTR = AfxOpenFileDialog(s, "", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags, NULL)
            MessageBoxW(s, cws, "Open", MB_OK)
            text2 = txtfileopen(cws)
            result = helpfile(text2)
            Form1.Text1.Text = result
        Case "MNUENCRYPT"
            dim text1 as string = Form1.Text1.Text
            Form1.Text1.Text = ""
           
            Form1.Text1.Text = encode(text1)
        Case "MNUDECRYPT"
            dim text1 as string = Form1.Text1.Text
            Form1.Text1.Text = ""
           
            Form1.Text1.Text = decode(text1)
        Case Else
    End Select
    Function = 0
End Function

ron77

okay i changed the sub/functions of the read/write to/from text file with out binary yet the problem still persist

here is the updated code of frmMain.bas
dim shared as string text
'reDIM shared AS STRING buffer(0)
Const string1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Const string2 = "VsciBjedgrzyHalvXZKtUPumGfIwJxqOCFRApnDhQWobLkESYMTN"

SUB sAppend(arr() AS STRING , Item AS STRING)
REDIM PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
arr(UBOUND(arr)) = Item
END SUB

function encode(text AS STRING) as string
   Dim s As String
   Dim p As INTEGER
   Dim As String vector, key2
   
   vector = string1 : key2 = string2
   DIM currentChar AS INTEGER
   FOR i AS INTEGER = 0 TO len(text)
'     
      currentChar = ASC(MID(text, i, 1))

      IF (currentChar >= 65 AND currentChar <= 90) OR (currentChar >= 97 AND currentChar <= 122) THEN
        p = INSTR(vector, MID(text, i, 1))
        MID(text, i, 1) = MID(key2, p, 1)
      END IF
   
'       
     
   NEXT
   return text

   
END function

function decode(text AS STRING) as string
   Dim s As String
   Dim p As INTEGER
   Dim As String vector, key2
   
   vector = string2 : key2 = string1
   DIM currentChar AS INTEGER
   FOR i AS INTEGER = 0 TO len(text)
'     
      currentChar = ASC(MID(text, i, 1))

      IF (currentChar >= 65 AND currentChar <= 90) OR (currentChar >= 97 AND currentChar <= 122) THEN
        p = INSTR(vector, MID(text, i, 1))
        MID(text, i, 1) = MID(key2, p, 1)
      END IF
   
'       
     
   NEXT
   return text

   
END function


SUB txtfile(f AS STRING)

' DIM AS STRING buffer
DIM h AS LONG = FREEFILE()
OPEN f FOR output AS #h
' buffer = SPACE(LOF(h))
'while not eof(h)
' put #h ,  , text
    print #h, text
'    buffer = buffer
CLOSE #h
' PRINT buffer
End SUB


function helpfile(lines as string) as string

    return lines & !"\r\n" '& !"\r\n"
'Dim As Long SelEnd = Len(Form1.Text1.Text)
'    SendMessage(form1.text1.hWindow, EM_SETSEL, SelEnd, SelEnd)
'    SendMessage form1.text1.hWindow, EM_SCROLLCARET, 0, 0
end function



function txtfileopen(f AS string) as string

' reDIM AS STRING buffer(0)
    dim as string buffer, r
DIM h AS LONG = FREEFILE()
OPEN f FOR input AS #h
' buffer = SPACE(LOF(h))
while not eof(h)
input #h, r
    buffer = buffer & r & !"\r\n"
'    sappend(buffer(), r)
    wend
CLOSE #h
    return buffer
End function





''
''  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)



''
''
Function Form1_MainMenu_Click( ByRef sender As wfxMenuItem, ByRef e As EventArgs ) As LRESULT
    Select Case UCase(sender.Name)
        Case "MNUFILE"
           
        Case "MNUSAVE"
             text =  Form1.Text1.Text
            dim s as HWND
            DIM wszFile AS WSTRING * 260 = "*.*"
            DIM wszInitialDir AS STRING * 260 = CURDIR
            DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
            DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY OR OFN_OVERWRITEPROMPT
            DIM cws AS CWSTR = AfxSaveFileDialog(s, "Save", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags)
            AfxMsg cws
            txtfile(cws)
        Case "MNUOPEN"
            redim text2(0) as string
            dim as string r
            dim s as HWND
            DIM wszFile AS WSTRING * 260 = "*.*"
            DIM wszInitialDir AS STRING * 260 = CURDIR
            DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
            DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY
            DIM cws AS CWSTR = AfxOpenFileDialog(s, "", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags, NULL)
            MessageBoxW(s, cws, "Open", MB_OK)
            Form1.Text1.Text = txtfileopen(cws)
             
        Case "MNUENCRYPT"
            dim text1 as string = Form1.Text1.Text
            Form1.Text1.Text = ""
           
            Form1.Text1.Text = encode(text1)
        Case "MNUDECRYPT"
            dim text1 as string = Form1.Text1.Text
            Form1.Text1.Text = ""
           
            Form1.Text1.Text = decode(text1)
        Case Else
    End Select
    Function = 0
End Function

''
''
Function Form1_MainMenu_Popup( ByRef sender As wfxMenuItem, ByRef e As EventArgs ) As LRESULT
    Select Case UCase(sender.Name)
        Case "MNUFILE"
        Case Else
    End Select
    Function = 0
End Function

''
''
'Function Form1_Text1_TextChanged( ByRef sender As wfxTextBox, ByRef e As EventArgs ) As LRESULT
'    dim text4 as string = Form1.Text1.Text
'    if instr(text4, !"\r\n") then
'        Form1.Text1.Text = Form1.Text1.Text & !"\n"' & !"\r\n"
'    end if
   
'    Function = 0
'End Function


ron77


ron77

#11
hello i managed to solve the issue (bug) by using a shared dynamic array of string to load the text into the text box and now you can add new lines and edit the text :)

p.s. - or actually what solved the bug was a change in the textbox properties to change "acceptReturn" to true did the real trick :)

here is the updated code of frmMain.bas
dim shared as string text
reDIM shared AS STRING buffer(0)
Const string1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Const string2 = "VsciBjedgrzyHalvXZKtUPumGfIwJxqOCFRApnDhQWobLkESYMTN"

SUB sAppend(arr() AS STRING , Item AS STRING)
REDIM PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
arr(UBOUND(arr)) = Item
END SUB

function encode(text AS STRING) as string
   Dim s As String
   Dim p As INTEGER
   Dim As String vector, key2
   
   vector = string1 : key2 = string2
   DIM currentChar AS INTEGER
   FOR i AS INTEGER = 0 TO len(text)
'     
      currentChar = ASC(MID(text, i, 1))

      IF (currentChar >= 65 AND currentChar <= 90) OR (currentChar >= 97 AND currentChar <= 122) THEN
        p = INSTR(vector, MID(text, i, 1))
        MID(text, i, 1) = MID(key2, p, 1)
      END IF
   
'       
     
   NEXT
   return text

   
END function

function decode(text AS STRING) as string
   Dim s As String
   Dim p As INTEGER
   Dim As String vector, key2
   
   vector = string2 : key2 = string1
   DIM currentChar AS INTEGER
   FOR i AS INTEGER = 0 TO len(text)
'     
      currentChar = ASC(MID(text, i, 1))

      IF (currentChar >= 65 AND currentChar <= 90) OR (currentChar >= 97 AND currentChar <= 122) THEN
        p = INSTR(vector, MID(text, i, 1))
        MID(text, i, 1) = MID(key2, p, 1)
      END IF
   
'       
     
   NEXT
   return text

   
END function


SUB txtfile(f AS STRING)

' DIM AS STRING buffer
DIM h AS LONG = FREEFILE()
OPEN f FOR output AS #h
' buffer = SPACE(LOF(h))
'while not eof(h)
' put #h ,  , text
    print #h, text
'    buffer = buffer
CLOSE #h
' PRINT buffer
End SUB


function helpfile(lines as string) as string

    return lines & !"\r\n" '& !"\r\n"
'Dim As Long SelEnd = Len(Form1.Text1.Text)
'    SendMessage(form1.text1.hWindow, EM_SETSEL, SelEnd, SelEnd)
'    SendMessage form1.text1.hWindow, EM_SCROLLCARET, 0, 0
end function



sub txtfileopen(f AS string)

' reDIM AS STRING buffer(0)
    dim as string r
DIM h AS LONG = FREEFILE()
OPEN f FOR input AS #h
' buffer = SPACE(LOF(h))
while not eof(h)
    input #h, r
'    buffer = buffer & r & !"\r\n"
    sappend(buffer(), r)
    wend
CLOSE #h
'    return buffer
End sub





''
''  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)



''
''
Function Form1_MainMenu_Click( ByRef sender As wfxMenuItem, ByRef e As EventArgs ) As LRESULT
    Select Case UCase(sender.Name)
        Case "MNUFILE"
           
        Case "MNUSAVE"
             text =  Form1.Text1.Text
            dim s as HWND
            DIM wszFile AS WSTRING * 260 = "*.*"
            DIM wszInitialDir AS STRING * 260 = CURDIR
            DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
            DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY OR OFN_OVERWRITEPROMPT
            DIM cws AS CWSTR = AfxSaveFileDialog(s, "Save", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags)
            AfxMsg cws
            txtfile(cws)
        Case "MNUOPEN"
            redim text2(0) as string
            dim as string r
            dim s as HWND
            DIM wszFile AS WSTRING * 260 = "*.*"
            DIM wszInitialDir AS STRING * 260 = CURDIR
            DIM wszFilter AS WSTRING * 260 = "TXT files (*.TXT)|*.TXT|" & "All Files (*.*)|*.*|"
            DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY
            DIM cws AS CWSTR = AfxOpenFileDialog(s, "", wszFile, wszInitialDir, wszFilter, "TXT", @dwFlags, NULL)
            MessageBoxW(s, cws, "Open", MB_OK)
            txtfileopen(cws)
            for i as integer = 0 to ubound(buffer)
                Form1.Text1.Text = Form1.Text1.Text & buffer(i) & !"\r\n"
            next
            redim as string buffer(0)
           
        case "MNUCLOSE"
            Form1.Text1.Text = ""
             
        Case "MNUENCRYPT"
            dim text1 as string = Form1.Text1.Text
            Form1.Text1.Text = ""
           
            Form1.Text1.Text = encode(text1)
        Case "MNUDECRYPT"
            dim text1 as string = Form1.Text1.Text
            Form1.Text1.Text = ""
           
            Form1.Text1.Text = decode(text1)
        Case Else
    End Select
    Function = 0
End Function

''
''
Function Form1_MainMenu_Popup( ByRef sender As wfxMenuItem, ByRef e As EventArgs ) As LRESULT
    Select Case UCase(sender.Name)
        Case "MNUFILE"
        Case Else
    End Select
    Function = 0
End Function

''
''
'Function Form1_Text1_TextChanged( ByRef sender As wfxTextBox, ByRef e As EventArgs ) As LRESULT
'    dim text4 as string = Form1.Text1.Text
'    if instr(text4, !"\r\n") then
'        Form1.Text1.Text = Form1.Text1.Text & !"\n"' & !"\r\n"
'    end if
   
'    Function = 0
'End Function

''
''
Function Form1_Text1_KeyDown( ByRef sender As wfxTextBox, ByRef e As EventArgs ) As LRESULT
    dim text6 as string = Form1.Text1.Text
    if sender.AcceptsReturn then
       Form1.Text1.Text = text6 & !"\r\n"
    endif   
    Function = 0
End Function


Paul Squires

Attached is a pretty complete Notepad project that should help you.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

ron77

#13
hello i'm trying to add code syntax highlights to freebasic code in my text editor... i found a code that prints to the screen console a content of a bas file with syntax highlight but i don't know how to modify it in order to print bas code of freebasic into the text editor textbox...

here is the code i found:
https://pastebin.com/SmyNcLDH


any help will be appreciated
ron77

Paul Squires

If you don't want to use a 3rd party control like Scintilla to do your syntax coloring then you should investigate syntax coloring via a RichEdit control.  https://www.freebasic.net/forum/viewtopic.php?f=6&t=28802&p=276311

I do have a custom control about 80% written in FB that does syntax highlighting but it is not in a state that I can release. Maybe I will at some point in case another programmer would like to help enhance it. It is basically a stripped down version of Scintilla.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer