The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: theifyppl on July 27, 2009, 02:13:09 AM

Title: An Easier way to make a text editor
Post by: theifyppl on July 27, 2009, 02:13:09 AM
Is there an easier way to do this?

Well I know I'm going to have to fill in the OPENFILENAME structure regardless, but is there an easier way to do this part?

Invoke GetOpenFileName, Addr ofn
Invoke DoEvents
.If Eax == TRUE
invoke CreateFile,ADDR buffer,\
                                       GENERIC_READ or GENERIC_WRITE ,\
                                       FILE_SHARE_READ or FILE_SHARE_WRITE,\
                                       NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
                                       NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov  hMemory,eax
invoke GlobalLock,hMemory
mov  pMemory,eax
invoke ReadFile,hFile,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL
invoke SendMessage,hwndEdit,WM_SETTEXT,NULL,pMemory
invoke CloseHandle,hFile
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
Title: Re: An Easier way to make a text editor
Post by: NightWare on July 27, 2009, 02:33:21 AM
increase the size (to have a final zero, and to apply your string functions directly to the file in memory),
use HeapAlloc instead of GlobalAlloc (no need to lock/unlock),
keep the memory area, to make your modifications on it (just don't forget to free the memory area at the end of your program with HeapFree).
Title: Re: An Easier way to make a text editor
Post by: Tedd on July 27, 2009, 10:05:25 AM

Invoke GetOpenFileName, Addr ofn
Invoke DoEvents
.If Eax == TRUE
    invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,MEMSIZE
    mov  pMemory,eax

    invoke CreateFile,ADDR buffer,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
    mov hFile,eax

    invoke ReadFile,hFile,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL
    invoke CloseHandle,hFile

    invoke SendMessage,hwndEdit,WM_SETTEXT,NULL,pMemory

    invoke GlobalFree,pMemory
.ENDIF

Title: Re: An Easier way to make a text editor
Post by: ecube on July 27, 2009, 10:43:51 AM
Icezlion has a nice tutortial, with beautifully written/easy to read code to make a editor.

http://win32assembly.online.fr/tutorials.html

tut 33-35
Title: Re: An Easier way to make a text editor
Post by: jj2007 on July 27, 2009, 11:46:34 AM
For your inspiration, here is a 6k rich text editor with essential features (F1 help, find & replace, bold, red, blue highlighting, one-key assembly etc). Source included.

EDIT: Tiny fix - name of current document now in window title

[attachment deleted by admin]
Title: Re: An Easier way to make a text editor
Post by: dedndave on July 27, 2009, 03:42:58 PM
very cool Jochen   :U
Title: Re: An Easier way to make a text editor
Post by: jj2007 on July 27, 2009, 04:02:55 PM
Quote from: dedndave on July 27, 2009, 03:42:58 PM
very cool Jochen   :U

Thanks. I have been fighting for every single byte to get it down to 6,144 bytes  :bg
Title: Re: An Easier way to make a text editor
Post by: theifyppl on July 30, 2009, 12:15:21 AM
Thanks a BUNCH you guys are awesome!

The reason I'm looking to do all this was so I can make video tutorials on how to do it.  I've made three so far on msgbox, editable msgbox, and a calculator.  The next step is a notepad, but I needed simpler code than what I had because otherwise it'd take like 5 videos to explain it.  I knew there had to be an easier way so I asked here :).

Thanks again