* *

Coding

User

Welcome, Guest. Please login or register.
May 23, 2013, 12:35:51 AM

Login with username, password and session length

Menu

Stats

Members
  • Total Members: 491
  • Latest: TOPMO3
Stats
  • Total Posts: 12060
  • Total Topics: 1688
  • Online Today: 67
  • Online Ever: 150
  • (September 26, 2012, 02:29:19 PM)
Users Online
Users: 1
Guests: 56
Spiders: 4
Total: 61
zappa52
Google (2)
Daumoa
Baidu

Recent Topics

Author Topic: Using line numbers within a rich edit control.  (Read 1195 times)

0 Members and 3 Guests are viewing this topic.

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Using line numbers within a rich edit control.
« on: September 25, 2011, 07:50:54 AM »
Does anyone have any ideas on how to display line numbers within a rich edit control using Ibasic standard?

I have tried using the @RTGETLINECOUNT function to retrieve the number of lines in the edit control and display the
numbers in a separate window along side a rich edit control but this looks odd, as the window looks like it is not part
of the edit window. Is it possible to include line numbers within a rich edit control similar to the Ibasic program
editor?

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 191
  • Bananas: 4
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #1 on: September 25, 2011, 11:52:02 AM »
The only thing I found in the windows sdk about numbering in the rich edit control had to do with paragraph numbering and not line numbering.
I know that I and others who come from the IB STD/IB PRO background now use IWBasic and use the scintilla editor dll to create child windows with line numbering, keyword highlighting, and the likes.
 
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline zlatkoCB

  • Sr. Member
  • ****
  • Posts: 462
  • Bananas: 2
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #2 on: September 26, 2011, 10:28:24 AM »
Larry is right scintilla is far better option then build from scratch
custimized richedit.
But if you wish to try look this:
http://cboard.cprogramming.com/windows-programming/99118-line-number-rich-edit-control.html

Offline kryton9

  • Hero Member
  • *****
  • Posts: 961
  • Bananas: 6
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #3 on: September 27, 2011, 02:49:57 AM »
The only thing I found in the windows sdk about numbering in the rich edit control had to do with paragraph numbering and not line numbering.
I know that I and others who come from the IB STD/IB PRO background now use IWBasic and use the scintilla editor dll to create child windows with line numbering, keyword highlighting, and the likes.



Larry have you figured out how to get row colors with scintilla? Like we used to have with printouts, alternating white and light pale green or grey? Or as shown in this example for this javascript code highlighter:
http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html  you need to give it a second or two to load up and scroll down to see the highlighted code example.

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 191
  • Bananas: 4
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #4 on: September 27, 2011, 03:33:55 AM »
There was something way back that I did with greenbar.  Don't know if it was scintilla or not.  I'll see if I can find it.
LarryMc
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 191
  • Bananas: 4
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #5 on: September 27, 2011, 03:46:09 AM »
This should get you headed in the right direction:
Code: [Select]

Sub CreateGreenBars
   int i, iLines, iFirstChar, iLastChar
 iLines = SendMessage(hSci, %SCI_GetLineCount, 0, 0)
 For i = 0 to iLines - 1
  iFirstChar = SendMessage(hSci, %SCI_PositionFromLine, i, 0)
  iLastChar =   SendMessage(hSci, %SCI_GetLineEndPosition, i, 0)
  Select Case i % 6
   Case 0
   Case& 1
   Case& 2
    SendMessage(hSci, %SCI_StartStyling, iFirstChar, 31)
    SendMessage(hSci, %SCI_SetStyling, iLastChar-iFirstChar+2, %Style_Gray)
   Case 3
   Case& 4
   Case& 5
    SendMessage(hSci, %SCI_StartStyling, iFirstChar,31)
    SendMessage(hSci, %SCI_SetStyling, iLastChar-iFirstChar+2, %Style_Default)
  EndSelect
 Next i
EndSub

