jordi
Full Member
A simple solution is the smarter one.
Posts: 106
|
Post by jordi on Oct 21, 2020 7:46:34 GMT -5
Here is the editor. I didn't do the coloring because it needs to be editable. But added a retro loading effect. Someone may use this short code as a base for an editor: (contains half spanish half english comments, sorry)
NoMainWin REM *** CREAR VENTANA *** WindowWidth = 630 : WindowHeight = 480 UpperLeftX= 100 UpperLeftY= 100 TexteditorColor$ = "black" ForegroundColor$ = "yellow" GoSub [InitToolbar]
graphicbox #editorCodigo.grafico, 5, 30, 600, 380 texteditor #editorCodigo.editor, 5, 30, 600, 380 menu #editorCodigo, "Edit" ' Open "Basic Editor" for window as #editorCodigo #editorCodigo "trapclose [quit]" #editorCodigo "resizehandler [resizeWin]" print #editorCodigo, "font consolas 12" GoSub [MakeToolbar] print #editorCodigo.grafico,"hide" Wait
[quit] close #editorCodigo : End
[resizeWin] ret = SendMessage(hTB, TB.AUTOSIZE, 0, 0) gosub [newTooltipAreas] wait
[Cut] print #editorCodigo.editor, "!cut" Wait
[Copy] print #editorCodigo.editor, "!copy" Wait
[Paste] print #editorCodigo.editor, "!paste" Wait
[New] print #editorCodigo.editor, "!cls" Wait
[Open] 'abrir un dialogo para elegir el archivo de texto con el listado filedialog "Cargar programa", "*.txt", fileName$ ' lo siguiente solo se ejecuta si se ha seleccionado algo if fileName$<>"" then print #editorCodigo.editor,"!cls" open fileName$ for input as #programa while eof(#programa) = 0 'mientras no se termine el archivo line input #programa, archivoCargado$ 'leer una linea print #editorCodigo.editor, archivoCargado$ 'poner lo leido en la caja de texto wend 'evaluar la siguiente linea close #programa 'cerrar archivo end if REM * efecto visual * REM Shows a floating LOADING multicolor message, then hides the graphicbox DIM colores$(6) colores$(0)="red" colores$(1)="green" colores$(2)="blue" colores$(3)="yellow" colores$(4)="pink" colores$(5)="cyan" print #editorCodigo.editor,"!hide" print #editorCodigo.grafico,"show" print #editorCodigo.grafico, "down; fill black; flush" for i = 0 to 5 sleeptime = 300 CallDLL #kernel32, "Sleep", sleeptime As long, ret As void print #editorCodigo.grafico, "backcolor black" print #editorCodigo.grafico, "up; goto 80 80; down" print #editorCodigo.grafico, "color "+colores$(i) print #editorCodigo.grafico, "\LOADED" print #editorCodigo.grafico, "flush" next i print #editorCodigo.editor,"!show" print #editorCodigo.grafico,"hide" Wait
[Save] filedialog "Guardar programa", "*.txt", fileName$ if fileName$="" then return 'si no se entra un nombre, aborta fileName$ = fileName$+".txt" 'añade la extension de archivo open fileName$ for output as #programa 'crear el archivo #editorCodigo.editor, "!contents? texto$" print #programa, upper$(texto$) 'imprimir el listado en el archivo close #programa 'cerrar el archivo Wait
[Properties] 'mostrar numero de lineas 'espacio estimado en disco 'consumo estimado de eeprom o ram Wait
[Print] #editorCodigo.editor, "!contents? texto$" PRINTERDIALOG LPRINT texto$ DUMP Wait
REM *********************TOOLBAR******************** REM************************************************** 'All code after this point is needed 'to create the toolbar. Do not modify 'or remove anything below. [InitToolbar] 'call this sub before opening window like this: 'GoSub [InitToolbar] 'hidden buttons used by toolbar code: Button #editorCodigo.hide0, "", [Cut], UL, -400, -400, 0, 0 Button #editorCodigo.hide1, "", [Copy], UL, -400, -400, 0, 0 Button #editorCodigo.hide2, "", [Paste], UL, -400, -400, 0, 0 Button #editorCodigo.hide3, "", [separator3], UL, -400, -400, 0, 0 Button #editorCodigo.hide4, "", [New], UL, -400, -400, 0, 0 Button #editorCodigo.hide5, "", [Open], UL, -400, -400, 0, 0 Button #editorCodigo.hide6, "", [Save], UL, -400, -400, 0, 0 Button #editorCodigo.hide7, "", [separator7], UL, -400, -400, 0, 0 Button #editorCodigo.hide8, "", [Properties], UL, -400, -400, 0, 0 Button #editorCodigo.hide9, "", [separator9], UL, -400, -400, 0, 0 Button #editorCodigo.hide10, "", [Print], UL, -400, -400, 0, 0 RETURN
[MakeToolbar] hMain = Hwnd(#editorCodigo) 'get window handle
struct TBADDBITMAP, hInst as uLong, nID as uLong struct TBBUTTON, bmpID as long,cID as uLong,StateStyle as word,dwData as uLong,Str As Long struct rect, left as long, top as long, right as long, bottom As Long struct toolinfo, cbSize as long,uFlags as long, hwnd as uLong,uId as uLong, left as long, top as long,_ right as long, bottom as long,hInst as uLong, lpstrText$ as ptr
TB.ADDBUTTONS = 1044 : TB. = 1057 TB.SETTOOLTIPS = 1060 : TBSTYLE.BUTN = 0 TBSTYLE.SEP = 1 : TBSTYLE.FLAT = 2048 TBSTYLE.TOOLTIPS = 256: TBSTYLE.WRAPABLE = 512 TB.ADDBITMAP = 1043 : TB.BUTTONCOUNT = 1048 TB.GETBUTTON = 1047 : TB.GETITEMRECT = 1053 TBSTATE.ENABLED = 4 : TBSTATE.INDETERMINATE = 16
STD.CUT = 0 : STD.Copy = 1 STD.PASTE = 2 : STD.UNDO = 3 STD.REDOW = 4 : STD.DELETE = 5 STD.FILENEW = 6 : STD.FILEOPEN = 7 STD.FILESAVE = 8 : STD.PRINTPRE = 9 STD.PROPERTIES = 10 : STD.HELP = 11 STD.FIND = 12 : STD.REPLACE = 13 STD.PRINT = 14 : HINST.COMMCTRL= -1
TTS.ALWAYSTIP = 1 : TTS.NOPREFIX = 2 TTF.SUBCLASS = 16 : TTM.ADDTOOL = 1028 TTM.NEWTOOLRECT = 1030
calldll #comctl32, "InitCommonControls", r As void
hID0 = GetWindowLong(hWnd(#editorCodigo.hide0),_GWL_ID) hID1 = GetWindowLong(hWnd(#editorCodigo.hide1),_GWL_ID) hID2 = GetWindowLong(hWnd(#editorCodigo.hide2),_GWL_ID) hID3 = GetWindowLong(hWnd(#editorCodigo.hide3),_GWL_ID) hID4 = GetWindowLong(hWnd(#editorCodigo.hide4),_GWL_ID) hID5 = GetWindowLong(hWnd(#editorCodigo.hide5),_GWL_ID) hID6 = GetWindowLong(hWnd(#editorCodigo.hide6),_GWL_ID) hID7 = GetWindowLong(hWnd(#editorCodigo.hide7),_GWL_ID) hID8 = GetWindowLong(hWnd(#editorCodigo.hide8),_GWL_ID) hID9 = GetWindowLong(hWnd(#editorCodigo.hide9),_GWL_ID) hID10 = GetWindowLong(hWnd(#editorCodigo.hide10),_GWL_ID)
style=_WS_CHILD Or _WS_VISIBLE Or TBSTYLE.TOOLTIPS Or TBSTYLE.WRAPABLE _ Or TBSTYLE.FLAT uStructSize = Len(TBBUTTON.struct) CallDLL #comctl32, "CreateToolbarEx",_ hMain as uLong,style As long,0 As long,0 As long,0 As long,_ 0 As long,0 As long,0 As long,0 As long,0 As long,0 As long,_ 0 As long,uStructSize As long,hTB as uLong
'add the bitmap using system images TBADDBITMAP.hInst.struct = HINST.COMMCTRL calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBITMAP as long, 1 as long, TBADDBITMAP as struct, TBaddbmp as long
'add the buttons 'add button TBBUTTON.cID.struct = hID0 'button ID TBBUTTON.bmpID.struct = STD.CUT 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID1 'button ID TBBUTTON.bmpID.struct = STD.Copy 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID2 'button ID TBBUTTON.bmpID.struct = STD.PASTE 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add separator TBBUTTON.cID.struct = 0 'ID = 0 for separator TBBUTTON.bmpID.struct = 8 '8 pixels wide TBBUTTON.StateStyle.struct = TBSTATE.INDETERMINATE + (256 * TBSTYLE.SEP ) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID4 'button ID TBBUTTON.bmpID.struct = STD.FILENEW 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID5 'button ID TBBUTTON.bmpID.struct = STD.FILEOPEN 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID6 'button ID TBBUTTON.bmpID.struct = STD.FILESAVE 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add separator TBBUTTON.cID.struct = 0 'ID = 0 for separator TBBUTTON.bmpID.struct = 8 '8 pixels wide TBBUTTON.StateStyle.struct = TBSTATE.INDETERMINATE + (256 * TBSTYLE.SEP ) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID8 'button ID TBBUTTON.bmpID.struct = STD.PROPERTIES 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add separator TBBUTTON.cID.struct = 0 'ID = 0 for separator TBBUTTON.bmpID.struct = 8 '8 pixels wide TBBUTTON.StateStyle.struct = TBSTATE.INDETERMINATE + (256 * TBSTYLE.SEP ) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long 'add button TBBUTTON.cID.struct = hID10 'button ID TBBUTTON.bmpID.struct = STD.PRINT 'ID of standard image TBBUTTON.StateStyle.struct = TBSTATE.ENABLED + (256 * TBSTYLE.BUTN) calldll #user32, "SendMessageA", hTB as uLong, _ TB.ADDBUTTONS as long, 1 as long, TBBUTTON as struct, r as long
gosub [AddTooltips] RETURN
[AddTooltips] style = _WS_POPUP or TTS.NOPREFIX or TTS.ALWAYSTIP hInstance = GetWindowLong(hMain,_GWL_HINSTANCE)
calldll #user32, "CreateWindowExA",_ _WS_EX_TOPMOST as long,_ "TOOLTIPS_CLASS32" as ptr,_ "" as ptr, style as long,_ _CW_USEDEFAULT as long,_CW_USEDEFAULT as long,_ _CW_USEDEFAULT as long,_CW_USEDEFAULT as long,_ hMain as uLong, 0 as long, hInstance as uLong,_ 0 as long,hwndTip as uLong
'THESE STRUCT MEMBERS ONLY NEED TO BE FILLED ONCE: toolinfo.cbSize.struct = Len(toolinfo.struct) toolinfo.uFlags.struct = TTF.SUBCLASS toolinfo.hwnd.struct = hTB
'THESE STRUCT MEMBERS NEED TO BE FILLED ANEW 'FOR EACH TOOTLIP ADDED:
'tooltip for button index 0 toolinfo.uId.struct = 0 toolinfo.lpstrText$.struct = "Cut" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 1 toolinfo.uId.struct = 1 toolinfo.lpstrText$.struct = "Copy" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 2 toolinfo.uId.struct = 2 toolinfo.lpstrText$.struct = "Paste" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 4 toolinfo.uId.struct = 4 toolinfo.lpstrText$.struct = "New" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 5 toolinfo.uId.struct = 5 toolinfo.lpstrText$.struct = "Open" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 6 toolinfo.uId.struct = 6 toolinfo.lpstrText$.struct = "Save" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 8 toolinfo.uId.struct = 8 toolinfo.lpstrText$.struct = "Properties" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
'tooltip for button index 10 toolinfo.uId.struct = 10 toolinfo.lpstrText$.struct = "Print" calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.ADDTOOL as long, 0 as long, toolinfo as struct, r as long
gosub [newTooltipAreas] RETURN
[newTooltipAreas] 'call when tooltips are created 'and when toolbar is resized For i = 0 To 10 calldll #user32, "SendMessageA", hTB as uLong, _ TB.GETITEMRECT as long, i as uLong, rect as struct, r as long toolinfo.left.struct = rect.left.struct toolinfo.top.struct = rect.top.struct toolinfo.right.struct = rect.right.struct toolinfo.bottom.struct = rect.bottom.struct toolinfo.uId.struct = i calldll #user32, "SendMessageA", hwndTip as uLong, _ TTM.NEWTOOLRECT as long, 0 as long, toolinfo as struct, r as long Next Return
Function SendMessage(hWin, msg, wParam, lParam) calldll #user32, "SendMessageA", hWin as uLong, msg As long, _ wParam As long, lParam As long, SendMessage As long End Function
Function GetWindowLong(hWin, type) calldll #user32, "GetWindowLongA",_ hWin as uLong,type As long,_ GetWindowLong as uLong End Function
'****** End Toolbar Code ****** '******************************
|
|