Author Topic: Examples for Win64 Iczelion tutorial  (Read 48338 times)

Mikl__

  • Member
  • ****
  • Posts: 542
Examples for Win64 Iczelion tutorial
« on: April 30, 2015, 03:14:46 PM »
Attention!
The programs were written and tested in Windows Seven pro, how the programs will work in Windows eight I don't know
Win x64 Tutorial #2: MessageBox
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
.code
WinMain proc
sub rsp,5*8
        invoke MessageBox,NULL,&MsgBoxText,&MsgCaption,MB_OK
        invoke ExitProcess,NULL
WinMain endp
MsgCaption      db "Iczelion's tutorial #2",0
MsgBoxText      db "Win64 Assembly is Great!",0
end
bat-file
Code: [Select]
cls
set masm64_path=\masm64\
set filename=%1
if exist %1.rc (
%masm64_path%bin\RC /r  %filename%.rc || exit
%masm64_path%bin\cvtres /machine:X64 %filename%.res || exit
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj %filename%.res /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
del %filename%.res
) else (
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
)
Win x64 Tutorial #2a: MessageBox
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include user32.inc
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
.code
WinMain proc
enter 4*8,0
xor ecx,ecx
mov r9,rcx
lea r8,MsgCaption
lea edx,MsgBoxText
        call MessageBox
        leave
ret
WinMain endp
MsgCaption      db "Iczelion's tutorial #2a",0
MsgBoxText      db "Win64 Assembly is Great!",0
end
Win x64 Tutorial #2b: MessageBox
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
.code
WinMain proc

push rbp
mov rbp,rsp
sub rsp,30h
invoke GetModuleHandle,NULL
mov x1,rax
invoke LoadIcon,NULL,IDI_APPLICATION
mov x2,rax
        invoke LoadCursor,NULL,IDC_ARROW
mov x3,rax
mov rax,x1
mov [rsp+20h],eax
lea ecx,buffer
lea edx,fmt
mov r8,x3
mov r9,x2
call wsprintf
        invoke MessageBox,NULL,&buffer,&MsgCaption,MB_OK
        invoke ExitProcess,NULL
WinMain endp
MsgCaption      db "Iczelion's tutorial #2b",0
fmt db "hCursor = %08Xh",0Ah,"hIcon = %08Xh",0Ah,"hInstance =%08Xh",0
n = $ - fmt + 12
buffer db n dup(?)
x1 dq ?
x2 dq ?
x3 dq ?
end
« Last Edit: August 19, 2015, 04:40:18 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Exapmles for Win64 Iczelion tutorial
« Reply #1 on: April 30, 2015, 03:34:33 PM »
Win x64 Tutorial #3: A Simple Window

Code: [Select]
include win64a.inc
.code
WinMain proc
local msg:MSG
        push rbp
        mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
        mov eax,10029h
push rax ;hIconSm
mov edi,offset ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOWTEXT;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
mov eax,offset WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
    call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
    call CreateWindowEx
@@: lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
        call GetMessage
lea ecx,msg
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:cmp edx,WM_DESTROY
je wmDESTROY
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
;---------------------------------------
ClassName db 'Win64 Iczelion lesson #3',0
end
  • call fuctions GetModuleHandle, LoadIcon, LoadCursor is unnecessary, they always return the same number, you can see the debugger in advance or in "Tutorial 2b: MessageBox"
  • instead PostQuitMessage directly use ExitProcess it will simplify the message loop
« Last Edit: August 19, 2015, 10:35:04 AM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #2 on: April 30, 2015, 03:57:57 PM »
Win x64 Tutorial #4: Painting with Text
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:
hwnd            equ [rbp+10h]
ps              equ [rbp-sizeof PAINTSTRUCT]
expRect         equ ps-sizeof RECT

enter sizeof PAINTSTRUCT+sizeof RECT+28h,0

              mov  hwnd,rcx
              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp  edx,WM_PAINT
              je   wmPAINT
              cmp  edx,WM_SIZE
              je   wmPAINT
              leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmSIZE:       mov r8d,1
              xor edx,edx
              call InvalidateRect;send WM_PAINT if size changes
              jmp wmBYE
