include 'win32wx.inc'
.data
szFile TCHAR "note.txt", 0
wc WNDCLASS 0, WindowProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE + 1, NULL, szFile
hWndEdit dd ?
msg MSG
client RECT
.code
start:
invoke GetModuleHandle, 0
mov [wc.hInstance], eax
invoke RegisterClass, wc
.if eax
invoke CreateWindowEx, 0, eax, szFile, WS_VISIBLE + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 256, 256, NULL, NULL, [wc.hInstance], NULL
.while eax
invoke GetMessage, msg, NULL, 0, 0
.if eax & (eax <> -1)
invoke TranslateMessage, msg
invoke DispatchMessage, msg
or eax, TRUE
.endif
.endw
.endif
invoke ExitProcess, [msg.wParam]
.end start
proc WindowProc hWnd, wMsg, wParam, lParam
local hFile : DWORD, hMap : DWORD, pMemory : DWORD
.if [wMsg] = WM_CREATE
invoke GetClientRect, [hWnd], client
invoke CreateWindowEx, WS_EX_CLIENTEDGE, "EDIT", 0, WS_VISIBLE + WS_CHILD + WS_HSCROLL + WS_VSCROLL + ES_AUTOHSCROLL + ES_AUTOVSCROLL + ES_MULTILINE, [client.left], [client.top], [client.right], [client.bottom], [hWnd], 0, [wc.hInstance], NULL
mov [hWndEdit], eax
.if [hWndEdit]
invoke CreateFile, szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.if eax <> INVALID_HANDLE_VALUE
mov [hFile], eax
invoke CreateFileMapping, [hFile], NULL, PAGE_READONLY, 0, 0, NULL
.if eax
mov [hMap], eax
invoke MapViewOfFile, [hMap], FILE_MAP_READ, 0, 0, 0
.if eax
mov [pMemory], eax
invoke SetWindowText, [hWndEdit], [pMemory]
invoke UnmapViewOfFile, [pMemory]
.endif
invoke CloseHandle, [hMap]
.else
mov [hMap], 0
.endif
invoke CloseHandle, [hFile]
.endif
xor eax, eax
.else
or eax, -1
.endif
.elseif [wMsg] = WM_SIZE
invoke GetClientRect, [hWnd], client
invoke MoveWindow, [hWndEdit], [client.left], [client.top], [client.right], [client.bottom], TRUE
xor eax,eax
.elseif [wMsg] = WM_SETFOCUS
invoke SetFocus, [hWndEdit]
xor eax,eax
.elseif [wMsg] = WM_DESTROY
.if [hWndEdit]
invoke CreateFile, szFile, GENERIC_READ + GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
.if eax <> INVALID_HANDLE_VALUE
mov [hFile], eax
invoke GetWindowTextLength, [hWndEdit]
.if eax
shl eax, 1
invoke CreateFileMapping, [hFile], NULL, PAGE_READWRITE, 0, eax, NULL
.if eax
mov [hMap], eax
invoke MapViewOfFile, [hMap], FILE_MAP_WRITE, 0, 0, 0
.if eax
mov [pMemory], eax
invoke GetWindowTextLength, [hWndEdit]
inc eax
invoke GetWindowText, [hWndEdit], [pMemory], eax
invoke UnmapViewOfFile, [pMemory]
.endif
invoke CloseHandle, [hMap]
.endif
.endif
invoke CloseHandle, [hFile]
.endif
.endif
invoke PostQuitMessage, 0
xor eax, eax
.else
invoke DefWindowProc, [hWnd], [wMsg], [wParam], [lParam]
.endif
ret
endp