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


format PE64 GUI 5.0
entry start
include 'win64w.inc'
section '.data' data readable writeable
msg MSG
ps PAINTSTRUCT
rct RECT
border_rect RECT
buf_rect RECT
sys_font_name du 'Segoe UI',0
edit_class du 'EDIT',0
hFont dq 0
mem_dc dq 0
mem_bmp dq 0
old_bmp dq 0
win_width dd 0
win_height dd 0
sys_win_count dq 1
  _class_GridWindow du 'Class_GridWindow',0
  _title_GridWindow du 'Grid Test',0
  wc_GridWindow WNDCLASS
  hwnd_GridWindow dq 0
section '.code' code readable executable
start:
    sub rsp, 8*5
    mov [wc_GridWindow.style], CS_HREDRAW or CS_VREDRAW
    mov [wc_GridWindow.lpfnWndProc], WindowProc_GridWindow
    invoke GetModuleHandle, 0
    mov [wc_GridWindow.hInstance], rax
    invoke LoadIcon, 0, IDI_APPLICATION
    mov [wc_GridWindow.hIcon], rax
    invoke LoadCursor, 0, IDC_ARROW
    mov [wc_GridWindow.hCursor], rax
    invoke CreateSolidBrush, 0x001A1A1A
    mov [wc_GridWindow.hbrBackground], rax
    mov [wc_GridWindow.lpszClassName], _class_GridWindow
    lea rcx, [wc_GridWindow]
    invoke RegisterClass, rcx
    test eax, eax
    jz exit
    invoke CreateWindowEx, 0, _class_GridWindow, _title_GridWindow, WS_OVERLAPPEDWINDOW or WS_VISIBLE, \
           CW_USEDEFAULT, CW_USEDEFAULT, 400, 350, \
           0, 0, [wc_GridWindow.hInstance], 0
    test rax, rax
    jz exit
    mov [hwnd_GridWindow], rax
    mov [win_width], 400
    mov [win_height], 350
    invoke LoadLibraryA, 'dwmapi.dll'
    test rax, rax
    jz .no_dwm_GridWindow
    mov r12, rax
    invoke GetProcAddress, r12, 'DwmSetWindowAttribute'
    test rax, rax
    jz .no_dwm_GridWindow
    mov r13, rax
    sub rsp, 32
    mov dword [rsp+0], 1
    lea r9, [rsp]
    mov r8d, 4
    mov edx, 20
    mov rcx, [hwnd_GridWindow]
    call r13
    add rsp, 32
  .no_dwm_GridWindow:
  msg_loop:
    lea rcx, [msg]
    invoke GetMessage, rcx, 0, 0, 0
    test eax, eax
    jz exit
    lea rcx, [msg]
    invoke TranslateMessage, rcx
    lea rcx, [msg]
    invoke DispatchMessage, rcx
    jmp msg_loop
  exit:
    mov rcx, [msg.wParam]
    invoke ExitProcess, rcx
proc WindowProc_GridWindow hwnd, wmsg, wparam, lparam
    push rbx rsi rdi r14
    mov rbx, rcx
    mov rsi, rdx
    mov rdi, r8
    mov r14, r9
    cmp edx, 1
    je .wm_create
    cmp edx, 5
    je .wm_size
    cmp edx, 15
    je .wm_paint
    cmp edx, WM_CTLCOLOREDIT
    je .wm_ctlcoloredit
    cmp edx, 512
    je .wm_mousemove
    cmp edx, 513
    je .wm_lbuttondown
    cmp edx, WM_DESTROY
    je .wm_destroy
    pop r14 rdi rsi rbx
    invoke DefWindowProc, rcx, rdx, r8, r9
    ret
  .wm_create:
    invoke CreateFont, 16, 0, 0, 0, 400, 0, 0, 0, 204, 0, 0, 5, 0, sys_font_name
    mov [hFont], rax
    invoke GetDC, rbx
    mov r15, rax
    invoke CreateCompatibleDC, r15
    mov [mem_dc], rax
    invoke CreateCompatibleBitmap, r15, 2000, 2000
    mov [mem_bmp], rax
    invoke SelectObject, [mem_dc], rax
    mov [old_bmp], rax
    invoke ReleaseDC, rbx, r15
    invoke InvalidateRect, rbx, 0, 1
    xor eax, eax
    jmp .finish
  .wm_ctlcoloredit:
    pop r14 rdi rsi rbx
    invoke DefWindowProc, rcx, rdx, r8, r9
    ret
  .wm_size:
    mov eax, r14d
    and eax, 0xFFFF
    mov [win_width], eax
    mov eax, r14d
    shr eax, 16
    mov [win_height], eax
    invoke InvalidateRect, rbx, 0, 1
    xor eax, eax
    jmp .finish
  .wm_paint:
    lea rdx, [ps]
    invoke BeginPaint, rbx, rdx
    mov r12, rax
    mov [buf_rect.left], 0
    mov [buf_rect.top], 0
    mov [buf_rect.right], 2000
    mov [buf_rect.bottom], 2000
    lea rdx, [buf_rect]
    invoke FillRect, [mem_dc], rdx, [wc_GridWindow.hbrBackground]
    invoke SelectObject, [mem_dc], [hFont]
    invoke SetBkMode, [mem_dc], 1
    invoke BitBlt, r12, 0, 0, [win_width], [win_height], [mem_dc], 0, 0, SRCCOPY
    lea rdx, [ps]
    invoke EndPaint, rbx, rdx
    xor eax, eax
    jmp .finish
  .wm_mousemove:
    mov rdx, r14
    movzx eax, dx
    shr rdx, 16
    movzx edx, dx
    xor eax, eax
    jmp .finish
  .wm_lbuttondown:
    mov rdx, r14
    movzx eax, dx
    shr rdx, 16
    movzx edx, dx
    xor eax, eax
    jmp .finish
  .wm_destroy:
    invoke SelectObject, [mem_dc], [old_bmp]
    invoke DeleteObject, [mem_bmp]
    invoke DeleteDC, [mem_dc]
    dec qword [sys_win_count]
    cmp qword [sys_win_count], 0
    jne .skip_quit
    invoke PostQuitMessage, 0
  .skip_quit:
    xor eax, eax
  .finish:
    pop r14 rdi rsi rbx
    ret
endp
section '.idata' import data readable writeable
  library kernel32, 'KERNEL32.DLL', \
          user32,   'USER32.DLL',   \
          gdi32,    'GDI32.DLL'
  include 'api\\kernel32.inc'
  include 'api\\user32.inc'
  include 'api\\gdi32.inc'