flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > text editor

Author
Thread Post new topic Reply to topic
Ali.A



Joined: 08 Jan 2018
Posts: 125
im trying to make a simple text editor, but the problem is there is no edit box.

note:
if you click some keys you will hear some sound.

Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.text' code executable

start:

    invoke      GetModuleHandle,0
    mov         [wc.hInstance],eax

    invoke      LoadCursor,0,IDC_IBEAM
    mov         [wc.hCursor],eax
    invoke      CreateFont,16,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,NULL
    mov         [hfont],eax
    xor         eax,eax
    mov         [wc.style],eax
    mov         [wc.lpfnWndProc],MainWindow
    mov         [wc.cbClsExtra],eax
    mov         [wc.cbWndExtra],eax
    mov         [wc.hbrBackground],COLOR_WINDOW
    mov         [wc.lpszMenuName],eax
    mov         [wc.lpszClassName],_class
    invoke      RegisterClass,wc
    invoke      LoadAccelerators,[wc.hInstance],IDA_MAIN
    mov         [hkeys],eax
    invoke      LoadMenu,[wc.hInstance],IDM_MAIN
    invoke      CreateWindowEx,0,_class,_caption,WS_TILEDWINDOW+WS_CLIPCHILDREN+WS_CLIPSIBLINGS,25,25,244,152,NULL,eax,[wc.hInstance],NULL
    mov         [hwnd_main],eax
    invoke      ShowWindow,eax,SW_SHOW
    invoke      UpdateWindow,[hwnd_main]

msg_loop:
    invoke      GetMessage,msg,NULL,0,0
    or          eax,eax
    jz          end_loop
    invoke      TranslateAccelerator,[hwnd_main],[hkeys],msg
    or          eax,eax
    jnz         msg_loop
    cmp         [msg.message],WM_KEYDOWN
    jz          msg_dispatch
    invoke      TranslateMessage,msg
msg_dispatch:
    invoke      DispatchMessage,msg
    jmp         msg_loop

end_loop:
    invoke      ExitProcess,[msg.wParam]

proc MainWindow hwnd,msg,wparam,lparam
    push        ebx esi edi
    cmp         [msg],WM_CREATE
    jz          wmcreate
    cmp         [msg],WM_SIZE
    jz          wmsize
    cmp         [msg],WM_SETFOCUS
    jz          wmsetfocus
    cmp         [msg],WM_COMMAND
    jz          wmcommand
    cmp         [msg],WM_CLOSE
    jz          wmclose
    cmp         [msg],WM_DESTROY
    jz          wmdestroy
    invoke      DefWindowProc,[hwnd],[msg],[wparam],[lparam]
    jmp         finish
  wmcreate:
    invoke      GetClientRect,[hwnd],rct
    invoke      CreateWindowEx,0,_edit_class,0,WS_CHILD,WS_VISIBLE,ES_MULTILINE,WS_VSCROLL,WS_HSCROLL,ES_AUTOVSCROLL,ES_AUTOHSCROLL,[rct.left],[rct.top],[rct.right],[rct.bottom],[hwnd],NULL,[wc.hInstance],NULL
    mov         [hedit],eax
    invoke      SendMessage,[hedit],WM_SETFONT,[hfont],0
    jmp         ok
  wmsize:
    invoke      GetClientRect,[hwnd],rct
    invoke      MoveWindow,[hedit],[rct.left],[rct.top],[rct.right],[rct.bottom],TRUE
    jmp         ok
  wmsetfocus:
    invoke      SetFocus,[hedit]
    jmp         ok
  wmcommand:
    mov         eax,[wparam]
    and         eax,0ffffh
    cmp         eax,IDM_NEW
    jz          ok
    cmp         eax,IDM_EXIT
    jz          wmclose
    cmp         eax,IDM_ABOUT
    jz          about_dlg
    jmp         ok
    about_dlg:
    invoke      DialogBoxParam,[wc.hInstance],IDD_ABOUT,[hwnd],AboutDialog,0
    jmp         ok
  wmclose:
    invoke      DeleteObject,[hfont]
    invoke      DestroyWindow,[hwnd]
    jmp         ok
  wmdestroy:
    invoke      WinHelp,[hwnd],0,HELP_QUIT,0
    invoke      PostQuitMessage,0
  ok:
    xor         eax,eax
  finish:
    pop         edi esi ebx
    ret
