The MASM Forum

General => The Campus => Topic started by: caraveiro on April 02, 2014, 02:12:55 PM

Title: Code Editor Line number?
Post by: caraveiro on April 02, 2014, 02:12:55 PM
Hi Buddies!

I want to make an application with a Edit Control to comparing text, but I want to color the dif. lines; It seems easy using a richedit control.

But I have no idea how to display the line number on the left side of the rows (line numbers same way that the code editor does).

Maybe having TWO edit controls wrapped: one for showing line number and the other to show the text. What do you think? 

Regards!
Title: Re: Code Editor Line number?
Post by: ragdog on April 03, 2014, 02:44:28 AM
Is not easy i use for my project RaEditLib from Radasm Project :t
Title: Re: Code Editor Line number?
Post by: caraveiro on April 04, 2014, 02:39:56 AM
Quote from: ragdog on April 03, 2014, 02:44:28 AM
Is not easy i use for my project RaEditLib from Radasm Project :t

Are you talking about this?

https://github.com/RaMMicHaeL/SimEd

and... yes, it seems that's not easy!  :dazzled:


But it seem a lot easier than what I was pretending to smoke,  some grass that goes by the name of InkEdit:

http://blogs.msdn.com/b/murrays/archive/2006/10/14/richedit-versions.aspx

Thank you!
Title: Re: Code Editor Line number?
Post by: dedndave on April 04, 2014, 02:52:23 AM
richedit controls and smoking grass probably don't go together well   :lol:
Title: Re: Code Editor Line number?
Post by: qWord on April 04, 2014, 04:18:08 AM
Quote from: caraveiro on April 02, 2014, 02:12:55 PMMaybe having TWO edit controls wrapped: one for showing line number and the other to show the text. What do you think? 
I would extend the left margin of the control and use that area to display the line numbers:
include \masm32\include\masm32rt.inc

DlgRichEdit MACRO dstyle,tx,ty,wd,ht,ctlID
    align_4 edi
    mov DWORD PTR [edi+0],  WS_VISIBLE or WS_CHILD or dstyle
    mov WORD  PTR [edi+8],  tx
    mov WORD  PTR [edi+10], ty
    mov WORD  PTR [edi+12], wd
    mov WORD  PTR [edi+14], ht
    mov WORD  PTR [edi+16], ctlID
    add edi, 18
    ustring "RichEdit20A"
    align_2 edi
    add edi, 2
ENDM

IDC_EDIT    EQU 100
MARGIN_X    EQU 30

.data?
    g_hInstance     HINSTANCE ?
    g_pOrgWndProc   WNDPROC ?
.code
WndProc  proc uses esi edi ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL pt:POINT
LOCAL sz[16]:CHAR
LOCAL lc:DWORD
LOCAL rect:RECT,rgn:HRGN

    invoke CallWindowProc,g_pOrgWndProc,hWnd,uMsg,wParam,lParam
    .if uMsg == WM_PAINT
        push eax
        .if rvx(lc=SendMessage,hWnd,EM_GETLINECOUNT,0,0)
            fnx ebx = GetDC,hWnd

            fn SaveDC,ebx
            fn GetClientRect,hWnd,&rect
            fn SelectClipRgn,ebx,rvx(rgn = CreateRectRgn,rect.left,rect.top,rect.right,rect.bottom)
           
            ;fnx br = SelectObject,ebx,rv(CreateSolidBrush,bkColor)
            invoke BitBlt,ebx,0,0,MARGIN_X,rect.bottom,ebx,0,0,PATCOPY
            ;fn DeleteObject,rv(SelectObject,ebx,br)
           
            fnx esi=SendMessage,hWnd,EM_GETFIRSTVISIBLELINE,0,0
            .while esi <= lc
                .break .if rv(SendMessage,hWnd,EM_LINEINDEX,esi,0) == -1
                fn SendMessage,hWnd,EM_POSFROMCHAR,&pt,eax
                mov eax,pt.y
                .break .if SDWORD ptr eax > rect.bottom
                fn wsprintf,&sz,"%lu",&[esi+1]
                fn TextOut,ebx,0,pt.y,&sz,rv(lstrlen,&sz)
                add esi,1
            .endw
            fn RestoreDC,ebx,-1
            fn DeleteObject,rgn
            fn ReleaseDC,hWnd,ebx
        .endif
        pop eax
    .endif
    ret
   
WndProc endp

DlgProc proc uses esi edi ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL rect:RECT

    .if uMsg == WM_INITDIALOG
        invoke SendDlgItemMessage,hWnd,IDC_EDIT,EM_SETMARGINS,EC_LEFTMARGIN,MARGIN_X
        fnx g_pOrgWndProc = SetWindowLong,rv(GetDlgItem,hWnd,IDC_EDIT),GWL_WNDPROC,WndProc
        xor eax,eax
    .elseif uMsg == WM_CLOSE
        fn EndDialog,hWnd,0
    .else
        xor eax,eax
    .endif
    ret
   
