format PE GUI 5.0
include 'win32wx.inc'
 
width  = 1280
height = 1024
 
.code
start:
 ; Open file and save its handle into EBX
    ; 
    invoke    CreateFileA, achFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 
    mov       ebx, eax 
    ; 
    ; If file is not opened - get out! 
    ; 
    cmp       eax, INVALID_HANDLE_VALUE 
    je         WM_CLOSE
    ; 
    ; ESI = file size in bytes 
    ; 
    invoke    GetFileSize, ebx, 0 
    mov       esi, eax 
    mov       [dwFileSize], eax 
    ; 
    ; Allocate memory for the file contents 
    ; EDI = pointer to that buffer 
    ; 
    invoke    VirtualAlloc, 0, esi, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE 
    mov       edi, eax 
    mov       [pFileBytes], eax 
    ; 
    ; If allocation fails - close file and get out! 
    ; 
    test      eax, eax 
    jz        .close_file 
    ; 
    ; Read the file into buffer and then close file. 
    invoke    ReadFile, ebx, Raster-54, [dwFileSize], dwNumLoaded, 0
    invoke    CloseHandle, ebx 
    ; 
    ; Now the file is fully loaded at the address in EDI... do whatever... 
    ; 
    nop 
    nop 
    nop 
    nop 
    nop 
    ; 
    ; Release memory and quit 
    ; 
    invoke    VirtualFree, [pFileBytes], 0, MEM_RELEASE 
.close_file: 
    invoke    CloseHandle, ebx 
invoke CreateWindowExW,0,static,0,WS_VISIBLE+WS_OVERLAPPEDWINDOW+SS_BITMAP+SS_CENTERIMAGE,0,0,width,height,0,0,0,0
mov    [wnd],eax
invoke SetWindowLongW,[wnd],GWL_WNDPROC,WndProc
invoke GetDC,[wnd]
mov    [DC],eax
 
;Òóò ìîæíî ðèñîâàòü
;mov  esi,Raster             ;ïåðåìåííàÿ Raster ñîäåðæèò èôîðìàöèþ î öâåòå ïèêñåëåé
;add  esi,width*3
;mov  dword[esi-3],255
;mov  ecx,(width-1)*height
;@@:lodsd
;   xor eax,[esi-width*3]
;   mov [esi],eax
;loop @b
;;;;;;;;;;;;;;;;;;;
 
@@:invoke GetMessageW,msg,0,0,0
   invoke DispatchMessageW,msg
jmp @b
 
WndProc:
  cmp dword[esp+8],WM_PAINT
  jz  .WM_PAINT
  cmp dword[esp+8],WM_CLOSE
  jz  .WM_CLOSE
      jmp [DefWindowProcW]
  .WM_PAINT:
      invoke SetDIBitsToDevice,[DC],0,0,width,height,0,0,0,height,Raster,bmi,0
      ret 16
  .WM_CLOSE:
     invoke ExitProcess,0
 
static du 'STATIC',0
 
.data
    pFileBytes   dd 0
    dwFileSize   dd 0 
    dwNumLoaded  dd 0 
    achFileName  db 'f:\333.bmp',0
bmi     BITMAPINFOHEADER sizeof.BITMAPINFOHEADER,width,-height,1,24,0,width*height*3
msg     MSG
wnd     rd 1
DC      rd 1
Raster  rd width*height
 
.end start