• Welcome to Jose's Read Only Forum 2023.
 

GUI: ListView & RichEdit

Started by Zlatko Vid, September 01, 2020, 10:56:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

Here is simple example with ListView and Richedit
Also show how change color of text in rich edit control:

$ Filename "RichEdit1.exe" ' o2-043
include "RTL32.inc"
include "awinh037.inc"
#lookahead ' auto-declare procedures
INT win,wx=200,wy=200,ww=800,wh=620,wstyle = WS_MINMAXSIZE
INT button0, b0ID=100, lvControl, lvID = 1000 , static1, st1ID = 500
INT hRich, ,richID=400
% ENM_CHANGE = 1
'CHARFORMAT cf
'create window =======================================================
win = SetWindow("GUI-Aurel-ListView & RichEdit",wx,wy,ww,wh,0,wstyle)
'=====================================================================
INT bmp1 = LoadImage(0,"Richi.ico",1,16,16,80) ' for ICON
INT bmp2 = LoadImage(0,"showE.bmp",0,88,30,16) ' for BITMAP
'create static control -----------------------------------------------
static1 = SetStatic(win,20,8,460,14,"ListView And RichEdit Control in Oxygen Basic - by Aurel",0,0,st1ID)
ControlFont(static1, 15, 8, 400, "Verdana")

'create button---------------------------------------------------------
button0 = SetButton(win,480,4,92,32,"", 1409384576, 0x200, b0ID) ' as bmp button FLAT
SendMessage(button0, 247, 0, bmp2)

'create List View -------------------------------------------------------------------------
lvControl = SetListView(win, 20, 30, 400, 140, "Column1", 200, 1417740297 ,0x200,lvID)

'add new column to listView -> {AddListViewColumn hwnd, pos, width , text, flag}-----------
AddListViewColumn (lvControl, 2, 200,"Column_2",0 )

'add listview it'em {AddListViewItem hwnd, pos, text, icon} -> column 0 - zero based ------
AddListViewItem (lvControl, 0, "Text 1- Oxygen Basic", 0)
AddListViewItem (lvControl, 1, "Text 2- Oxygen Basic", 0)
AddListViewItem (lvControl, 2, "Text 3- Oxygen Basic", 0)
AddListViewItem (lvControl, 3, "Text 4- Oxygen Basic", 0)
AddListViewItem (lvControl, 4, "Text 5- Oxygen Basic", 0)
AddListViewItem (lvControl, 5, "Text 6- Oxygen Basic", 0)
'add second column item -  AddListViewSubItem{hwnd,pos,sub,text) -> column 1 -second column

AddListViewSubItem (lvControl,0, 1, "Text 0 - Power Basic")
AddListViewSubItem (lvControl,1, 1, "Text 1 - Power Basic")
AddListViewSubItem (lvControl,2, 1, "Text 2 - Power Basic")
AddListViewSubItem (lvControl,3, 1, "Text 3 - Power Basic")
AddListViewSubItem (lvControl,4, 1, "Text 4 - Power Basic")
AddListViewSubItem (lvControl,5, 1, "Text 5 - Power Basic")

'create RichEdit Control ///////////////////////////////////////////////////////////////////////////////
'INT reStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_SUNKEN
'INT reStyle = 0x508010C4 /:rc code line::
hRich = SetRichEdit(win, 20,174,500,400,"", WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_NOHIDESEL|ES_SUNKEN,0x200,richID)
ControlFont(hRich, 16, 8, 400, "Consolas") : SetRichEditBackColor hRich, RGB(250,244,179)
'SendMessage (hRich, EM_SETEVENTMASK, 0, ENM_CHANGE)
'SetEditSelection( hRich, 0, -1)
SendMessage hRich, WM_SETTEXT, 0, strptr "if var while "
CHARFORMAT cf

'SENDMESSAGE( hRich, EM_SETSEL, 0, -1 )
   cf.cbSize       = 60 'SizeOf(CHARFORMAT) 'Length of structure *must be set manually sizeOf() not work!
   cf.dwMask       = CFM_COLOR
   cf.crTextColor  = rgb(200,0,0)    'Set the new color value
   'cf.dwMask       = CFM_COLOR
 
'SendMessage(hRich, WM_SETREDRAW, -1, 0)
int cfres = SendMessage(hRich, EM_SETCHARFORMAT, SCF_ALL, cf)
'SendMessage(hRich, WM_SETREDRAW, -1, 0)
print "ChFORMAT: " + str(cfres)
print "CbSIZE:   " + str(cf.cbSize)
'UpdateWindow(win)


'setfocus hRich
'///////////////////////////////////////////////////////////////////////////////////////////////////////

'----------------------------------------------------------------------
Wait()  'message loop
'----------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg

Case WM_COMMAND
                 controlID = LoWord(wParam) 'get control ID
   notifyCode = HiWord(wParam) 'get notification message

             Select controlID
   CASE b0ID
                       

                 End Select
   
             
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION
'------------------------------------------------------------------------
'------------------------------------------------------------------------

Function SetEditSelection(INT eHandle, sStart, sEnd)
SendMessage( ehandle, EM_SETSEL, sstart, sEnd)
End Function

Zlatko Vid

small update
richedit control show colors
that block of code should be inside function/sub for use in loops