wmPAINT:      lea edx,ps
              call BeginPaint
              mov rcx,hwnd
              lea rdx,expRect
              call GetClientRect
              mov qword ptr [rbp-60h],DT_SINGLELINE or DT_CENTER or DT_VCENTER
              lea r9,expRect
              or r8,-1
              lea edx,expTxt
              mov rcx,ps.PAINTSTRUCT.hdc
              call DrawText
              lea edx,ps
              mov rcx,hwnd
              call EndPaint
wmBYE:        leave
              retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #4: Painting with Text',0
expTxt    db 'Win64 assembly with MASM is great and easy',0

end
« Last Edit: August 19, 2015, 04:43:24 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #3 on: April 30, 2015, 04:20:43 PM »
Win x64 Tutorial #5: More about Text
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:
hwnd            equ [rbp+10h]
ps              equ [rbp-sizeof PAINTSTRUCT]

enter sizeof PAINTSTRUCT+98h,0

              mov  hwnd,rcx
              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp  edx,WM_PAINT
              je   wmPAINT
              leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmPAINT:      lea edx,ps
              call BeginPaint
              mov edx,OBJ_FONT
               mov rcx,ps.PAINTSTRUCT.hdc
               call GetCurrentObject
               push rax       ;default font object
lea rax,expFont
               push rax
               push DEFAULT_PITCH or FF_SCRIPT
               push rbx;DEFAULT_QUALITY
               push rbx;CLIP_DEFAULT_PRECIS
               push rbx;OUT_DEFAULT_PRECIS
               push OEM_CHARSET
               push rbx
               push rbx
               push rbx
               push 400
               mov r9,rbx
               mov r8,rbx
               mov edx,12
               mov ecx,26
       push rbx
       push rbx
       push rbx
       push rbx
               call CreateFont
                    mov rdx,rax
                    mov rcx,ps.PAINTSTRUCT.hdc
                    call SelectObject
                    mov edx,32C8C8h
                    mov rcx,ps.PAINTSTRUCT.hdc
                    call SetTextColor
                    mov edx,0FF0000h
                    mov rcx,ps.PAINTSTRUCT.hdc
                    call SetBkColor
                    lea ecx,expTxt
                    call lstrlen           ;help us to count the string length
                    push rax
                    lea r9,expTxt
                    xor edx,edx
                    mov r8,rdx
                    mov rcx,ps.PAINTSTRUCT.hdc
    push rbx
    push rbx
                    push rbx
                    push rbx
                    call TextOut
                    add rsp,30h
                    pop  rdx
                    mov rcx,ps.PAINTSTRUCT.hdc
                    call SelectObject
              lea edx,ps
              mov rcx,hwnd
              call EndPaint
wmBYE:        leave
              retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #5:More about Text',0
expTxt    db 'Win64 assembly with MASM is great and easy',0
expFont   db   'script',0
end
« Last Edit: August 19, 2015, 04:45:02 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #4 on: April 30, 2015, 05:47:04 PM »
Win x64 Tutorial #6: Keyboard Input
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 352
push 512
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call TranslateMessage
        mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:
hwnd            equ [rbp+10h]
ps              equ [rbp-sizeof PAINTSTRUCT]

enter sizeof PAINTSTRUCT+20h,0

              mov  hwnd,rcx
              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp edx,WM_CHAR
              je wmCHAR
              cmp  edx,WM_PAINT
              je   wmPAINT
              leave
              jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
 wmCHAR:        mov expChar,r8
                mov r8d,TRUE
                xor edx,edx
                call InvalidateRect
                jmp wmBYE
