News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Examples for Win64 Iczelion tutorial

Started by Mikl__, April 30, 2015, 03:14:46 PM

Previous topic - Next topic

Mikl__

#45
Win64 Tutorial #7a: Creating a cursor and icons from file

include win64a.inc
include gdi32.inc
includelib gdi32.lib

IMAGE_BASE equ 400000h

.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov ecx,offset FileName
call LoadCursorFromFile

push rax ;hIconSm
lea edi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push rax ;hCursor
push rax        ;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
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 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

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess

WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #7a: Creating a cursor and icons from file',0
FileName db "Images\cursor.cur",0
end

Win64 Tutorial #7b: Creating a cursor and icons from resources
asm-fileinclude win64a.inc
include gdi32.inc
includelib gdi32.lib

IMAGE_BASE equ 400000h
ID_CURSOR = 18
.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov edx,ID_CURSOR
mov ecx,IMAGE_BASE
call LoadCursor

push rax ;hIconSm
lea edi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push rax ;hCursor
push rax        ;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
    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 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

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess

WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #7b: Creating a cursor and icons from resources',0
end
rc-file#define ID_CURSOR  18

ID_CURSOR CURSOR "Images\\cursor.cur"

Win64 Tutorial #7c: Icon binary datas
include win64a.inc
include gdi32.inc
includelib gdi32.lib

IMAGE_BASE equ 400000h
ICON_SIZE = 744  ;taille de Icon.ico (header=22 Image=744) total=766
.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov ecx,offset FileName
call LoadCursorFromFile

push rax ;hIconSm
lea edi,ClassName
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;hbrBackground
push rax ;hCursor
push rax        ;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
    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

mov r9d,030000h
or r8,-1
mov edx,ICON_SIZE
mov ecx,offset ptIcon
call CreateIconFromResource
mov hIcon,rax

    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

local ps:PAINTSTRUCT
push rbp
mov ebp,esp
sub esp,sizeof PAINTSTRUCT+20h

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 r9,hIcon
mov r8d,68
mov edx,134
mov ecx,eax
call DrawIcon
lea edx,ps
mov rcx,hWnd
call EndPaint
wmBYE: leave
retn
WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #7-3:Icone datas binaire',0
FileName db 'Images\cursor.cur',0
hIcon     dq ?
ptIcon:;sauter le header du fichier d'icone
; пропуск первых 22 байт
db 40,0,0,0,32,0,0,0,64,0,0,0,1,0,4,31 dup(0)
db 128,0,0,128,0,0,0,128,128,0,128,0
db 0,0,128,0,128,0,128,128,0,0,192,192,192,0,128,128
db 128,0,0,0,255,0,0,255,0,0,0,255,255,0,255,0
db 0,0,255,0,255,0,255,255,0,0,255,255,255,0,0,10
db 5 dup(170),160,10 dup(0),3 dup(170),160,12 dup(0)
db 10,170,0,10,4 dup(170),0,128,8 dup(0)
db 10,6 dup(170),168,6 dup(0)
db 8,10,170,160,0,0,0,10,170,170,7 dup(0)
db 170,170,1,16,5 dup(170),168,5 dup(0)
db 10,170,160,17,10,4 dup(170),0,0,0,128,0,0,0
db 74,170,160,16,8 dup(170),160,0,8,0
db 0,170,160,10,9 dup(170),0,128,10
db 3 dup(170),10,170,160,8,6 dup(170),168,0,170
db 170,170,160,0,170,138,160,136,160,4 dup(170),160,10,170
db 170,74,170,170,168,170,15,0,0,10,170,170,170,168,10,170
db 164,10,170,170,10,160,255,0,15,0,10,170,170,0,10,170
db 64,10,160,168,10,160,255,240,15,0,0,0,0,0,10,160
db 0,170,160,8,10,160,4 dup(255),10,0,0,0,0,170
db 170,170,0,128,10,160,255,255,15,255,10,0,0,0,7,10
db 170,160,8,248,10,170,15,240,15,240,170,0,0,0,15,112
db 0,15,255,255,0,170,160,10,168,10,160,128,0,0,15,5 dup(255)
db 128,170,170,170,138,170,8,0,0,0,7,5 dup(255)
db 248,10,170,160,96,0,0,0,0,0,0,6 dup(255)
db 128,0,15,255,247,112,0,0,0,0,9 dup(255)
db 119,119,128,0,128,0,0,6 dup(255)
db 127,136,136,128,8,255,255,248,0,8,127
db 5 dup(255),247,112,8,4 dup(255),240,0,0,15
db 5 dup(255),248,143,5 dup(255),240,0,0,135
db 12 dup(255),248,0,0,0,12 dup(255),0,0,0,0
db 7,10 dup(255),240,5 dup(0),135,8 dup(255),247,7 dup(0)
db 7,6 dup(255),247,8,8 dup(0)
db 8,127,3 dup(255),247,8,10 dup(0)
db 128,0,0,0,8,5 dup(0),192,0
db 255,255,224,0,15,255,240,0,1,255,248,0,0,255,248,0
db 0,127,248,0,0,63,240,0,0,7,224,0,0,3,128,0
db 0,1,15 dup(0),1,0,0,0,3,4 dup(0,0,0,31)
db 0,0,0,63,0,0,0,127,128,0
db 0,63,128,0,0,7,128,0,0,3,128,0,0,3,192,0
db 0,3,192,0,0,3,224,0,0,7,240,0,0,15,248,0
db 0,31,254,0,0,63,255,128,0,255,255,240,3,255
end

Gunther

Mikl__,

Quote from: Mikl__ on May 25, 2015, 12:27:37 PM
what should be the first step?

I'll provide some web space for your examples, the jWasm sources etc. That'll take some time.

Gunther
You have to know the facts before you can distort them.

Mikl__

I have time to translate all the Iczelion tutorials on x64

Mikl__

#48
Win64 Tutorial #11: More about Dialog Box

asm-file
include win64a.inc

