Editor question (scintilla)

Started by Frank Brübach, October 29, 2024, 06:55:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hello.. Charles..

I have a little Problem with a simple Editor and scintilla how to send a String properly to the Editor. The example Works but Something is wrong cause I have Got some hieroglyphs at the end of my String Text

O2 example

  ' franks-test scintilla editor,simple 2016, update 29-10-2024
  '
  $ filename "t.exe"
  'uses RTL32
  'uses RTL64
  uses winutil
  uses scintilla

  #lookahead ' for procedures

  %DEFAULT_GUI_FONT = 1234
  %IDCANCEL = 1002
  %IDC_EDIT = 80 '103 ' length of scintilla text but it's not working correct

  % SCI_SETTEXT 2001
  % SCI_GETTEXT 2002
  % SCI_GETTEXTLENGTH 2003
  % SCI_GETDIRECTPOINTER 2185

  % SCI_SETMARGINWIDTHN                      2242
  % SCI_STYLESETFORE                         2051
  % SCI_SETLEXER                             4001
  % SCLEX_CONTAINER                          0      ' // No lexer selected (default)

 
  dim cmdline as asciiz ptr, inst as sys
  @cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  WinMain inst,0,cmdline,SW_NORMAL

  '--------------------------------------------------------------------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  '====================================================================

' // Load Scintilla
   dword hSciLib
   hSciLib = LoadLibrary("lib/SciLexer.dll") '
   if hSciLib = %null then exit function
   
  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax
  with wc
  .style = CS_HREDRAW or CS_VREDRAW
  .lpfnWndProc = @WndProc
  .cbClsExtra =0
  .cbWndExtra =0   
  .hInstance =inst
  .hIcon=LoadIcon 0, IDI_APPLICATION
  .hCursor=LoadCursor 0,IDC_ARROW
  .hbrBackground = GetStockObject WHITE_BRUSH
  .lpszMenuName =null
  .lpszClassName = strptr "Demo"
  end with
  RegisterClass (@wc)
 
  Wwd = 420 : Wht = 300
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"Editor test",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  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,hInstance,sci 'static as sys hdc,hInstance
    static as String txt
    static as PaintStruct Paintst
 
    '==========
    select wMsg
    '==========
       
      '--------------
      case WM_CREATE
      '=============
 
        sci= LoadLibrary "lib/SciLexer.dll"
            if not sci then
              print "Unable to load Scintilla: SciLexer.dll"
            end if

      sys hInstance = GetWindowLongPtr(hWnd, GWL_HINSTANCE)

      GetClientRect  hWnd,&cRect

      sys hButton = CreateWindowEx(0, "Button", "&Quit", _
                   %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
                   80, 208, 80, 23, _
                   hWnd, %IDCANCEL, hInstance, null)

           
       sys hSci = CreateWindowEx(%WS_EX_CLIENTEDGE, "Scintilla", "", _
                   %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_VSCROLL OR %WS_HSCROLL OR %WS_TABSTOP OR _
                   %ES_MULTILINE OR %ES_WANTRETURN, _
                   10, 10, 312, 170, _
                   hWnd, %IDC_EDIT, hInstance, null)

            ' Check if the Scintilla control was created successfully
            IF hSci = 0 THEN
                mbox "Failed to create Scintilla control."
                Return -1
            END IF
     
        string strx 
        strx="hello scintilla how are you?" + chr(0) + cr
        strx=strx+"here I am staying for a while" + chr(34) + cr
       
        DIM samplePtr AS ZSTRING PTR
        samplePtr = STRPTR(strx)
        sys result =SendMessage(hSci,SCI_SETTEXT,%IDC_EDIT, strx ) ' no 0

        ' example works only here with -> %IDC_EDIT (not 0) but at the end I have got some hyroglyphs
        ' something must be missing
 
        result=SendMessage hSci, %SCI_SetMarginWidthN,0, 20 '%IDC_EDIT
        result=SendMessage hSci, %SCI_SETLEXER,  %SCLEX_CONTAINER, 0       
       
       case WM_COMMAND
            select case loword(wParam)
                case %IDCANCEL
                    select case hiword(wParam)
                        case BN_CLICKED
                            MessageBox(NULL, "Close Window", "Standard Button", MB_OK or MB_ICONINFORMATION)
                            SendMessage hwnd, WM_CLOSE, 0, 0
                    end select
            end select

      '-------------- 
      case WM_DESTROY
      '===============
         
      PostQuitMessage 0
       
      '------------
      case WM_PAINT
      '============

      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
       
      '--------------   
      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

Frank Brübach


' little update