DlgProc endp

main proc
   
    fnx g_hInstance = GetModuleHandle,0
    fn LoadLibrary,"Riched20.dll"
   
    Dialog "test","MS Sans Serif",12,WS_OVERLAPPED or WS_SYSMENU or DS_CENTER,1,10,10,100,100,1024
    DlgRichEdit ES_MULTILINE or ES_WANTRETURN or ES_AUTOHSCROLL or ES_AUTOVSCROLL ,0,0,90,50,IDC_EDIT
    CallModalDialog g_hInstance,0,DlgProc,0
   
    exit
main endp
end main


EDIT: handle leak fixed
Title: Re: Code Editor Line number?
Post by: caraveiro on April 04, 2014, 07:03:05 AM
Quote from: qWord on April 04, 2014, 04:18:08 AM
I would extend the left margin of the control and use that area to display the line numbers:

Wow, wow!

Thank you.

;)

I someone need it; here are the best richedit reference I'd found.


http://www.jose.it-berater.org/richedit/iframe/index.htm

Bravo!
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 01:55:05 AM
Hello
is there a compiled 32 bit version of this program?
I simply don't know how to compile this example because i don't know assembler
yes shame on me   :rolleyes:
thanks in advance
Title: Re: Code Editor Line number?
Post by: jj2007 on February 15, 2020, 02:56:11 AM
Yep, shame on you, Aurel :biggrin:

