Win04.ASM : BeginPaint / TextOut /EndPaint 


;Win04.ASM : BeginPaint / TextOut /EndPaint (May 9, 2024)
;====================================================================
%ifdef
   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 win04.asm -o win04.obj

       Linking: GDI32 is added to the linker string.
            golink.exe /entry:start win04.obj  kernel32.dll user32.dll gdi32.dll
%endif

%include '\nasm32\inc\win32\windows.inc'
%include '\nasm32\inc\win32\kernel32.inc'
%include '\nasm32\inc\win32\user32.inc'
%include '\nasm32\inc\nasm32.inc'
%include '\nasm32\inc\win32\gdi32.inc'

;                        ---------------
                         [section .data]
;                        ---------------
;-------
;STRUCS
;-------
      wcx times WNDCLASSEX_size dd 0     
      msg times MSG_size dd 0              
      ps times PAINTSTRUCT_size dd 0     
;----------
;Messages
;----------
     MsgText db "This UGLY message brought to you by BeginPaint/TextOut/EndPaint ",0
     lMsgText equ $-MsgText -1     ;Len of MsgText without zero term

     MsgExit db "Hit ESC or ALT/F4 or SYSMENU 'x' to quit.",0
     lMsgExit equ $-MsgExit -1

;-------
;HANDLES
;-------
     hDC dd 0       ; Handle to the Device Context
     hInstance dd 0
     hWnd dd 0
;--------------
;VARIOUS LABELS
;--------------
     szTitle db 'Win04 : NASM Window With Display Using BeginPaint/Text Out/EndPaint',0x0
     szClass db 'win04 Class',0x0


;                        ---------------
                         [section .text]
;                        ---------------
start:          

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

;---------------------------------------
      proc WinMain ,hInst,hPinst,CmdLn,dwShow

;Block reserved for wcx [WNDCLASSEX] has no data yet. 

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]

push dword CS_VREDRAW +CS_HREDRAW
pop dword [wcx + WNDCLASSEX.style]

           
           invoke RegisterClassExA, dword wcx
;-----------
;Load Window
;-----------
          invoke CreateWindowExA,\
           WS_EX_OVERLAPPEDWINDOW,\
                          szClass,\
                          szTitle,\
                WS_OVERLAPPEDWINDOW +WS_VISIBLE ,\
                  50, 120, 590, 250,\
                                NULL,\
                               NULL,\
                 dword [hInstance],\
                                NULL

           mov [hWnd], eax

;-------------------------
;Process Windows Messages
;-------------------------
      MsgGet:
          invoke GetMessageA, dword msg, dword NULL, dword NULL, dword NULL
          cmp eax,0
              jnz MsgProcess
          jmp MsgEnd

      MsgProcess:
            invoke TranslateMessage, dword msg
            invoke DispatchMessageA, dword msg
            jmp MsgGet
      MsgEnd:
         ret
      endproc ;WinMain

;-------------------------
;Windows Callback Function
;-------------------------
      proc WndProc, hWin, uMsg, wParam, lParam

      Is_Key?:
           cmp dword argv(uMsg),dword WM_KEYDOWN
               jz uMsgKey
           cmp dword argv(uMsg),dword WM_PAINT
               jz Painter
           cmp dword argv(uMsg),dword WM_DESTROY
               jz near ExitWin04

              jmp DefWndProc

      uMsgKey:
           cmp argv(wParam), dword VK_ESCAPE   ; ESC Key ?
               jz near ExitWin04
           xor eax,eax
      ret				
	  
      Painter:
           invoke BeginPaint,dword argv(hWin),ps
           mov dword [hDC],eax    
           invoke TextOutA,dword [hDC],0,100,MsgText,lMsgText
           invoke TextOutA,dword [hDC],0,120,MsgExit,lMsgExit
           invoke EndPaint,dword argv(hWin),ps
           xor eax,eax
      ret     


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

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

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