Загрузка данных


format PE64 GUI
entry start

include 'win64a.inc'

section '.data' data readable writeable

  className db 'MyWindow',0
  windowTitle db 'FASM Win64',0

  buttonText db 'Нажми меня',0
  msgText db 'Кнопка нажата!',0
  msgTitle db 'FASM',0

  hButton dq ?

section '.code' code readable executable

start:

  invoke GetModuleHandle,0
  mov rbx,rax

  sub rsp,sizeof.WNDCLASSEX

  mov [rsp+WNDCLASSEX.cbSize],sizeof.WNDCLASSEX
  mov [rsp+WNDCLASSEX.style],CS_HREDRAW+CS_VREDRAW
  mov [rsp+WNDCLASSEX.lpfnWndProc],WndProc
  mov [rsp+WNDCLASSEX.cbClsExtra],0
  mov [rsp+WNDCLASSEX.cbWndExtra],0
  mov [rsp+WNDCLASSEX.hInstance],rbx

  invoke LoadIcon,0,IDI_APPLICATION
  mov [rsp+WNDCLASSEX.hIcon],rax
  mov [rsp+WNDCLASSEX.hIconSm],rax

  invoke LoadCursor,0,IDC_ARROW
  mov [rsp+WNDCLASSEX.hCursor],rax

  mov [rsp+WNDCLASSEX.hbrBackground],COLOR_BTNFACE+1
  mov [rsp+WNDCLASSEX.lpszMenuName],0
  mov [rsp+WNDCLASSEX.lpszClassName],className

  invoke RegisterClassEx,rsp
  add rsp,sizeof.WNDCLASSEX

  invoke CreateWindowEx,\
         0,\
         className,\
         windowTitle,\
         WS_OVERLAPPEDWINDOW+WS_VISIBLE,\
         200,200,600,400,\
         0,0,rbx,0

  mov r12,rax

msg_loop:
  invoke GetMessage,msg,0,0,0
  test eax,eax
  jz exit_app

  invoke TranslateMessage,msg
  invoke DispatchMessage,msg
  jmp msg_loop

exit_app:
  invoke ExitProcess,0

proc WndProc hwnd,wmsg,wparam,lparam

  cmp [wmsg],WM_CREATE
  je .create

  cmp [wmsg],WM_COMMAND
  je .command

  cmp [wmsg],WM_DESTROY
  je .destroy

  invoke DefWindowProc,\
         [hwnd],\
         [wmsg],\
         [wparam],\
         [lparam]
  ret

.create:

  invoke CreateWindowEx,\
         0,\
         'BUTTON',\
         buttonText,\
         WS_CHILD+WS_VISIBLE+BS_PUSHBUTTON,\
         180,140,220,60,\
         [hwnd],\
         1,\
         0,\
         0

  mov [hButton],rax
  xor eax,eax
  ret

.command:

  mov rax,[wparam]
  and eax,0FFFFh
  cmp eax,1
  jne .end_command

  invoke MessageBox,\
         [hwnd],\
         msgText,\
         msgTitle,\
         MB_OK

.end_command:
  xor eax,eax
  ret

.destroy:
  invoke PostQuitMessage,0
  xor eax,eax
  ret

endp

section '.bss' readable writeable

  msg MSG

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,'USER32.DLL'

import kernel32,\
       GetModuleHandle,'GetModuleHandleA',\
       ExitProcess,'ExitProcess'

import user32,\
       RegisterClassEx,'RegisterClassExA',\
       CreateWindowEx,'CreateWindowExA',\
       DefWindowProc,'DefWindowProcA',\
       ShowWindow,'ShowWindow',\
       UpdateWindow,'UpdateWindow',\
       GetMessage,'GetMessageA',\
       TranslateMessage,'TranslateMessage',\
       DispatchMessage,'DispatchMessageA',\
       PostQuitMessage,'PostQuitMessage',\
       MessageBox,'MessageBoxA',\
       LoadCursor,'LoadCursorA',\
       LoadIcon,'LoadIconA'