wmPAINT:      lea edx,ps
              call BeginPaint
                sub rsp,10h
                mov qword ptr [rsp+20h],lengthof Message
                lea r9,Message
                mov r8d,90
                mov edx,192
                mov rcx,ps.PAINTSTRUCT.hdc
                call TextOut
                mov qword ptr [rsp+20h],1
                lea r9,expChar
                mov r8d,150
                mov edx,242
                mov rcx,ps.PAINTSTRUCT.hdc
                call TextOut
                add rsp,10h
                lea edx,ps
                mov rcx,hwnd
                call EndPaint
wmBYE:          leave
                retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #6: Keyboard Input',0
Message   db 'Press any key'
expChar   dq   '?'
end
« Last Edit: July 01, 2015, 03:25:56 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #5 on: April 30, 2015, 06:00:25 PM »
Win x64 Tutorial 7: Mouse Input
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:
hwnd            equ [rbp+10h]
ps              equ [rbp-sizeof PAINTSTRUCT]

enter sizeof PAINTSTRUCT+30h,0

              mov  hwnd,rcx
              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp  edx,WM_PAINT
              je   wmPAINT
              cmp edx,WM_LBUTTONDOWN
              je wmLBUTTONDOWN
              leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmLBUTTONDOWN:  ;low order lParam  = x
                ;high order lParam = y
                mov word ptr expHPoint.x,r9w;eax
                shr r9,16
                mov expHPoint.y,r9d
                or expClick,TRUE
                mov r8d,TRUE
                xor edx,edx
                call InvalidateRect
                jmp  wmBYE
wmPAINT:      lea edx,ps
              call BeginPaint
              cmp expClick,TRUE
                jne  wmPAINT_END
                mov qword ptr [rsp+20h],lengthof expTxt
                lea r9,expTxt
                mov r8d,expHPoint.y
                mov edx,expHPoint.x
                mov rcx,ps.PAINTSTRUCT.hdc
                call TextOut
wmPAINT_END:    lea edx,ps
              mov rcx,hwnd
              call EndPaint
wmBYE:        leave
              retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #7:Mouse Input',0
expTxt    db 'You clicked here!',0
expClick  db   0
expHPoint POINT <0>
end
« Last Edit: July 01, 2015, 03:25:25 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #6 on: April 30, 2015, 06:22:41 PM »
Win x64 Tutorial #7a: Mouse Input
In difference from Lesson 7 Iczelion'a which handles the event by pressing the left click and output only the inscription "You clicked here!", we will handle pressing the left and right mouse click, and will display the inscription "left-clicking" and "right-clicking "and these inscriptions will be so much the importance we assign a constant MAXRECTS. If the number exceeds the number of clicks MAXRECTS is a beep sounds.

Code: [Select]
include win64a.inc
include gdi32.inc
includelib gdi32.lib

MAXRECTS = 40;the maximum number of processed mouse clicks
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
    call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
    call CreateWindowEx
@@: lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
        call GetMessage
lea ecx,msg
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:
hwnd            equ [rbp+10h]
lParam          equ [rbp+28h]
ps              equ [rbp-sizeof PAINTSTRUCT]

enter sizeof PAINTSTRUCT+30h,0
              mov lParam,r9
xor eax,eax
              mov  hwnd,rcx
              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp  edx,WM_PAINT
              je   wmPAINT
              cmp edx,WM_LBUTTONDOWN
              je wmLBUTTONDOWN
                cmp edx,WM_RBUTTONDOWN
                je wmRBUTTONDOWN
              leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmLBUTTONDOWN:  ;low order lParam  = x
                ;high order lParam = y
                mov eax,80000000h
wmRBUTTONDOWN:  add eax,lParam
                cmp nextRect,MAXRECTS-1
                jge @f
                inc nextRect
                mov ecx,nextRect
                mov [ecx*4+recs],eax
                xor edx,edx
                mov rcx,hwnd
                mov r8d,TRUE
                call InvalidateRect
                jmp wmBYE
@@:             xor ecx,ecx
                call MessageBeep
                jmp  wmBYE
wmPAINT:      mov ebx,nextRect
                inc ebx;cmp nextRect,-1
                jz wmBYE