IMAGE_BASE equ 400000h
ZZZ_OPEN   equ  0
ZZZ_EXIT   equ  1
MAXSIZE         equ 256
OUTPUTSIZE equ 512
IDR_MAINMENU equ 30
.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon

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
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
mov ecx,WS_EX_CLIENTEDGE
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, wParam, lParam

local dlgOpenBuffer [MAXSIZE]:BYTE
strMsgSize     equ  512
local strMsg [strMsgSize]:BYTE

        push rbp
mov ebp,esp
sub esp,20h+MAXSIZE+strMsgSize

        mov esi,offset dlgOpenOfn
mov hWnd,rcx

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_CREATE
        je   wmCREATE
        leave
        jmp DefWindowProc

wmDESTROY:call DestroyWindow
xor ecx,ecx
        call ExitProcess
wmCOMMAND:cmp r8d,ZZZ_OPEN
        jnz wmDESTROY
mov ecx,esi;offset dlgOpenOfn.lStructSize
call GetOpenFileName
or eax,eax
jz wmBYE
        mov ecx,OUTPUTSIZE
        lea rdi,strMsg
        mov esi,offset FullPathName
        call StringOut1
mov rsi,dlgOpenOfn.lpstrFile
call StringOut1
mov esi,offset FullName
call StringOut1
movzx rsi,dlgOpenOfn.nFileOffset
add rsi,dlgOpenOfn.lpstrFile
call StringOut1
mov esi,offset ExtensionName
call StringOut1
movzx rsi,dlgOpenOfn.nFileExtension
add rsi,dlgOpenOfn.lpstrFile
call StringOut1
mov [rdi],rbx
mov rcx,hWnd
mov r9,rbx;r9=MB_OK
        mov r8d,offset ClassName
lea rdx,strMsg
        call MessageBox
jmp wmBYE
wmCREATE:lea eax,dlgOpenBuffer
mov [rsi+OPENFILENAME.lpstrFile],rax
wmBYE:  leave
        retn
WndProc endp
StringOut1 proc
@@: movsb
cmp [rsi],bl
loopnz @b
retn
StringOut1 endp
;---------------------------------------
.data
ClassName db 'Win64 Iczelion''s lesson #11: More about Dialog Box',0
dlgOpenTitle db 'Open File',0
dlgOpenOfn     OPENFILENAME <{sizeof OPENFILENAME},,IMAGE_BASE,\
FilterString,,,,,{MAXSIZE},,,,,,,,,,,,,,>

FilterString  db 'All Files (*.*)',0,'*.*',0
      db 'Text Files (*.txt)',0,'*.txt',0,0
FullPathName  db 'The Full Filename with Path is : ',0
FullName      db 10,'The Filename is : ',0
ExtensionName db 10,'The Extension is : ',0
end
rc-file#define ZZZ_OPEN 0
#define ZZZ_EXIT 1
#define IDR_MAINMENU 30

IDR_MAINMENU MENU
{
POPUP "&File"
{       MENUITEM "&Open",ZZZ_OPEN
MENUITEM SEPARATOR
MENUITEM "&Exit",ZZZ_EXIT
}
MENUITEM "&Exit",ZZZ_EXIT
}

Mikl__

Win64 Tutorial #12: Memory Management, File I/O, GlobalAlloc/Lock/Unlock and GlobalFree
asm-fileOPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comdlg32.inc
includelib comdlg32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
ZZZ_OPEN   equ  1
ZZZ_SAVE   equ  2
ZZZ_EXIT   equ  3
MAXSIZE         equ 256
MEM_SIZE equ 65535
EditID equ 1
IDR_MAINMENU equ 30

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
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
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
mov ecx,WS_EX_CLIENTEDGE
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
mov rcx,hwndEdit
call SetFocus
    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 proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

local hMem:QWORD ;handle to the allocated memory block
local pMem:QWORD ;pointer to the allocated memory block
local szReadWrite:QWORD ;number of bytes actually read or write

        push rbp
mov ebp,esp
sub esp,30h+4*8

        mov edi,offset dlgOpenOfn
mov hWnd,rcx
        mov wParam,r8
        mov lParam,r9

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_CREATE
        je   wmCREATE
        cmp  edx,WM_SIZE
je   wmSIZE
        leave
        jmp DefWindowProc

wmDESTROY:xor ecx,ecx
        call ExitProcess
wmSIZE: push TRUE
        movzx rax,word ptr lParam+2
        push rax
movzx r9,word ptr lParam
xor edx,edx
mov r8,rdx
mov rcx,hwndEdit
push rbx
push rbx
push rbx
push rbx
        call MoveWindow
        jmp wmBYE