LarryMc
« Last Edit: September 27, 2011, 03:49:32 AM by Larry McCaughn »
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline kryton9

  • Hero Member
  • *****
  • Posts: 961
  • Bananas: 6
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #6 on: September 28, 2011, 02:28:53 AM »
Thanks Larry, I will give that a shot in the coming days. Thanks again.

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Re: Using line numbers within a rich edit control.
« Reply #7 on: December 15, 2011, 04:55:50 AM »
Finally getting back to the rich edit control line numbers problem, I am trying to figure out how to setup the left margin as shown in the following line of code ...

SendMessage( hRichEdit, EM_SETMARGINS, EC_LEFTMARGIN, 70 );

Taken from ...

http://cboard.cprogramming.com/windows-programming/99118-line-number-rich-edit-control.html

I would like to know how to set the variables for  EM_SETMARGINS and EC_LEFTMARGIN.

Do you have any example code to show how to do this?

I would appreciate any help you could offer.

Offline zlatkoCB

  • Sr. Member
  • ****
  • Posts: 462
  • Bananas: 2
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #8 on: December 15, 2011, 07:18:53 AM »
Hmm
I really dont know about example
of this type.
I think that i try long time ago
something similiar but with
listbox panel which present
line numbers but i quickly give up
from this.
About SendMessage you must know that CB require
SendMessage parentWindow,message,wparam,lparam,controlID
and i think that then must work.

Offline zlatkoCB

  • Sr. Member
  • ****
  • Posts: 462
  • Bananas: 2
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #9 on: December 15, 2011, 12:05:02 PM »
Do you mean something like this:
Code: [Select]
'a simple SDI editor (like notepad)
'using a multiline richedit control sized to the window
def win:window
def left,top,width,height,hprinter:int
def startpg,endpg,copies,collate:int
def filename,ln,printer:string
def file1:FILE
def buffer[32766]:ISTRING
Const EC_LEFTMARGIN = 0x1
Const EM_SETMARGINS = 0xD3
run = 0
'Open our main window, get its client size and create the control
window win,0,0,640,400,@SIZE|@MINBOX|@MAXBOX|@MAXIMIZED,0,"EDITOR V1.1",mainwindow
getclientsize win,left,top,width,height

CONTROL win,"RE,,left,top,width,height,@CTEDITMULTI|@HSCROLL|@VSCROLL,1"
SETFONT win,"Courier New",10,400,0,1
SendMessage win, EM_SETMARGINS,EC_LEFTMARGIN,80,1

menu win,"T,&File,0,0","I,&Load,0,1","I,&Save,0,2","I,&Print,0,4","I,&Quit,0,3"
insertmenu win,1,"T,&Options,0,0","I,Change Font,0,5"
SETCONTROLCOLOR win,1,0,RGB(255,255,255)
'process messages until somebody closes us
run = 1
waituntil run=0

closewindow win
end

'this is the handler subroutine for the window
'process @IDSIZE to size the edit control
'process the menus
'process @IDCLOSEWINDOW to quit the program
sub mainwindow
select @CLASS
case @IDCLOSEWINDOW
run = 0
case @IDSIZE
'size the edit control to match the client size of the window
'we use CONTROLEXISTS to verify the existance of the edit control
'because the first @IDSIZE message is sent while the window is being created
'but before we have a chance to add the edit control.
if CONTROLEXISTS(win,1)
getclientsize win,left,top,width,height
setsize win,left,top,width,height,1
endif
case @IDMENUPICK
select @MENUNUM
case 5
GOSUB changefont
case 4
'dump the edit control to the printer
GOSUB doprint
case 3
'quit the program
run = 0
case 2
'save the file
GOSUB dosave
case 1
'open a file
GOSUB doopen
endselect
endselect
return

'------------- DOOPEN ----------------
SUB doopen
filename = filerequest("Load File",win,1)
if(len(filename) > 0)
buffer = ""
if( openfile(file1,filename,"R") = 0)
do
if(read(file1,ln) = 0)
if(len(ln) <> 0)
buffer = buffer + ln + chr$(13) + chr$(10)
endif
endif
until eof(file1)
closefile file1
setcontroltext win,1,buffer
endif
endif
RETURN