lea edx,ps
              call BeginPaint
              mov edx,TRANSPARENT
                mov rcx,rax
                call SetBkMode
@@:             mov eax,[ebx*4+recs-4]
                mov ecx,1
                shl eax,1
                adc ecx,0
                shr eax,1
                shl ecx,4
                xor edx,edx
                mov dx,ax;nYStart
                shr eax,16
                mov r8d,eax;nXStart
                mov rax,[PS+ecx]
                mov [rsp+20h],rax;cchString
                mov r9,[PS+ecx+8];lpString
                mov rcx,ps.PAINTSTRUCT.hdc
                call TextOut
                dec  ebx
                jnz @b
wmPAINT_END:    lea edx,ps
              mov rcx,hwnd
              call EndPaint
wmBYE:        leave
              retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #7a: Mouse Input',0
text1   db 'right-clicking'
text2   db 'left-clicking'
PS      dq 0,0,lengthof text1, text1, lengthof text2, text2
recs    dd MAXRECTS dup(?)
nextRect dd     -1
end                   
« Last Edit: August 24, 2015, 05:14:22 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #7 on: April 30, 2015, 06:53:35 PM »
Win x64 Tutorial #8: Menu
asm-file
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
ZZZ_TEST equ 0
ZZZ_OPEN equ 1
ZZZ_SAVE equ 2
ZZZ_EXIT equ 3
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0
xor ebx,ebx
push 10029h ;hIconSm
lea rdi,ClassName
push rdi ;lpszClassName
lea eax,menu_name
push rax ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,400000h
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea rax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:

enter 20h,0

              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp  edx,WM_COMMAND
              je   wmCOMMAND
              leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmCOMMAND:cmp r8,ZZZ_EXIT
        je wmDESTROY
show_msg:mov r9,rbx;r9=MB_OK
mov rdx,menu_handlers[r8*8]
        lea r8,menu_name
        call MessageBox
wmBYE:        leave
              retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #8: Menu',0
menu_name db 'ZZZ_Menu',0
test_msg        db      'You select menu item TEST',0
open_msg        db      'You select menu item OPEN',0
save_msg        db      'You select menu item SAVE',0
menu_handlers dq test_msg, open_msg, save_msg
end
rc-file
Code: [Select]
#define ZZZ_TEST 0
#define ZZZ_OPEN 1
#define ZZZ_SAVE 2
#define ZZZ_EXIT 3

ZZZ_Menu MENU
{
POPUP "&File"
{       MENUITEM "&Test",ZZZ_TEST
MENUITEM "&Open",ZZZ_OPEN
MENUITEM "&Save",ZZZ_SAVE
                MENUITEM SEPARATOR
MENUITEM "&Exit",ZZZ_EXIT
}
MENUITEM "&Exit",ZZZ_EXIT
}
« Last Edit: July 01, 2015, 03:30:16 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #8 on: April 30, 2015, 07:41:25 PM »
Win x64 Tutorial #25: Simple Bitmap
like Iczelion's tutoral
asm-file
Code: [Select]
include win64a.inc
include gdi32.inc
includelib gdi32.lib

IMAGE_BASE      equ 400000h
IDB_MYBITMAP    equ 100
.code
WinMain proc
local msg:MSG
      push rbp
      mov rbp,rsp
sub rsp,sizeof MSG

xor ebx,ebx     

push 10029h ;hIconSm       
mov edi,offset ClassName
push rdi ;lpszClassName 
push rbx ;lpszMenuName   
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor       
push 10029h        ;hIcon       
mov esi,IMAGE_BASE
push rsi ;hInstance     
push rbx        ;cbClsExtra & cbWndExtra
mov eax,offset WndProc
push rax ;lpfnWndProc             
push sizeof WNDCLASSEX;cbSize & style   
mov rcx,rsp ;addr WNDCLASSEX
push rbx       
push rbx                                 
push rbx                                 
push rbx                                 
    call RegisterClassEx
