Win00a.ASM : Win00.asm With Simpler STRUC Declaration 


;Win00a.ASM : Win00.asm With Simpler Instance Code (April 25,2024)
;             Read Win00a.rtf for more info especially on STRUCs.
;
;   The " %include " paths at the start of the file might need to be
;       changed to suit your own disk directory setup.
;
;   Command Lines:
;	Assembly: nasm -f win32 Win00a.asm -o Win00a.obj;
;	Link: GoLink.exe: golink.exe /entry:start Win00a.obj kernel32.dll user32.dll

;========================= INCLUDE FILES =====================================

%include '\nasm32\inc\win32\windows.inc'
%include '\nasm32\inc\win32\kernel32.inc'
%include '\nasm32\inc\win32\user32.inc'
%include '\nasm32\inc\nasm32.inc'
;                          ===============
                           [section .data]
;                          ===============
;-------
;HANDLES
;-------
hInstance dd 0
hWnd dd 0

;--------------
;VARIOUS LABELS
;--------------
ModName db "Win00a.exe",0
szTitle db 'Win00a : A Simple NASM Window : Click The Close Button To Exit -------->',0x0
szClass db 'Win00a Class',0x0

;-----------------------------------------------------------
;Simpler instance definitions which avoid the STRUC template
;-----------------------------------------------------------
wcx  times WNDCLASSEX_size db 0	;Declare a memory block of WNDCLASSEX_size
msg times MSG_size db 0			;Declare a memory block of MSG_size

;                          ===============
                           [section .text]
;                          ===============

start:         ;Start offset for GoLink.exe

   proc Win00a
          invoke GetModuleHandleA, dword NULL
          mov [hInstance], eax
          invoke WinMain,dword [hInstance],NULL,NULL,SW_SHOWNORMAL
          invoke ExitProcess,eax
ret
   endproc ;Win00a

;---------
;WINMAIN
;---------
   proc WinMain ,hInst,hPinst,CmdLn,dwShow
          
;Memory block reserved for wcx [WNDCLASSEX] has no data yet. 

;A different method of populating memory slots.
push dword WNDCLASSEX_size
pop dword [wcx  + WNDCLASSEX.cbSize]

push dword argv(hInst)      
pop dword [wcx  + WNDCLASSEX.hInstance]

push dword szClass
pop dword [wcx  + WNDCLASSEX.lpszClassName]

push dword WndProc    ; Adr of WndProc
pop dword [wcx  + WNDCLASSEX.lpfnWndProc]

push dword COLOR_BTNFACE +1
pop dword [wcx  + WNDCLASSEX.hbrBackground]
          
          invoke RegisterClassExA, dword wcx 

;------------------
;Create The Window
;------------------
          invoke CreateWindowExA,\
           WS_EX_OVERLAPPEDWINDOW,\
                          szClass,\
                          szTitle,\
                WS_OVERLAPPEDWINDOW +WS_VISIBLE ,\
                  50, 50, 660, 200,\
                                NULL,\
                                NULL,\
           			dword argv(hInst),\
                                NULL

;EAX returns handle to window. Store it in global variable.
          mov [hWnd], eax

;------------------------
;Process Windows Messages
;------------------------
      MsgGet:
          invoke GetMessageA, msg, NULL, NULL, NULL
          cmp eax,0
             jnz MsgProcess
          jmp MsgEnd
      MsgProcess:
      	  invoke TranslateMessage, msg
      	  invoke DispatchMessageA, msg
      	  jmp MsgGet
      MsgEnd:
          mov eax,dword [msg +MSG.wParam]
ret
   endproc ;WinMain

;------------------
;WNDPROC CALLBACK
;------------------

   proc WndProc, hWin, uMsg, wParam, lParam

      IsDestroy?:
          cmp dword argv(uMsg),dword WM_DESTROY
      	    jnz DefWndProc  ;Msg not handled. Pass it to DefWndProc
          jmp ExitWin00a

      DefWndProc:
          invoke DefWindowProcA,dword argv(hWin),dword argv(uMsg), \
                                dword argv(wParam),dword argv(lParam)
ret

      ExitWin00a:
          invoke PostQuitMessage,dword NULL   
          xor eax,eax
ret

   endproc     ;WndProc
;-------------------------------------------------
;mcamember May 9, 2024