'------------- DOSAVE -----------------
SUB dosave
filename = filerequest("Save File",win,0)
if(len(filename) > 0)
if(openfile(file1,filename,"W") = 0)
buffer = getcontroltext(win,1)
REM EDIT controls insert extra carriage returns at in every line
REM so remove them before saving
GOSUB RemoveCR
write file1,buffer
closefile file1
endif
endif
RETURN

'------------- DOPRINT ----------------
SUB doprint
startpg = 1
endpg = 1
copies = 1
collate = 1
printer = PRTDIALOG(win,startpg,endpg,copies,collate)
hprinter = OPENPRINTER(printer,"Document","TEXT")
if(hprinter)
buffer = getcontroltext(win,1)
WRITEPRINTER hprinter, buffer
CLOSEPRINTER hprinter
endif
RETURN

'------------- CHANGEFONT -------------
SUB changefont
DEF size,weight,flags,col:int
DEF fontname:string

fontname = FONTREQUEST(win,size,weight,flags,col)
if(fontname <> "")
SETFONT win,fontname,size,weight,flags,1
endif
SETCONTROLCOLOR win,1,col,RGB(255,255,255)
RETURN

'------------- REMOVECR ----------------
SUB RemoveCR
def pos:INT
def buffer2[32766]:ISTRING
pos = INSTR(buffer,CHR$(13))
while(pos)
if(mid$(buffer,pos,1) = CHR$(13))
buffer2 = left$(buffer,pos-1)
buffer2 = buffer2 + mid$(buffer,pos+1)
buffer = buffer2
endif
pos = INSTR(pos+1,buffer,chr$(13))
endwhile
return

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Re: Using line numbers within a rich edit control.
« Reply #10 on: December 24, 2011, 07:07:36 AM »
Thanks once again for your help on setting up the left margin for a rich edit control. I would like to know how to set the variables for the following code.

case WM_COMMAND:
switch( HIWORD(wParam) ){
case EN_UPDATE:
hRichEdit = FindWindowEx( hwnd, NULL, "RichEdit20A", NULL );
hdc = GetDC( hRichEdit );
makeLineNumber( hRichEdit, hdc );
ReleaseDC( hRichEdit, hdc );
break;
}
break;

How to set the variables for ...

WM_COMMAND:
and
EN_UPDATE:

I would appreciate any help.

Offline zlatkoCB

  • Sr. Member
  • ****
  • Posts: 462
  • Bananas: 2
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #11 on: December 24, 2011, 10:45:30 AM »
I don't know why you insist on this
and i simply cannot give you
proper answer ,i have search
trough Net and dont find anything
useful.
I think that LarryMc can put you in right direction...

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 191
  • Bananas: 4
  • Gender: Male
Re: Using line numbers within a rich edit control.
« Reply #12 on: December 24, 2011, 01:46:57 PM »
The setup should look something like this:
Code: [Select]
DECLARE "user32",GetDlgItem(hwnd:INT,id:INT),INT
CONST WM_COMMAND = &H111
CONST EN_UPDATE = &H400


def myrichedit:int
def mywin:window
window mywin.......................,handler
control mywin,".....,myrichedit"
 
handler:
select @CLASS
        case @IDCLOSEWINDOW
               
   case @IDCONTROL  '<---- WM_COMMAND
  select @CONTROLID
     case myrichedit
    if @CODE/&hFFFF = EN_UPDATE
    int hRichEdit=GetDlgItem(mywin.hwnd,myrichedit)
    int hdc = GetDC( hRichEdit )
    makeLineNumber( hRichEdit, hdc )
    ReleaseDC( hRichEdit, hdc )
    endif
  endselect
endselect
return
sub makeLineNumber(int hr,int hd)
 blah
 blah
return

LarryMc
« Last Edit: December 24, 2011, 01:50:22 PM by Larry McCaughn »
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

 

To link to us use this code/button on your site

http://www.codingmonkeys.com/images/cm_link.gif