push rbx                                 
push rsi ;rsi=400000h             
shr esi,7;Special CreateWindow position value CW_USEDEFAULT=8000h
push rbx                                 
push rbx                                 
push 320
push 300
push rsi                                 
push rsi                                 
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx                             
push rbx                                 
push rbx                                 
push rbx                                 
push rbx                                 
    call CreateWindowEx
lea edi,msg
@@:   mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
      call GetMessage
mov ecx,edi
      call DispatchMessage
      jmp @b
WinMain endp
;---------------------------------------------------------------
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   LOCAL ps:PAINTSTRUCT
   LOCAL hMemDC:HDC
   LOCAL rect:RECT

        push rbp
        mov rbp,rsp
        sub rsp,sizeof PAINTSTRUCT+sizeof RECT+8+40h
       
        mov hWnd,rcx
       
        cmp edx,WM_DESTROY
je wmDESTROY
        cmp edx,WM_CREATE
je wmCREATE
        cmp edx,WM_PAINT
je wmPAINT
        leave
        jmp DefWindowProc
wmDESTROY:mov rcx,hBitmap
        call DeleteObject
        xor ecx,ecx
        call ExitProcess
wmCREATE:mov edx,IDB_MYBITMAP
        mov ecx,IMAGE_BASE
        call LoadBitmap
        mov hBitmap,rax
        jmp wmBYE
wmPAINT:lea edx,ps
        call BeginPaint
        mov rcx,rax
        call CreateCompatibleDC
        mov hMemDC,rax
        mov rdx,hBitmap
        mov rcx,rax
        call SelectObject
        lea edx,rect
        mov rcx,hWnd
        call GetClientRect
        mov qword ptr [rsp+40h],SRCCOPY
        mov [rsp+38h],rbx
        mov [rsp+30h],rbx
        mov rax,hMemDC
        mov [rsp+28h],rax
        mov eax,rect.bottom
        mov [rsp+20h],rax
        mov r9d,rect.right
        mov r8,rbx
        xor edx,edx
        mov rcx,ps.hdc
        call BitBlt
        mov rcx,hMemDC
        call DeleteDC
        lea edx,ps
        mov rcx,hWnd
        call EndPaint       
wmBYE:  leave
        retn
 WndProc endp
;---------------------------------------
ClassName   db 'Win64 Iczelion lesson #25a',0
hBitmap     dq ?
end
rc-file
Code: [Select]
#define IDB_MYBITMAP   100
IDB_MYBITMAP  BITMAP  "Images\\tweety78.bmp"
but it can be a lot easier
Code: [Select]
include win64a.inc
include gdi32.inc
includelib gdi32.lib

.code
WinMain proc
local msg:MSG

        push rbp
        mov rbp,rsp
sub rsp,sizeof MSG

xor ebx,ebx

        mov esi,400000h
lea rdi,ClassName
        mov qword ptr [rsp+28h],LR_LOADFROMFILE
        mov [rsp+20h],rbx
        mov r9,rbx
        mov r8,rbx
        mov edx,edi
        mov ecx,esi
        call LoadImage
        mov rcx,rax
        call CreatePatternBrush
push 10029h ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push rax ;hbrBackground
push 10005h ;hCursor
push 10029h     ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea eax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 305
push 286
push rsi
push rsi
mov r9d,WS_OVERLAPPED or WS_VISIBLE or WS_CAPTION or \
        WS_SYSMENU or WS_MINIMIZEBOX
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:cmp  edx,WM_DESTROY
        je   wmDESTROY
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
;---------------------------------------
ClassName db 'Images\tweety78.bmp',0
end
« Last Edit: August 18, 2015, 05:19:16 PM by Mikl__ »

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Examples for Win64 Iczelion tutorial
« Reply #9 on: May 01, 2015, 10:32:20 PM »
those are nice, Mikl   :t
i haven't had the chance to play with 64-bit code
but, when i get around to it, these will come in handy

Zen

  • Member
  • ****
  • Posts: 962
  • slightly red-shifted