OPEN: mov [rdi+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or\
OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ecx,edi
call GetOpenFileName
test eax,eax
je @0
push rbx
        push FILE_ATTRIBUTE_ARCHIVE
push OPEN_EXISTING
mov r9,rbx
        mov r8d,FILE_SHARE_READ or FILE_SHARE_WRITE
        mov edx,GENERIC_READ or GENERIC_WRITE
mov ecx,offset dOpenBuffer
push rbx
push rbx
push rbx
push rbx
call CreateFile
mov  edi,eax;handle to file
mov edx,MEM_SIZE
mov ecx,GMEM_MOVEABLE or GMEM_ZEROINIT
call GlobalAlloc
mov hMem,rax
mov ecx,eax
call GlobalLock
mov pMem,rax
push rbx
        lea r9d,szReadWrite
mov r8d,MEM_SIZE-1
mov rdx,rax;pMem
mov ecx,edi
push rbx
push rbx
push rbx
push rbx
call ReadFile
mov r9,pMem
mov r8,rbx
mov edx,WM_SETTEXT
mov rcx,hwndEdit
call SendMessage
jmp @1
SAVE: mov [rdi+OPENFILENAME.Flags],OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ecx,edi;&dOpenOfn
call GetSaveFileName
test eax,eax
je @0
push rbx
push FILE_ATTRIBUTE_ARCHIVE
push CREATE_NEW
mov r9,rbx
mov r8d,FILE_SHARE_READ or FILE_SHARE_WRITE
mov edx,GENERIC_READ or GENERIC_WRITE
mov ecx,offset dOpenBuffer
push rbx
push rbx
push rbx
push rbx
        call CreateFile  
mov edi,eax;hFile
mov edx,MEM_SIZE
mov ecx,GMEM_MOVEABLE or GMEM_ZEROINIT
call GlobalAlloc
mov hMem,rax
mov ecx,eax
call GlobalLock
mov pMem,rax
mov r9,rax ;pMem
mov r8d,MEM_SIZE-1
mov edx,WM_GETTEXT
mov rcx,hwndEdit
call SendMessage
push rbx
lea r9,szReadWrite
mov r8,rax
mov rdx,pMem
mov ecx,edi;hFile
push rbx
push rbx
push rbx
push rbx
call WriteFile
@1: mov ecx,edi;hFile
call CloseHandle
mov rcx,pMem
call GlobalUnlock
mov rcx,hMem
call GlobalFree
@0: mov rcx,hwndEdit
call SetFocus
jmp wmBYE
wmCREATE:mov [rdi+OPENFILENAME.hwndOwner],rcx
push rbx
push IMAGE_BASE
push EditID
push rcx;hWnd
push rbx
push rbx
push rbx
push rbx
mov r9d,WS_VISIBLE or \
  WS_CHILD or ES_LEFT or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or\
  ES_AUTOHSCROLL or ES_AUTOVSCROLL
mov r8,rbx
mov edx,offset EditClass
xor ecx,ecx
;-------------------------------
push rbx
push rbx
push rbx
push rbx
        call CreateWindowEx
mov hwndEdit,rax
        jmp wmBYE
wmCOMMAND:movzx rax,word ptr wParam
        cmp r9,rbx ;cmp lParam,0
jnz wmBYE
cmp rax,ZZZ_EXIT
ja  wmBYE
jmp  [menu_handlers+rax*8]
EXIT: call DestroyWindow
wmBYE:  leave
        retn
menu_handlers dq wmBYE,OPEN,SAVE,EXIT
WndProc endp
;---------------------------------------
ClassName     db 'Win64 Iczelion''s lesson #12: Memory Management, File I/O, GlobalAlloc/Lock/Unlock and GlobalFree',0
dlgOpenTitle  db 'Open File',0
align 8
dlgOpenOfn    OPENFILENAME <{sizeof OPENFILENAME},,IMAGE_BASE,\
FilterString,,,,dOpenBuffer,{MAXSIZE},,,,,,,,,,,,,,>
FilterString  db 'All Files (*.*)',0,'*.*',0
      db 'Text Files (*.txt)',0,'*.txt',0,0
dOpenBuffer   db MAXSIZE dup(?)
hwndEdit      dq ? ;handle for edit control
EditClass     db "edit",0
end
rc-file#define ZZZ_OPEN 1
#define ZZZ_SAVE 2
#define ZZZ_EXIT 3

#define IDR_MAINMENU 30



IDR_MAINMENU MENU
{
POPUP "&File"
{       MENUITEM "&Open",ZZZ_OPEN
                MENUITEM "&Save As",ZZZ_SAVE
MENUITEM SEPARATOR
MENUITEM "&Exit",ZZZ_EXIT
}
MENUITEM "&Exit",ZZZ_EXIT
}

Mikl__

Win64 Tutorial #12b:  Memory Management, File I/O, GetProcessHeap, HeapAlloc and HeapFree
asm-fileOPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comdlg32.inc
includelib comdlg32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
ZZZ_OPEN   equ  1
ZZZ_SAVE   equ  2
ZZZ_EXIT   equ  3
MAXSIZE         equ 256
MEM_SIZE equ 65535
EditID equ 1
IDR_MAINMENU equ 30

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
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
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
mov ecx,WS_EX_CLIENTEDGE
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
mov ecx,eax
        call GetMenu
mov hMenu,rax
    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 proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

local hFile:QWORD ;handle of file
local szReadWrite:QWORD ;number of bytes actually read or write

        push rbp
mov ebp,esp
sub esp,30h+4*8

        mov edi,offset dlgOpenOfn
mov hWnd,rcx
        mov lParam,r9
        mov wParam,r8

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_CREATE
        je   wmCREATE
        cmp  edx,WM_SIZE
je   wmSIZE
        leave
        jmp DefWindowProc

wmDESTROY:xor ecx,ecx
        call ExitProcess
wmSIZE: push TRUE
        movzx rax,word ptr lParam+2
        push rax
movzx r9,word ptr lParam
xor edx,edx
mov r8,rdx
mov rcx,hwndEdit
push rbx
push rbx
push rbx
push rbx
        call MoveWindow
        jmp wmBYE
OPEN: mov  [edi+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or\
OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ecx,edi
call GetOpenFileName
test eax,eax
je wmBYE
        movzx edx,word ptr [edi+OPENFILENAME.nFileOffset]
add edx,offset dOpenBuffer
mov rcx,hWnd
call SetWindowText
push rbx
        push FILE_ATTRIBUTE_ARCHIVE
push OPEN_EXISTING
mov r9,rbx
        mov r8d,FILE_SHARE_READ or FILE_SHARE_WRITE
        mov edx,GENERIC_READ or GENERIC_WRITE
mov ecx,offset dOpenBuffer
push rbx
push rbx
push rbx
push rbx
call CreateFile
mov hFile,rax;handle to file
        xor edx,edx
mov ecx,eax
        call GetFileSize
mov FileSize,rax
        call GetProcessHeap
mov hHeap,rax
mov r8d,MEM_SIZE
mov edx,HEAP_ZERO_MEMORY
mov ecx,eax
call HeapAlloc
mov pMem,rax
push rbx
        lea r9d,szReadWrite
mov r8d,MEM_SIZE-1
mov edx,eax;pMem
mov rcx,hFile
push rbx
push rbx
push rbx
push rbx
call ReadFile
mov r9,pMem
mov r8,rbx
mov edx,WM_SETTEXT
mov rcx,hwndEdit
call SendMessage
mov r9,rbx
mov r8d,MF_GRAYED
jmp @f
SAVE: mov [edi+OPENFILENAME.Flags],OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ecx,edi;&dOpenOfn
call GetSaveFileName
test eax,eax
je wmBYE
        movzx edx,word ptr [edi+OPENFILENAME.nFileOffset]
add edx,offset dOpenBuffer
mov rcx,hWnd
call SetWindowText
push rbx
push FILE_ATTRIBUTE_ARCHIVE
push CREATE_NEW
mov r9,rbx
mov r8d,FILE_SHARE_READ or FILE_SHARE_WRITE
mov edx,GENERIC_READ or GENERIC_WRITE
mov ecx,offset dOpenBuffer
push rbx
push rbx
push rbx
push rbx
        call CreateFile  
mov hFile,rax
mov r9,pMem
mov r8,FileSize
mov edx,WM_GETTEXT
mov rcx,hwndEdit
call SendMessage
push rbx
lea r9,szReadWrite
mov r8,rax
mov rdx,pMem
mov rcx,hFile
push rbx
push rbx
push rbx
push rbx
call WriteFile
mov r8,pMem
xor edx,edx
mov rcx,hHeap
call HeapFree
        mov r9d,MF_GRAYED
mov r8,rbx;MF_ENABLED=0
@@: mov edx,edx;IDM_OPEN=0
mov rcx,hMenu
call EnableMenuItem
mov edx,ZZZ_SAVE
mov rcx,hMenu
call EnableMenuItem
mov rcx,hFile
call CloseHandle
jmp wmBYE
wmCREATE:mov [dlgOpenOfn.hwndOwner],rcx
push rbx
push IMAGE_BASE
push EditID
push rcx;hWnd
push rbx
push rbx
push rbx
push rbx
mov r9d,WS_VISIBLE or \
  WS_CHILD or ES_LEFT or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or\
  ES_AUTOHSCROLL or ES_AUTOVSCROLL
mov r8,rbx
mov edx,offset EditClass
xor ecx,ecx
;-------------------------------
push rbx
push rbx
push rbx
push rbx
        call CreateWindowEx
mov hwndEdit,rax
        jmp wmBYE
wmCOMMAND:movzx rax,word ptr wParam
        cmp r9,rbx ;cmp lParam,0
jnz wmBYE
cmp rax,ZZZ_EXIT
ja  wmBYE
jmp  [menu_handlers+eax*8]
EXIT: ;mov rcx,hWnd ;ax=MI_EXIT
        call DestroyWindow
wmBYE:  leave
        retn
menu_handlers dq wmBYE,OPEN,SAVE,EXIT
WndProc endp
;---------------------------------------
ClassName     db 'Win64 Iczelion''s lesson #12b: Memory Management, File I/O, GetProcessHeap, HeapAlloc and HeapFree',0
dlgOpenTitle  db 'Open File',0
dlgOpenOfn    OPENFILENAME <{sizeof OPENFILENAME},,IMAGE_BASE,\
FilterString,,,,dOpenBuffer,{MAXSIZE},,,,,,,,,,,,,,>
FilterString  db 'All Files (*.*)',0,'*.*',0
      db 'Text Files (*.txt)',0,'*.txt',0,0
dOpenBuffer   db MAXSIZE dup(?)
hwndEdit      dq ? ;handle for edit control
EditClass     db "edit",0
hHeap dq ?
pMem dq ?
FileSize dq ?
hMenu dq ?
end
rc-file#define ZZZ_OPEN 1
#define ZZZ_SAVE 2
#define ZZZ_EXIT 3

#define IDR_MAINMENU 30



IDR_MAINMENU MENU
{
POPUP "&File"
{       MENUITEM "&Open",ZZZ_OPEN
                MENUITEM "&Save As",ZZZ_SAVE
MENUITEM SEPARATOR
MENUITEM "&Exit",ZZZ_EXIT
}
MENUITEM "&Exit",ZZZ_EXIT
}

Mikl__

#51
Win64 Tutorial #14: Process
asm-fileOPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comdlg32.inc
includelib comdlg32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
MI_PROCESS_CREATE equ 1
MI_PROCESS_TERMINATE equ 2
MI_EXIT equ 3
IDR_MAINMENU equ 30

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
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
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 400
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
mov ecx,eax
        call GetMenu
mov hMenu,rax
    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 progStartInfo:STARTUPINFO

        push rbp
mov ebp,esp
sub esp,38h+sizeof STARTUPINFO

        mov edi,offset processInfo
mov esi,offset proExitCode
mov hWnd,rcx
        mov wParam,r8
        mov lParam,r9

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_INITMENUPOPUP
je   wmINITMENUPOPUP
        leave
        jmp DefWindowProc

wmDESTROY:xor ecx,ecx
        call ExitProcess
wmINITMENUPOPUP:mov edx,esi
mov rcx,[rdi+PROCESS_INFORMATION.hProcess]
call GetExitCodeProcess
or eax,eax
jz @f;GetExitCodeProcess_TRUE
cmp dword ptr [rsi],STILL_ACTIVE;cmp     [proExitCode],STILL_ACTIVE
jne @f;     GetExitCodeProcess_STILL_ACTIVE
mov r9,rbx;MF_ENABLED
mov r8d,MF_GRAYED
jmp @0
@@: mov r9d,MF_GRAYED
mov r8,rbx;MF_ENABLED
@0: xor edx,edx;MI_PROCESS_CREATE
mov rcx,hMenu
call EnableMenuItem
        mov r9d,MF_GRAYED
mov r8,rbx;MF_ENABLED
mov edx,MI_PROCESS_TERMINATE
mov rcx,hMenu
call EnableMenuItem
        jmp wmBYE
wmCOMMAND:movzx rax,word ptr wParam
        cmp r9,rbx ;cmp lParam,0
jnz wmBYE
cmp rax,MI_EXIT
ja  wmBYE
jmp  [menu_handlers+eax*8]

PROCESS_CREATE:cmp [rdi+PROCESS_INFORMATION.hProcess],rbx
je pi_hProcess_IS_0
mov rcx,[edi+PROCESS_INFORMATION.hProcess]
call CloseHandle
mov [rdi+PROCESS_INFORMATION.hProcess],rbx
pi_hProcess_IS_0:
lea esi,progStartInfo
mov ecx,esi
call GetStartupInfo
push rdi
push rsi
push rbx
push rbx
push NORMAL_PRIORITY_CLASS
push rbx
mov r9,rbx
mov r8,rbx
xor edx,edx
mov ecx,offset progName
push rbx
push rbx
push rbx
push rbx
call CreateProcess
mov rcx,[rdi+PROCESS_INFORMATION.hThread]
call CloseHandle
jmp wmBYE
TERMINATE:mov edx,esi;proExitCode
        mov rcx,[rdi+PROCESS_INFORMATION.hProcess]
call GetExitCodeProcess
cmp dword ptr [rsi],STILL_ACTIVE
jne proExitCode_NOT_STILL_ACTIVE;a4;
xor edx,edx
mov rcx,[rdi+PROCESS_INFORMATION.hProcess]
call TerminateProcess
proExitCode_NOT_STILL_ACTIVE:
mov rcx,[rdi+PROCESS_INFORMATION.hProcess]
call CloseHandle
mov [rdi+PROCESS_INFORMATION.hProcess],rbx;0
        jmp wmBYE

EXIT: ;mov rcx,hWnd ;ax=MI_EXIT
        call DestroyWindow
wmBYE:  leave
        retn
menu_handlers dq wmBYE,PROCESS_CREATE, TERMINATE, EXIT
WndProc endp
;---------------------------------------
ClassName       db 'Win64 Iczelion''s lesson #14: Process',0
hMenu dq ?
proExitCode dq ?;process exit code
progName db 'msgbox.exe',0
processInfo PROCESS_INFORMATION <>
end
rc-file#define MI_PROCESS_CREATE 1
#define MI_PROCESS_TERMINATE 2
#define MI_EXIT 3

#define IDR_MAINMENU 30



IDR_MAINMENU MENU
{
POPUP "&Process"
        {
         MENUITEM "&Create Process",MI_PROCESS_CREATE
         MENUITEM "&Terminate Process",MI_PROCESS_TERMINATE,GRAYED
         MENUITEM SEPARATOR
         MENUITEM "E&xit",MI_EXIT
        }
}

Mikl__

Win64 Tutorial #15: Multithreading Programming
asm-fileOPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comdlg32.inc
includelib comdlg32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
MI_THREAD_CREATE equ 0
MI_EXIT equ 1
WMU_THREAD_FINISH    equ WM_USER + 100h
IDR_MAINMENU equ 30

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
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
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 500
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
        mov hWindow,rax
mov ecx,eax
        call GetMenu
mov hMenu,rax
    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 progStartInfo:STARTUPINFO

        push rbp
mov ebp,esp
sub esp,20h

mov hWnd,rcx

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WMU_THREAD_FINISH
je   wmu_THREAD_FINISH
        leave
        jmp DefWindowProc

wmDESTROY:xor ecx,ecx
        call ExitProcess
wmu_THREAD_FINISH:mov r9,rbx;MB_OK
mov edx,offset ClassName
mov r8,rdx
xor ecx,ecx
        call MessageBox
        jmp wmBYE
wmCOMMAND:cmp    r8w,MI_THREAD_CREATE
je wmCOMMAND_MI_THREAD_CREATE
cmp r8w,MI_EXIT
jne wmBYE
wmCOMMAND_MI_EXIT:call DestroyWindow;,[hWnd]
jmp wmBYE
wmCOMMAND_MI_THREAD_CREATE:
mov eax,offset tId
push rax
push NORMAL_PRIORITY_CLASS
mov r9,rbx;NULL
        mov r8d,offset thread_procedure
xor edx,edx;0
xor ecx,ecx;NULL
push rbx
push rbx
push rbx
push rbx
call CreateThread
mov ecx,eax
call CloseHandle
wmBYE:  leave
        retn
WndProc endp
;---------------------------------------
thread_procedure proc
sub rsp,5*8
mov rcx,3FFFFFFFh
loopSTART:add eax,eax
dec rcx
jnz loopSTART
loopEND:mov r9,rbx;NULL
        mov r8,rbx;NULL
mov edx,WMU_THREAD_FINISH
mov rcx,hWindow
call SendMessage
add rsp,5*8
ret
thread_procedure endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #15: Multithreading Programming',0
hMenu   dq ?
hWindow   dq ?
tId         dd ?
end
rc-file#define MI_THREAD_CREATE 0
#define MI_EXIT 1
#define IDR_MAINMENU 30

IDR_MAINMENU MENU
{
POPUP "&Thread"
        {
         MENUITEM "&Create Thread",MI_THREAD_CREATE
         MENUITEM SEPARATOR
         MENUITEM "E&xit",MI_EXIT
        }
}

Mikl__

Win64 Tutorial #13: Memory Mapped File
asm-fileOPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comdlg32.inc
includelib comdlg32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
ZZZ_OPEN   equ  1
ZZZ_SAVE   equ  2
ZZZ_EXIT   equ  3
MAXSIZE         equ 256
MEM_SIZE equ 65535
EditID equ 1
IDR_MAINMENU equ 30

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
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
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
mov ecx,WS_EX_CLIENTEDGE
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
mov ecx,eax
        call GetMenu
mov hMenu,rax
        mov rcx,hwndEdit
call SetFocus
    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 proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

local hFile:QWORD ;handle of file
local szReadWrite:QWORD ;number of bytes actually read or write

        push rbp
mov ebp,esp
sub esp,(30h+2*8+15)and(-16)

        mov edi,offset dlgOpenOfn
mov hWnd,rcx
        mov wParam,r8
        mov lParam,r9

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_CREATE
        je   wmCREATE
        cmp  edx,WM_SIZE
je   wmSIZE
        leave
        jmp DefWindowProc

wmDESTROY:xor ecx,ecx
        call ExitProcess
wmSIZE: push TRUE
        movzx rax,word ptr lParam+2
        push rax
movzx r9,word ptr lParam
xor edx,edx
mov r8,rdx
mov rcx,hwndEdit
push rbx
push rbx
push rbx
push rbx
        call MoveWindow
        jmp wmBYE
OPEN: mov  [rdi+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or\
OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ecx,edi
call GetOpenFileName
test eax,eax
je wmBYE
push rbx ;<- align stack 16h
        push rbx
        push FILE_ATTRIBUTE_ARCHIVE
push OPEN_EXISTING
mov r9,rbx
        mov r8d,FILE_SHARE_READ or FILE_SHARE_WRITE
        mov edx,GENERIC_READ or GENERIC_WRITE
mov ecx,offset dOpenBuffer
push rbx
push rbx
push rbx
push rbx
call CreateFile
mov hFile,rax;handle to file
        xor edx,edx
mov ecx,eax
        call GetFileSize
mov FileSize,rax
        movzx edx,word ptr [rdi+OPENFILENAME.nFileOffset]
add edx,offset dOpenBuffer
mov rcx,hWnd
call SetWindowText
;созддание в памяти объекта "проекция файла"
mov [rsp+28h],rbx
        mov [rsp+20h],rbx
mov r9,rbx
mov r8d,PAGE_READWRITE
xor edx,edx
mov rcx,hFile
call CreateFileMapping
mov hMapping,rax
;отображение проекции файла на адресное пространство процесса
        mov [rsp+20h],rbx
mov r9,rbx
        mov r8,rbx
mov edx,FILE_MAP_WRITE
mov ecx,eax
call MapViewOfFile
mov pMapping,rax
mov r9,rax
mov r8,rbx
mov edx,WM_SETTEXT
mov rcx,hwndEdit
call SendMessage
mov r9,rbx
mov r8d,MF_GRAYED
jmp @f
SAVE: mov [rdi+OPENFILENAME.Flags],OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ecx,edi;&dOpenOfn
call GetSaveFileName
test eax,eax
je wmBYE
push rbx ;<- align stack 16h
        push rbx
push FILE_ATTRIBUTE_ARCHIVE
push CREATE_NEW
mov r9,rbx
mov r8d,FILE_SHARE_READ or FILE_SHARE_WRITE
mov edx,GENERIC_READ or GENERIC_WRITE
mov ecx,offset dOpenBuffer
push rbx
push rbx
push rbx
push rbx
        call CreateFile
mov hFile,rax
movzx edx,word ptr [rdi+OPENFILENAME.nFileOffset]
add edx,offset dOpenBuffer
mov rcx,hWnd
call SetWindowText
        push rbx ;<- align stack 16h
push rbx
lea r9,szReadWrite
mov r8,FileSize
mov rdx,pMapping
mov rcx,hFile
push rbx
push rbx
push rbx
push rbx
call WriteFile
mov rcx,pMapping
call UnmapViewOfFile
        mov rcx,pMapping
call CloseHandle
        mov rcx,hMapping
call CloseHandle
        mov r9d,MF_GRAYED
mov r8,rbx;MF_ENABLED=0
@@: mov edx,edx;IDM_OPEN=0
mov rcx,hMenu
call EnableMenuItem
mov edx,ZZZ_SAVE
mov rcx,hMenu
call EnableMenuItem
mov rcx,hFile
call CloseHandle
jmp wmBYE
wmCREATE:mov [rdi+OPENFILENAME.hwndOwner],rcx
push rbx
push IMAGE_BASE
push EditID
push rcx;hWnd
push rbx
push rbx
push rbx
push rbx
mov r9d,WS_VISIBLE or \
  WS_CHILD or ES_LEFT or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or\
  ES_AUTOHSCROLL or ES_AUTOVSCROLL
mov r8,rbx
mov edx,offset EditClass
xor ecx,ecx
;-------------------------------
push rbx
push rbx
push rbx
push rbx
        call CreateWindowEx
mov hwndEdit,rax
        jmp wmBYE
wmCOMMAND:movzx rax,word ptr wParam
        cmp r9,rbx ;cmp lParam,0
jnz wmBYE
cmp rax,ZZZ_EXIT
ja  wmBYE
jmp  [menu_handlers+eax*8]
EXIT: ;mov rcx,hWnd ;ax=MI_EXIT
        call DestroyWindow
wmBYE:  leave
        retn
menu_handlers dq wmBYE,OPEN,SAVE,EXIT
WndProc endp
;---------------------------------------
ClassName     db 'Win64 Iczelion''s lesson #13: Memory Mapped File',0
dlgOpenTitle  db 'Open File',0
align 8
dlgOpenOfn    OPENFILENAME <{sizeof OPENFILENAME},,IMAGE_BASE,\
FilterString,,,,dOpenBuffer,{MAXSIZE},,,,,,,,,,,,,,>
FilterString  db 'All Files (*.*)',0,'*.*',0
      db 'Text Files (*.txt)',0,'*.txt',0,0
dOpenBuffer   db MAXSIZE dup(?)
hwndEdit      dq ? ;handle for edit control
EditClass     db "edit",0
hMapping dq ? ;file mapped handle
pMapping dq ?
FileSize dq ?
hMenu dq ?
end
rc-file#define ZZZ_OPEN 1
#define ZZZ_SAVE 2
#define ZZZ_EXIT 3
#define IDR_MAINMENU 30

IDR_MAINMENU MENU
{
POPUP "&File"
{       MENUITEM "&Open",ZZZ_OPEN
                MENUITEM "&Save As",ZZZ_SAVE
MENUITEM SEPARATOR
MENUITEM "&Exit",ZZZ_EXIT
}
MENUITEM "&Exit",ZZZ_EXIT
}

Mikl__

#54
Win64 Tutorial #18: few kinds of Progress bar

include win64a.inc
include gdi32.inc
includelib gdi32.lib

IMAGE_BASE equ 400000h
IDC_PROGRESS equ 1; control IDs
IDC_STATUS equ 2
IDC_TIMER  equ 3
btn1 equ 4


.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

call InitCommonControls
xor ebx,ebx
mov eax,10029h
mov edi,offset ClassName
mov esi,IMAGE_BASE
push rax ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_APPWORKSPACE;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
mov eax,offset WndProc
push rax ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
mov ecx,esp ;addr WNDCLASSEX
    call RegisterClassEx

push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 240
push 400
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW+WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
    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 oldBrush:QWORD
local ps:PAINTSTRUCT

        push rbp
mov ebp,esp
sub esp,(20h+sizeof PAINTSTRUCT+8+15)and(-16)

mov hWnd,rcx
mov wParam,r8
mov lParam,r9

        cmp  edx,WM_DESTROY
        je   wmDESTROY
cmp  edx,WM_PAINT
je   wmPAINT
        cmp  edx,WM_CREATE
je   wmCREATE
        cmp  edx,WM_COMMAND
je   wmCOMMAND
leave
        jmp DefWindowProc
wmPAINT:lea edx,ps
call BeginPaint
mov rdx,blueBrush
mov rcx,ps.hdc
call SelectObject
mov oldBrush,rax
finit
fld angle
fsincos
fmul const_80
fistp tempX
fmul const_80
fchs
fist tempY
mov eax,tempY
add rax,130
push rax ;nYRadial2
mov eax,tempX
add rax,190
push rax ;nXRadial2
        push 80       ;nYRadial1
push 190      ;nXRadial1
push 180      ;nBottomRect
mov r9d,270   ;nRightRect
mov r8d,80    ;nTopRect
mov edx,110   ;nLeftRect
mov rcx,ps.hdc
push rbx
push rbx
push rbx
push rbx
call Pie
mov rdx,oldBrush
mov rcx,ps.hdc
call SelectObject
lea edx,ps
mov rcx,hWnd
call EndPaint
jmp wmBYE
wmDESTROY:mov rdx,TimerID
or edx,edx
jne  @f
        call KillTimer;,hWnd
@@: xor ecx,ecx
        call ExitProcess

wmCREATE:mov edi,3
@@: push rbx ;lpParam
push IMAGE_BASE ;hInstance
push IDC_PROGRESS
push hWnd ;hWndParent
push nHeight[rdi*8]
push nWidth[rdi*8]
push y[rdi*8]
push x[rdi*8]
mov r9d,dwStyle[rdi*4]
mov r8,rbx ;lpWindowName
mov edx,offset progressClass;lpClassName
mov ecx,dwExStyle[rdi*4]
        push rbx
push rbx
push rbx
push rbx
call CreateWindowEx
mov pb1H[rdi*8],rax

        mov r9,rbx
        mov r8d,2
mov edx,PBM_SETSTEP
mov ecx,eax
call SendMessage
dec edi
jns @b
;-------------------------------------------------------
push rbx;NULL
push IMAGE_BASE
push btn1
push hWnd
push 30
push 100
push 90
push 10
mov r9d,WS_CHILD + WS_VISIBLE + BS_PUSHBUTTON
mov r8d,offset btn1Txt
mov edx,offset ctlClsNameBtn
xor ecx,ecx;NULL

        push rbx
push rbx
push rbx
push rbx
call CreateWindowEx
mov btn1H,rax
;---------------------------------------------------------------
mov r9d,IDC_STATUS
mov r8,hWnd
xor edx,edx;NULL
mov ecx,WS_CHILD + WS_VISIBLE
call CreateStatusWindow
mov hwndStatus,rax
mov ecx,0FF9933h; light blue color
        call CreateSolidBrush
mov blueBrush,rax
jmp wmBYE
wmCOMMAND:cmp wParam,BN_CLICKED shl 16 or 4
jne wmBYE
wmCOMMAND_btn1:;create a timer
mov r9d,offset TimerProc
mov r8d,100
mov edx,IDC_TIMER
mov rcx,hWnd
call SetTimer
        mov TimerID,rax

xor edx,edx;FALSE
mov rcx,btn1H
call EnableWindow
wmBYE: leave
retn
WndProc endp

TimerProc proc hWnd:HWND
local buffer[16]:BYTE

push rbp
mov ebp,esp
sub esp,20h+10h
mov hWnd,rcx

mov edi,3
@@: mov r9,rbx; step up the progress in
        mov r8,rbx;0
mov edx,PBM_STEPIT
mov rcx,pb1H[rdi*8]
call SendMessage
        mov r9,rbx
mov r8,rbx
mov edx,PBM_GETPOS
mov rcx,pb1H[rdi*8]
call SendMessage
dec edi
jns @b
lea ecx,buffer
mov edx,offset format
mov r8,rax
call wsprintf
lea r9,buffer
mov r8,rbx
mov edx,SB_SETTEXT
mov rcx,hwndStatus
call SendMessage
mov r8,rbx
xor edx,edx
mov rcx,hWnd
        call InvalidateRect
finit
fld delta
fadd angle
fst angle
sub CurrentStep,2
jne wmBYE
mov rdx,TimerID
mov rcx,hWnd
call KillTimer
mov TimerID,0
mov r9d,offset Message
mov r8,rbx;0
mov edx,SB_SETTEXT
mov rcx,hwndStatus
call SendMessage
wmBYE: leave
retn
TimerProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #18: Common Controls',0
progressClass db 'msctls_progress32',0
TimerID dq ?
pb1H dq ?;hwndprogress
pb2H dq ?
pb3H dq ?
pb4H dq ?
sb1H dq ?
btn1H dq ?
hwndStatus dq ?
ctlClsNameBtn db 'BUTTON',0
btn1Txt db 'Click To Start',0
CurrentStep dq 100 ;increase step value
blueBrush dq ?
const_80 dd 80.0
tempX dd ?
tempY dd ?
angle dd 1.57952297305486826711594014548    ;90.5*pi/180
delta dd 0.12548917321839229658081336625    ;7.19*pi/180
dwStyle dd WS_CHILD + WS_VISIBLE,WS_CHILD + WS_VISIBLE + PBS_SMOOTH,\
                        WS_CHILD + WS_VISIBLE + PBS_VERTICAL,WS_CHILD + WS_VISIBLE + PBS_VERTICAL + PBS_SMOOTH
x               dq 10,10,305,350
y               dq 10,40,80,80
nHeight         dq 22,22,100,100
nWidth          dq 367,367,25,25
dwExStyle       dd WS_EX_DLGMODALFRAME,WS_EX_DLGMODALFRAME + WS_EX_STATICEDGE,0,0
format db ' Process : %i %%',0
Message db ' 100% Completed',0
end

Mikl__

Win64 Tutorial #16:  Event Example
asm-file
OPTION DOTNAME
option casemap:none
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comdlg32.inc
includelib comdlg32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none

IMAGE_BASE equ 400000h
IDM_START_THREAD equ 1
IDM_STOP_THREAD equ 2
IDM_EXIT equ 3
WM_FINISH equ WM_USER+100h
IDR_MAINMENU equ 30

.code
WinMain proc
local msg:MSG

        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx

mov edi,offset ClassName
mov esi,IMAGE_BASE
mov eax,10029h
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
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
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 400
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
push rbx
push rbx
push rbx
push rbx
    call CreateWindowEx
mov hwnd,rax
mov ecx,eax
        call GetMenu
mov hMenu,rax
    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

        push rbp
mov ebp,esp
sub esp,20h

mov hWnd,rcx
        mov wParam,r8
        mov lParam,r9

        cmp  edx,WM_DESTROY
        je   wmDESTROY
        cmp  edx,WM_COMMAND
        je   wmCOMMAND
        cmp  edx,WM_CREATE
je   wmCREATE
        cmp  edx,WM_FINISH
je   wmFINISH
        leave
        jmp DefWindowProc

wmDESTROY:xor ecx,ecx
        call ExitProcess
wmCREATE:mov r9,rbx;NULL
mov r8,rbx;FALSE
xor edx,edx;FALSE
xor ecx,ecx;NULL
call CreateEvent
mov hEventStart,rax
mov eax,offset ThreadID
push rax
push NORMAL_PRIORITY_CLASS
mov r9,rbx;NULL
mov r8d,offset ThrdProc
xor edx,edx;NULL
xor ecx,ecx;NULL
push rbx
push rbx
push rbx
push rbx
call CreateThread                             
mov hThread,rax
mov ecx,eax
call CloseHandle
        jmp wmBYE
wmCOMMAND:movzx rax,word ptr wParam
        cmp r9,rbx ;cmp lParam,0
jnz wmBYE
cmp rax,IDM_EXIT
ja  wmBYE
jmp  [menu_handlers+eax*8]
START_THREAD:mov rcx,hEventStart
call SetEvent
mov r8d,MF_GRAYED
mov edx,IDM_START_THREAD
mov rcx,hMenu
call EnableMenuItem
mov r8d,MF_ENABLED
mov edx,IDM_STOP_THREAD
mov rcx,hMenu
call EnableMenuItem
        jmp wmBYE
STOP_THREAD:mov EventStop,TRUE
mov r8d,MF_ENABLED
mov edx,IDM_START_THREAD
mov rcx,hMenu
call EnableMenuItem
mov r8d,MF_GRAYED
mov edx,IDM_STOP_THREAD
mov rcx,hMenu
call EnableMenuItem
        jmp wmBYE
EXIT: ;mov rcx,hWnd ;ax=MI_EXIT
        call DestroyWindow
        jmp wmBYE
wmFINISH:mov r9,rbx;MB_OK
mov r8d,offset ClassName
mov edx,offset SuccessString
xor ecx,ecx;NULL
        call MessageBox
wmBYE:  leave
        retn
menu_handlers dq wmBYE, START_THREAD, STOP_THREAD, EXIT
WndProc endp
;---------------------------------------
ThrdProc:
sub rsp,5*8
mov edx,INFINITE
mov rcx,hEventStart
        call WaitForSingleObject
        or  ecx,-1
@0:     cmp EventStop,FALSE
jz @f
mov r9,rbx;MB_OK
mov r8d,offset SuccessString
mov edx,offset StopString
mov rcx,hwnd
        call MessageBox
        mov EventStop,FALSE
add rsp,5*8
        jmp ThrdProc
@@:     add eax,eax
        dec rcx
        jnz @0
mov r9,rbx;NULL
mov r8,rbx;NULL
mov edx,WM_FINISH
mov rcx,hwnd
        call PostMessage
mov r8d,MF_ENABLED
mov edx,IDM_START_THREAD
mov rcx,hMenu
        call EnableMenuItem
mov r8d,MF_GRAYED
mov edx,IDM_STOP_THREAD
mov rcx,hMenu
        call EnableMenuItem
add rsp,5*8
        jmp ThrdProc
;        ret
;---------------------------------------
ClassName       db 'Win64 Iczelion''s lesson #16: Event Example',0
SuccessString db "The calculation is completed!",0
StopString db "The thread is stopped",0
EventStop BOOL FALSE
hwnd HANDLE ?
hMenu HANDLE ?
ThreadID dq ?
ExitCode dq ?
hThread dq ?
hEventStart HANDLE ?
end

rc-file
#define IDM_START_THREAD 1
#define IDM_STOP_THREAD 2
#define IDM_EXIT 3
#define IDR_MAINMENU 30

IDR_MAINMENU MENU
{
POPUP "&Thread"
        {
         MENUITEM "&Run Thread",IDM_START_THREAD
         MENUITEM "&Stop Thread",IDM_STOP_THREAD,GRAYED
         MENUITEM SEPARATOR
         MENUITEM "E&xit",IDM_EXIT
        }
}

Mikl__


jj2007

If I had started Win64, you would get questions every day :biggrin:
Fantastic job,  Mikl :t

Mikl__


Siekmanski

Thank you for the examples.  :t
Just like jj2007, haven't started programming x64 yet.
When I do, this will be a great help.
Creative coders use backward thinking techniques as a strategy.