Here is a quickie for you. (http://www.jj2007.eu/Masm32_Tips_Tricks_and_Traps.htm) But it won't help much, because there is no source around. Btw which proggie do you mean, the one by caraveiro or qWord's example?
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 03:19:16 AM
Yes shame  on me .. :sad:

hI jj , well i am not sure , one which show line numbers in richedit margin

edit; yes that one from qWord do you can compile it ?

edit2; jj ..do you have line numbers in your MasMbasic editor ,sorry i forgot all that things...
Title: Re: Code Editor Line number?
Post by: jj2007 on February 15, 2020, 03:32:27 AM
Quote from: aurel on February 15, 2020, 03:19:16 AMedit2; jj ..do you have line numbers in your MasMbasic editor ,sorry i forgot all that things...

Kind of, yes: If text is selected, then you get in the upper right corner, for example:
L1200 C3+4 73d 49 6E 69 74h meaning
line 1200
column 3 + 4 characters selected
73d is the decimal code of the first selected character
49 6E 69 74h are the hex codes of the four selected characters (Init)

(http://www.jj2007.eu/pics/RmMenu1.jpg)

If no text is selected, you get the absolute line number plus the line inside the current proc or macro:
(http://www.jj2007.eu/pics/LineCol.png)
Title: Re: Code Editor Line number?
Post by: jimg on February 15, 2020, 03:34:12 AM
I'm confused.
What is it you are looking for exactly?
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 03:59:02 AM
Hello
Yes looking confusing but not .
I asking is there anyone who can compile this above source code to 32bit exe  and zip it that i can try how work.
I simply don't have a clue how to do that , or i must download somewhere masm32 ?
i download Jwasm but there is no any include in that sourceforge pack.
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 04:01:16 AM
jj ...well as i can remember and see it  looks that you dont have it,i dont know how is that possible
because you have all that interesting things in it ,even i don't get it what is what ,
sorry but i am too stupid ,or to slow .. :rolleyes:
Title: Re: Code Editor Line number?
Post by: jj2007 on February 15, 2020, 04:03:15 AM
Apparently Aurel wants something like this, from qWord's example:

(http://www.jj2007.eu/pics/Qword.png)

Which is fine but not that useful if the editor jumps to the error line anyway:

(http://www.jj2007.eu/pics/RmErrorInMacro.png)

@Aurel: Step by step installation instructions are here (http://www.jj2007.eu/Masm32_Tips_Tricks_and_Traps.htm). Re "is there anyone who can compile this above source code to 32bit exe", no, because there is no source code...
Title: Re: Code Editor Line number?
Post by: jimg on February 15, 2020, 04:24:32 AM
Quote from: aurel on February 15, 2020, 01:55:05 AM
Hello
is there a compiled 32 bit version of this program?
I simply don't know how to compile this example because i don't know assembler
yes shame on me   :rolleyes:
thanks in advance

I can't see what you are referring to.  Which program is  "this"  program?
Title: Re: Code Editor Line number?
Post by: jj2007 on February 15, 2020, 04:26:51 AM
Aurel,
The solution posted by Xusinboy Bekchanov (https://www.freebasic.net/forum/viewtopic.php?f=6&t=28314&sid=1e2976996ca4b62f6b152bd6442e09aa#p268752) works but is limited to the first 32768 (apparently) lines, then it restarts at zero under certain idiosyncratic circumstances:
(http://www.jj2007.eu/pics/RmLines.png)

Actually, it's much buggier than that, but I don't want to indulge in details here. Line numbers are 20th Century :biggrin:

The PARAFORMAT2 struct is described here at M$ docs (https://docs.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-paraformat2). Note that they mention the wNumbering member, but it's not listed in the PARAFORMAT2 STRUCT; you would have to go back to PARAFORMAT, but the link is broken (apparently, nobody has ever used this feature, otherwise people would have complained, right?). But you can find it here (https://docs.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-paraformat).

To illustrate the mess, attached a little testbed. Press + to increase the wNumbering value, - to decrease it (see the status bar). Values<0 and >=7 produce nonsense, but #5 and #6 look very, very nice. Ideal for a code editor, actually :bgrin:
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 06:31:22 AM
Hello jj and others...of course
Well i am not master for this assembler stuff but i know very well how windows win32 api functions works.
First time when i see this qWord assembly code i have feeling that must work.
Hey jj , line numbers is not just 20c things they are very useful for me at last.
After downloading ...never using EasyCode IDE ..then VisualMasm - which looks very nice but always require Project
offering Visual Designer...what is not bad in general i download another one called SASM IDE..
and voila this small (not very small but looks to me simply enough). i use it to compile qWord program.
You can screenshot ...it work ...and much important ...work properly!  :thumbsup:
, i will spend some time to explore more masm examples.
JJ ...maybe you ask yourself...what that freak cooking this time...????
answer is simple..
This time i will try to create standalone code editor with my new interpreter without need for scintilla.
Yes scintilla is great control ,and i like it a lot...but it is one more separate .dll which always require adjusting,etc..etc...
well ..i really talking too much ...but ahh
i am glad that this assembly code work !

screenshot:
https://aurelsoft.ucoz.com/SASM_IDE_RichEditLineNumbers.png
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 06:32:58 AM
Also i have a question.
Is this control subcassed in this qWord program?
thanks
Title: Re: Code Editor Line number?
Post by: jj2007 on February 15, 2020, 07:38:33 AM
I don't think so. I can't tell you with certainty because I don't have the source.
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 06:48:22 PM
well JJ , i really don't know about what source code you talking, source code is under qWord post in code box.
and that is all, another thing is , it looks to me that you simply don't like it
I always like someone else code if i find it useful...in this case it is
all best... :smiley:
Title: Re: Code Editor Line number?
Post by: hutch-- on February 15, 2020, 06:58:40 PM
aurel,

Tread carefully here, this forum is not a free code ordering facility and giving lip to members who have tried to help you will get you kicked out of here like a rocket. If you want an editor written in assembler, feel free to write your own. First and last warning.
Title: Re: Code Editor Line number?
Post by: Mikl__ on February 15, 2020, 07:35:59 PM
Quoteis there a compiled 32 bit version of this program?
Hi, aurel!
It is a compiled 64 bit version of qWord program
asm-file; GUI #
include win64a.inc
IDC_EDIT    equ 100
IDD_DLG1    equ 101
IDC_ICON1   equ 10
MARGIN_X    equ 30
.code
WinMain proc
local dummy:qword

mov ecx,offset LibFileName
        invoke LoadLibrary
invoke LoadIcon,IMAGE_BASE,IDC_ICON1
mov hIcon,rax
mov r9d,offset DlgProc
invoke DialogBoxParam,IMAGE_BASE,IDD_DLG1,0,,rax
    invoke RtlExitUserProcess,NULL
WinMain endp

DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov hWnd,rcx

        cmp edx, WM_INITDIALOG
jz wmINITDIALOG
        cmp edx, WM_CLOSE
jz wmCLOSE
wmdefault:xor eax, eax
jmp wmBYE
wmINITDIALOG:
invoke SendMessage,,WM_SETICON,0,hIcon
invoke SendDlgItemMessage,hWnd,IDC_EDIT,EM_SETMARGINS,\
EC_LEFTMARGIN,MARGIN_X
invoke GetDlgItem,hWnd,IDC_EDIT
mov r8d,offset WndProc
invoke SetWindowLongPtr,eax,GWL_WNDPROC
mov g_pOrgWndProc,rax
jmp wmdefault
wmCLOSE:invoke EndDialog,,0
wmBYE: leave
retn
DlgProc endp

WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local pt:POINT
local sz[6]:BYTE
local lc:dword
local rect:RECT
local rgn:qword
local old_rsi:qword

mov hWnd,rcx
mov uMsg,edx
mov old_rsi,rsi

mov [rsp+20h],r9;lParam
mov r9,r8;wParam
mov r8,rdx;uMsg
mov edx,ecx;hWnd
        invoke CallWindowProc,g_pOrgWndProc
cmp uMsg,WM_PAINT
jnz wmBYE
wmPAINT:invoke SendMessage,hWnd,EM_GETLINECOUNT,0,0
mov lc, eax
or eax, eax
jz wmBYE
invoke GetDC,hWnd
mov hDC,rax
lea edx,rect
invoke GetClientRect,hWnd
invoke CreateRectRgn,rect.left,rect.top,rect.right,rect.bottom
mov rgn,rax ;rgn
invoke SelectClipRgn,hDC,eax
invoke BitBlt,hDC,0,0,MARGIN_X,rect.bottom,hDC,0,0,PATCOPY
invoke SendMessage,hWnd,EM_GETFIRSTVISIBLELINE,0,0
mov esi,eax;lineNo
;.while esi <= lc
@@: invoke SendMessage,hWnd,EM_LINEINDEX,esi,0
inc eax;eax = -1?
jz break
lea r9d,[rax-1]
lea r8d,pt
invoke SendMessage,hWnd,EM_POSFROMCHAR
mov eax,pt.y
cmp eax,rect.bottom
ja break;.break .if eax > rect.bottom
inc esi;lineNo+
lea ecx,sz
mov edx,offset aLu  ; "%lu"
invoke wsprintf,,,esi
lea r9d,sz
mov r8d,pt.y
invoke TextOut,hDC,0,,,eax
cmp esi,lc
jbe @b;.endw
break: invoke DeleteObject,rgn
invoke SelectClipRgn,hDC,0
invoke ReleaseDC,hWnd,hDC
wmBYE: mov rsi,old_rsi
leave
retn
WndProc endp
.data
aLu db '%lu',0
LibFileName db 'msftedit.dll',0
g_pOrgWndProc dq ?
hDC dq ?
hIcon dq ?
end
rc-file#include "resource.h"
#define IDC_EDIT 100
#define IDD_DLG1 101
#define IDC_ICON1 10

IDC_ICON1 ICON DISCARDABLE "br_Fox1.ico"

IDD_DLG1 DIALOGEX 10,10,100,100
CAPTION "test"
FONT 12,"MS Sans Serif",0,0,0
STYLE WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU|DS_CENTER
BEGIN
CONTROL "",IDC_EDIT,"RichEdit50W",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|ES_AUTOHSCROLL|ES_AUTOVSCROLL,0,0,90,50
END
There are asm-/rc-/ico-/exe-files in temp.zip (http://masm32.com/board/index.php?action=dlattach;topic=3079.0;attach=10163) attachment
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 07:49:48 PM
QuoteTread carefully here, this forum is not a free code ordering facility and giving lip to members who have tried to help you will get you kicked out of here like a rocket. If you want an editor written in assembler, feel free to write your own. First and last warning.

hello admin
I just ask for help abut given example by qWord and nothing else.
I really cannot understand what i do wrong.
thanks
Title: Re: Code Editor Line number?
Post by: jj2007 on February 15, 2020, 08:15:37 PM
@Mikl: Molto bello :thumbsup:

@Aurel: I just realise that qWord's post (http://masm32.com/board/index.php?topic=3079.msg31996#msg31996) does contain the full source. I had thought it was only a snippet... my apologies :sad:

So all you have to do is copy the source, paste it into a text file, name it RicheditLineNumbers.asm, and build it, either with \Masm32\qEditor.exe or with \Masm32\MasmBasic\Richmasm.exe in case you have that installed.
Title: Re: Code Editor Line number?
Post by: Mikl__ on February 15, 2020, 08:24:44 PM
Ciao, jj2007!
ci ho provato (https://wasm.in/styles/smiles_s/blush2.gif) (я старался...)
Title: Re: Code Editor Line number?
Post by: aurel on February 15, 2020, 08:28:38 PM
Hi jj
Yes it is complete example and probably only one we can find out there.
Yes i do that , i first install masm32 sdk on my win7_32bit computer then setting IDE options and as you can see
program is compiled and work perfectly.
You know that i don't have experience with asseblers and i don't want to bother Charles with asmosphere assembler.
all best...
Title: Re: Code Editor Line number?
Post by: aurel on February 16, 2020, 07:14:42 PM
Sorry i forgot ti say
thank Mikl_ for your 64bit version , i see code is different and because i don't know is that
WASM i found in your signature..
thanks