Re: Examples for Win64 Iczelion tutorial
« Reply #10 on: May 02, 2015, 03:48:15 AM »
Hi, Miki__,
Great Stuff,...I was wondering what MASM 64-bit code looked like,...
Where do you find: win64.inc ???
Zen

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #11 on: May 02, 2015, 11:02:12 AM »
Quote from: Zen
Where do you find: win64.inc ???
Hi, Zen!
On the site http://dsmhelp.narod.ru/environment.htm you can find a set of lib- and inc-files to create 64-bit applications in assembler, as well as a lot of useful macros. Sorry, but the forum rules do not allow me to attach the zip-file size of 4 MB with lib- and inc- files. You can easily find lib- and inc-files  in my attach-files above.

Zen

  • Member
  • ****
  • Posts: 962
  • slightly red-shifted
Re: Examples for Win64 Iczelion tutorial
« Reply #12 on: May 03, 2015, 02:40:38 AM »
Thanks, Miki__,
Quote from: MIKI__
On the site http://dsmhelp.narod.ru/environment.htm you can find a set of lib- and inc-files to create 64-bit applications in assembler, as well as a lot of useful macros.
Zen

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Examples for Win64 Iczelion tutorial
« Reply #13 on: May 03, 2015, 09:32:02 PM »
Hi Mikl__,

you're a hard working man. Good work by the way.

Gunther
Get your facts first, and then you can distort them.

Mikl__

  • Member
  • ****
  • Posts: 542
Re: Examples for Win64 Iczelion tutorial
« Reply #14 on: May 05, 2015, 12:43:58 PM »
Win x64 Tutorial #8a: Menu and LoadMenu
asm-file
Code: [Select]
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
OPTION PROLOGUE:rbpFramePrologue
OPTION EPILOGUE:rbpFrameEpilogue
ZZZ_TEST equ 0
ZZZ_OPEN equ 1
ZZZ_SAVE equ 2
ZZZ_EXIT equ 3
IMAGE_BASE equ 400000h
ZZZ_Menu equ 30
.code
WinMain proc
msg equ [rbp-sizeof MSG]

enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0
xor ebx,ebx
push 10029h ;hIconSm
lea edi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push 10029h        ;hIcon
mov esi,IMAGE_BASE
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
lea eax,WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov rcx,rsp ;addr WNDCLASSEX
push rbx
push rbx
push rbx
push rbx
    call RegisterClassEx
add rsp,sizeof WNDCLASSEX+20h
        mov edx,ZZZ_Menu
mov ecx,IMAGE_BASE
call LoadMenu
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rax
push rbx
push rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc:

enter 20h,0

              cmp  edx,WM_DESTROY
              je   wmDESTROY
              cmp  edx,WM_COMMAND
              je   wmCOMMAND
              leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmCOMMAND:cmp r8,ZZZ_EXIT
        je wmDESTROY
show_msg:mov r9,rbx;r9=MB_OK
mov rdx,menu_handlers[r8*8]
        lea r8,menu_name
        call MessageBox
wmBYE:        leave
              retn
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #8a: Menu and LoadMenu',0
menu_name db 'ZZZ_Menu',0
test_msg        db      'You select menu item TEST',0
open_msg        db      'You select menu item OPEN',0
save_msg        db      'You select menu item SAVE',0
menu_handlers dq test_msg, open_msg, save_msg
end
rc-file
Code: [Select]
#define ZZZ_TEST 0
#define ZZZ_OPEN 1
#define ZZZ_SAVE 2
#define ZZZ_EXIT 3
#define ZZZ_Menu 30

ZZZ_Menu MENU
{
POPUP "&File"
{       MENUITEM "&Test",ZZZ_TEST
MENUITEM "&Open",ZZZ_OPEN
MENUITEM "&Save",ZZZ_SAVE
                MENUITEM SEPARATOR
MENUITEM "&Exit",ZZZ_EXIT
}
MENUITEM "&Exit",ZZZ_EXIT
}
« Last Edit: July 01, 2015, 03:31:16 PM by Mikl__ »