' with chr(34) it's getting better but not perfect, have expand %IDC_EDIT = 120

        strx="hello scintilla how are you?" + chr(34) + cr 'chr(0)
        strx=strx+"here I am staying for a while" + chr(34) + cr
        strx=strx+"thor hulk batman, spiderman, hawkeye, ironman" + chr(34) + cr
       
        DIM samplePtr AS ZSTRING PTR
        samplePtr = STRPTR(strx)
        sys result =SendMessage(hSci,SCI_SETTEXT,%IDC_EDIT, strx ) ' no 0
       
        ' example works only here with -> %IDC_EDIT (not 0) but at the end I have got some hyroglyphs
        ' something must be missing
 
        result=SendMessage hSci, %SCI_SetMarginWidthN,0, 20 '%IDC_EDIT
        result=SendMessage hSci, %SCI_SETLEXER,  %SCLEX_CONTAINER, 0       
   

Zlatko Vid

wrong scintilla constant values

  ' franks-test scintilla editor,simple 2016, update 29-10-2024
  '
  $ filename "t.exe"
  'uses RTL32
  'uses RTL64
  uses winutil
  uses scintilla

  #lookahead ' for procedures

  % DEFAULT_GUI_FONT = 1234
  % IDCANCEL = 1002
  % IDC_EDIT = 80 '103 ' length of scintilla text but it's not working correct

'wrong  constant values
'% SCI_GETTEXT = 2182
'% SCI_SETTEXT = 2181
'% SCI_GETTEXTLENGTH = 2183

  % SCI_SETTEXT 2181
  % SCI_GETTEXT 2182
  % SCI_GETTEXTLENGTH 2183
  % SCI_GETDIRECTPOINTER 2185

  % SCI_SETMARGINWIDTHN                      2242
  % SCI_STYLESETFORE                         2051
  % SCI_SETLEXER                             4001
  % SCLEX_CONTAINER                          75      ' // No lexer selected (default)
  string CRLF = chr(13) + chr(10)
  string strx

 
  dim cmdline as asciiz ptr, inst as sys
  @cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  WinMain inst,0,cmdline,SW_NORMAL

  '--------------------------------------------------------------------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  '====================================================================

' // Load Scintilla
   dword hSciLib
   hSciLib = LoadLibrary("lib/SciLexer.dll") '
   if hSciLib = %null then exit function
   
  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax
  with wc
  .style = CS_HREDRAW or CS_VREDRAW
  .lpfnWndProc = @WndProc
  .cbClsExtra =0
  .cbWndExtra =0   
  .hInstance =inst
  .hIcon=LoadIcon 0, IDI_APPLICATION
  .hCursor=LoadCursor 0,IDC_ARROW
  .hbrBackground = GetStockObject WHITE_BRUSH
  .lpszMenuName =null
  .lpszClassName = strptr "Demo"
  end with
  RegisterClass (@wc)
 
  Wwd = 420 : Wht = 300
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"Editor test",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  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,hInstance,sci 'static as sys hdc,hInstance
    static as String txt
    static as PaintStruct Paintst
 
    '==========
    select wMsg
    '==========
       
      '--------------
      case WM_CREATE
      '=============
 
        sci= LoadLibrary "lib/SciLexer.dll"
            if not sci then
              print "Unable to load Scintilla: SciLexer.dll"
            end if

      sys hInstance = GetWindowLongPtr(hWnd, GWL_HINSTANCE)

      GetClientRect  hWnd,&cRect

      sys hButton = CreateWindowEx(0, "Button", "&Quit", _
                   %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
                   80, 208, 80, 23, _
                   hWnd, %IDCANCEL, hInstance, null)

           
       sys hSci = CreateWindowEx(%WS_EX_CLIENTEDGE, "Scintilla", "", _
                   %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_VSCROLL OR %WS_HSCROLL OR %WS_TABSTOP OR _
                   %ES_MULTILINE OR %ES_WANTRETURN,_
                   10, 10, 312, 170, _
                   hWnd, IDC_EDIT, hInstance, null)

            ' Check if the Scintilla control was created successfully
            IF hSci = 0 THEN
                mbox "Failed to create Scintilla control."
                Return -1
            END IF
 
       SendMessage hSci, SCI_SetMarginWidthN,0, 20 '%IDC_EDIT
       SendMessage hSci, SCI_SETLEXER,  SCLEX_CONTAINER, 0


     
        'string strx
        strx = "hello scintilla how are you?" + CRLF
        strx = strx + "here I am staying for a while..."
       
        'DIM samplePtr AS ZSTRING PTR
        'samplePtr = STRPTR(strx)
        SendMessage(hSci, SCI_SETTEXT, 0, strx) ' no 0

        ' example works only here with -> %IDC_EDIT (not 0) but at the end I have got some hyroglyphs
        ' something must be missing
 
           
       
       case WM_COMMAND
            select case loword(wParam)
                case %IDCANCEL
                    select case hiword(wParam)
                        case BN_CLICKED
                            MessageBox(NULL, "Close Window", "Standard Button", MB_OK or MB_ICONINFORMATION)
                            SendMessage hwnd, WM_CLOSE, 0, 0
                    end select
            end select

      '--------------
      case WM_DESTROY
      '===============
         
      PostQuitMessage 0
       
      '------------
      case WM_PAINT
      '============

      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
       
      '--------------   
      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

Frank Brübach

Thanks was my mistake copied another old scintilla File with constants.