$ Filename "RichEdit1.exe" ' o2-043
include "RTL32.inc"
include "awinh037.inc"
#lookahead ' auto-declare procedures
INT win,wx=200,wy=200,ww=800,wh=620,wstyle = WS_MINMAXSIZE
INT button0, b0ID=100, lvControl, lvID = 1000 , static1, st1ID = 500
INT hRich, ,richID=400
% ENM_CHANGE = 1
'CHARFORMAT cf
'create window =======================================================
win = SetWindow("GUI-Aurel-ListView & RichEdit",wx,wy,ww,wh,0,wstyle)
'=====================================================================
INT bmp1 = LoadImage(0,"Richi.ico",1,16,16,80) ' for ICON
INT bmp2 = LoadImage(0,"showE.bmp",0,88,30,16) ' for BITMAP
'create static control -----------------------------------------------
static1 = SetStatic(win,20,8,460,14,"ListView And RichEdit Control in Oxygen Basic - by Aurel",0,0,st1ID)
ControlFont(static1, 15, 8, 400, "Verdana")

'create button---------------------------------------------------------
button0 = SetButton(win,480,4,92,32,"", 1409384576, 0x200, b0ID) ' as bmp button FLAT
SendMessage(button0, 247, 0, bmp2)

'create List View -------------------------------------------------------------------------
lvControl = SetListView(win, 20, 30, 400, 140, "Column1", 200, 1417740297 ,0x200,lvID)

'add new column to listView -> {AddListViewColumn hwnd, pos, width , text, flag}-----------
AddListViewColumn (lvControl, 2, 200,"Column_2",0 )

'add listview it'em {AddListViewItem hwnd, pos, text, icon} -> column 0 - zero based ------
AddListViewItem (lvControl, 0, "Text 1- Oxygen Basic", 0)
AddListViewItem (lvControl, 1, "Text 2- Oxygen Basic", 0)
AddListViewItem (lvControl, 2, "Text 3- Oxygen Basic", 0)
AddListViewItem (lvControl, 3, "Text 4- Oxygen Basic", 0)
AddListViewItem (lvControl, 4, "Text 5- Oxygen Basic", 0)
AddListViewItem (lvControl, 5, "Text 6- Oxygen Basic", 0)
'add second column item -  AddListViewSubItem{hwnd,pos,sub,text) -> column 1 -second column

AddListViewSubItem (lvControl,0, 1, "Text 0 - Power Basic")
AddListViewSubItem (lvControl,1, 1, "Text 1 - Power Basic")
AddListViewSubItem (lvControl,2, 1, "Text 2 - Power Basic")
AddListViewSubItem (lvControl,3, 1, "Text 3 - Power Basic")
AddListViewSubItem (lvControl,4, 1, "Text 4 - Power Basic")
AddListViewSubItem (lvControl,5, 1, "Text 5 - Power Basic")

'create RichEdit Control ///////////////////////////////////////////////////////////////////////////////
'INT reStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_SUNKEN
'INT reStyle = 0x508010C4 /:rc code line::
hRich = SetRichEdit(win, 20,174,500,400,"", WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_NOHIDESEL|ES_SUNKEN,0x200,richID)
ControlFont(hRich, 16, 8, 400, "Consolas") : SetRichEditBackColor hRich, RGB(250,244,179)
'SendMessage (hRich, EM_SETEVENTMASK, 0, ENM_CHANGE)
'SetEditSelection( hRich, 0, -1)
SendMessage hRich, WM_SETTEXT, 0, strptr "if var while "
CHARFORMAT cf

SENDMESSAGE( hRich, EM_SETSEL, 0, 2 )
   cf.cbSize       = 60
   cf.dwMask       = CFM_COLOR
   cf.crTextColor  = rgb(0,0,200)    'new color
 
SendMessage(hRich, EM_SETCHARFORMAT, SCF_SELECTION, cf)
'SendMessage(hRich, EM_HIDESEL, 0, -1)
SENDMESSAGE( hRich, EM_SETSEL, 0, 0 )

SENDMESSAGE( hRich, EM_SETSEL, 3, 6 )
   cf.cbSize       = 60
   cf.dwMask       = CFM_COLOR
   cf.crTextColor  = rgb(0,160,0)    'new color
 
SendMessage(hRich, EM_SETCHARFORMAT, SCF_SELECTION, cf)
SENDMESSAGE( hRich, EM_SETSEL, 0, 0 )

SENDMESSAGE( hRich, EM_SETSEL, 7, 12 )
   cf.cbSize       = 60
   cf.dwMask       = CFM_COLOR
   cf.crTextColor  = rgb(200,0,0)    'new color
 
SendMessage(hRich, EM_SETCHARFORMAT, SCF_SELECTION, cf)
SENDMESSAGE( hRich, EM_SETSEL, 0, 0 )
'UpdateWindow(win)


'setfocus hRich
'///////////////////////////////////////////////////////////////////////////////////////////////////////

'----------------------------------------------------------------------
Wait()  'message loop
'----------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg

Case WM_COMMAND
                 controlID = LoWord(wParam) 'get control ID
   notifyCode = HiWord(wParam) 'get notification message

             Select controlID
   CASE b0ID
                       

                 End Select
   
             
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION
'------------------------------------------------------------------------
'------------------------------------------------------------------------

Function SetEditSelection(INT eHandle, sStart, sEnd)
SendMessage( ehandle, EM_SETSEL, sstart, sEnd)
End Function
   

Charles Pegge

The advantage RichEdit has over Scintilla is that it is part of Windows and supports Unicode.

Zlatko Vid

#3
...yes that is only advantage ...but Scintilla have large amounts of advantages over richedit control