endp

proc AboutDialog hwnd,msg,wparam,lparam
    push        ebx esi edi
    cmp         [msg],WM_CLOSE
    jz          .close
    xor         eax,eax
    jmp         .finish
  .close:
    invoke      EndDialog,[hwnd],0
    mov         eax,1
  .finish:
    pop         edi esi ebx
    ret
endp

section '.data' data readable writeable

  wc WNDCLASS
  msg MSG
  rct RECT

  hwnd_main dd ?
  hfont     dd ?
  hedit     dd ?
  hkeys     dd ?

section '.rdata' data readable

  _class db 'CES',0
  _edit_class db 'SEDIT',0
  _caption db 'Fasm Example',0

section '.idata' import data readable

  library kernel32,'kernel32.dll',\
          user32,'user32.dll',\
          advapi32,'advapi32.dll',\
          shell32,'shell32.dll',\
          gdi32,'gdi32.dll',\
          comctl32,'comctl32.dll',\
          comdlg32,'comdlg32.dll'

  include 'api\kernel32.inc'
  include 'api\user32.inc'
  include 'api\advapi32.inc'
  include 'api\shell32.inc'
  include 'api\gdi32.inc'
  include 'api\comctl32.inc'
  include 'api\comdlg32.inc'

section '.rsrc' resource data readable

  directory RT_MENU,menus,\
            RT_ACCELERATOR,accelerators,\
            RT_DIALOG,dialogs

  resource menus,\
           IDM_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu

  resource accelerators,\
           IDA_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,hot_keys

  resource dialogs,\
           IDD_ABOUT,LANG_ENGLISH+SUBLANG_DEFAULT,about_dialog

  IDA_MAIN      = 101
  IDM_MAIN      = 201
  IDM_NEW       = 202
  IDM_EXIT      = 203
  IDM_ABOUT     = 204
  IDD_ABOUT     = 301

  _ equ ,09,

  menu main_menu
       menuitem '&File',0,MFR_POPUP
                menuitem '&New' _ 'Ctrl+N',IDM_NEW,0,MFS_GRAYED,0
                menuseparator
                menuitem '&Exit' _ 'Alt+X',IDM_EXIT,MFR_END
       menuitem '&Help',0,MFR_POPUP+MFR_END
                menuitem '&About' _ 'Shift+H',IDM_ABOUT,MFR_END

  accelerator hot_keys,\
              FVIRTKEY+FNOINVERT+FCONTROL,'N',IDM_NEW,\
              FVIRTKEY+FNOINVERT+FALT,'X',IDM_EXIT,\
              FVIRTKEY+FNOINVERT+FSHIFT,'H',IDM_ABOUT

  dialog about_dialog,'About..',50,50,100,100,WS_SYSMENU+WS_CAPTION+WS_POPUP+DS_MODALFRAME
    dialogitem 'STATIC','Win32 GUI example',-1,25,25,50,50,WS_VISIBLE+SS_CENTER
  enddialog

section '.reloc' fixups data readable discardable    

_________________
Asm For Wise Humans
Post 18 Oct 2018, 13:02
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 419
Location: Belarus
Ali.A wrote:
im trying to make a simple text editor, but the problem is there is no edit box.

Something wrong went here, at least:
Code:
    invoke      CreateWindowEx,0,_edit_class,0,WS_CHILD,WS_VISIBLE,ES_MULTILINE,WS_VSCROLL,WS_HSCROLL,ES_AUTOVSCROLL,ES_AUTOHSCROLL,[rct.left],[rct.top],[rct.right],[rct.bottom],[hwnd],NULL,[wc.hInstance],NULL    
Post 18 Oct 2018, 16:24
View user's profile Send private message Visit poster's website Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 132
In order to see your input, you are going to need:

In CreateWindowEx:

WS_CHILD+WS_VISIBLE+ES_MULTILINE+WS_VSCROLL+WS_HSCROLL+ES_AUTOVSCROLL+ES_AUTOHSCROLL

Class:

_edit_class db 'EDIT',0

and in msg_loop:

; cmp [msg.message],WM_KEYDOWN
; jz msg_dispatch
Post 18 Oct 2018, 16:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16054
Location: 112 Ocean Avenue, Amityville
If you check the return values from each API call then you can narrow down each problem more easily. Print some sort of simple message (or better, use a debugger) when any of the API calls fails. Fix up each call one-by-one until they all execute successfully.
Post 18 Oct 2018, 17:22
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 125
ok found my issue after debugging:
Code:
WS_CHILD,WS_VISIBLE,ES_MULTILINE,WS_VSCROLL,WS_HSCROLL,ES_AUTOVSCROLL,ES_AUTOHSCROLL    

used comma instead of '+' plus sign.

and why i cant get a custom name for _edit_class? why it have to be 'edit'?

and why im limited in the editbox? i cant write many characters!

also
; cmp [msg.message],WM_KEYDOWN
; jz msg_dispatch

didnt work, i had to change it to:

Code:
msg_loop:
    invoke      GetMessage,msg,NULL,0,0
    or          eax,eax
    jz          end_loop
    cmp         [msg.message],WM_KEYDOWN
    jz          msg_translate
    invoke      TranslateAccelerator,[hwnd_main],[hkeys],msg
    or          eax,eax
    jnz         msg_loop
    cmp         [msg.message],WM_KEYDOWN
    jz          msg_dispatch
msg_translate:
    invoke      TranslateMessage,msg
msg_dispatch:
    invoke      DispatchMessage,msg
    jmp         msg_loop    


but the issue now is i cant receive hotkeys with shift or ctrl, only alt key.

Code:
menu main_menu
       menuitem '&File',0,MFR_POPUP
                menuitem '&New' _ 'Alt+N',IDM_NEW,0,MFS_GRAYED,0
                menuseparator
                menuitem '&Exit' _ 'Alt+X',IDM_EXIT,MFR_END
       menuitem '&Help',0,MFR_POPUP+MFR_END
                menuitem '&About' _ 'Alt+H',IDM_ABOUT,MFR_END

accelerator hot_keys,\ ; cant use FCONTROL
              FVIRTKEY+FNOINVERT+FALT,'N',IDM_NEW,\
              FVIRTKEY+FNOINVERT+FALT,'X',IDM_EXIT,\
              FVIRTKEY+FNOINVERT+FALT,'H',IDM_ABOUT    

how could i solve this?
Post 18 Oct 2018, 20:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16054
Location: 112 Ocean Avenue, Amityville
Ali.A wrote:
and why i cant get a custom name for _edit_class? why it have to be 'edit'?
The "EDIT" class is provided by the Windows standard DLLS. You don't have to use it if you don't want to. You can create a custom class with any name. But then you have to write the code to support the class.

Have a look at the FEDIT.ASM source for the "FEDIT" class.
Post 18 Oct 2018, 21:14
View user's profile Send private message Visit poster's website Reply with quote
MacroZ



Joined: 12 Oct 2018
Posts: 16
More text editors are always useful. I hope it will have syntax highlighting for asm. Keep up the good work.

_________________
The king auto-generates two things to degrade dangerous artists and intellectuals. The King reserves the right to be king and has made the culprits in advance. Half of the time or more, they are auto-generated.
Post 19 Oct 2018, 12:05
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.