News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Examples for Win64 Iczelion tutorial

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

Previous topic - Next topic

Mikl__

#105
Win x64 Tutorial #10: a dozen ways to create a dialogue

|DlgProc|WndProc+Class|DlgProc+WndProc
DialogBoxParam|10a|10f|10e
CreateDialogParam|10b|10c|10d
DialogBoxIndirectParam|10g|10i|10k
CreateDialogIndirectParam|10h|10j|10l

Mikl__

#106
Win x64 Tutorial #19: Tree View Demo
asm-fileinclude win64a.inc
include gdi32.inc
includelib gdi32.lib
IMAGE_BASE equ 400000h
IDB_TREE equ 4006
ZZZ_Menu equ 30
IDM_EXPANDALL equ 0
IDM_COLLAPSEALL equ 1
IDM_EXIT equ 2
ID_TREEVIEW equ 44
.code
WinMain proc
local msg:MSG
        push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
call InitCommonControls
mov eax,10027h
mov edi,offset ClassName
mov esi,IMAGE_BASE
push rax ;hIconSm
push rdi ;lpszClassName
push ZZZ_Menu ;lpszMenuName
push COLOR_APPWORKSPACE;hbrBackground
push 10005h ;hCursor
push rax        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc;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 260;rsi
push 385;rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW+WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
mov ecx,WS_EX_CLIENTEDGE
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 proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local tvis:TV_INSERTSTRUCT
local old_rdi:QWORD
local ps:PAINTSTRUCT
local tvhit:TV_HITTESTINFO

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

mov hWnd,rcx
mov lParam,r9
mov old_rdi,rdi

        cmp edx,WM_DESTROY
        je wmDESTROY
cmp edx,WM_NOTIFY
je wmNOTIFY
cmp edx,WM_LBUTTONUP
je wmLBUTTONUP
cmp edx,WM_CREATE
je wmCREATE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_SIZE
je wmSIZE
        cmp edx,WM_MOUSEMOVE
je wmMOUSEMOVE
leave
        jmp DefWindowProc
wmMOUSEMOVE:cmp DragMode,TRUE
jnz wmBYE
movzx ecx,r9w;word ptr lParam
movzx edx,word ptr lParam+2
mov tvhit.pt.x,ecx ; eax is the horizontal position of the drag image
mov tvhit.pt.y,edx ; ecx is the vertical position
call ImageList_DragMove

xor ecx,ecx;FALSE
call ImageList_DragShowNolock

lea r9,tvhit ; check if an item is hit
xor r8d,r8d;NULL
mov edx,TVM_HITTEST
mov rcx,hWndTree
call SendMessage
or eax,eax;.if eax!=NULL
jz @f
mov r9,rax
mov r8d,TVGN_DROPHILITE
mov edx,TVM_SELECTITEM
mov rcx,hWndTree
call SendMessage
@@: mov ecx,TRUE
call ImageList_DragShowNolock
jmp wmBYE
wmCOMMAND:cmp r8d,IDM_EXIT
        ja wmBYE
jmp handle[r8*8]
handle dq wmEXPANDALL,wmCOLLAPSEALL,wmDESTROY
wmEXPANDALL:mov r9,hParent0
mov r8d,TVE_EXPAND
mov edx,TVM_EXPAND
mov rcx,hWndTree
call SendMessage
mov r9,hParent1
mov r8d,TVE_EXPAND
mov edx,TVM_EXPAND
mov rcx,hWndTree
call SendMessage
        mov r9,hParent2
mov r8d,TVE_EXPAND
mov edx,TVM_EXPAND
mov rcx,hWndTree
call SendMessage
        mov r9,hChild3
mov r8d,TVE_EXPAND
mov edx,TVM_EXPAND
mov rcx,hWndTree
call SendMessage
jmp wmBYE
wmCOLLAPSEALL:mov r9,hParent0
mov r8d,TVE_COLLAPSE
mov edx,TVM_EXPAND
mov rcx,hWndTree
call SendMessage
jmp wmBYE
wmDESTROY:xor ecx,ecx
        call ExitProcess
wmSIZE: lea edx,ps
;mov rcx,hWnd     
call BeginPaint
mov r8d,GreenBrush
        mov ecx,eax
lea edx,ps.rcPaint
call FillRect
lea edx,ps 
mov rcx,hWnd
call EndPaint
jmp wmBYE
wmCREATE:push rbx;NULL
push IMAGE_BASE;hInstance
push ID_TREEVIEW
push rcx;hWnd
push 200
push 200
push rbx
push rbx
mov r9d,WS_CHILD or WS_VISIBLE or TVS_HASLINES or \
TVS_HASBUTTONS or TVS_LINESATROOT or WS_CLIPSIBLINGS
xor r8d,r8d;NULL
mov edx,offset TreeViewClass
xor ecx,ecx
sub esp,20h
call CreateWindowEx
        mov hWndTree,rax

        mov r9d,0FF00h
xor r8d,r8d;0
mov edx,TVM_SETBKCOLOR
mov rcx,hWndTree
call SendMessage
;---------- [Get the Imagelist] ----------
mov qword ptr [rsp+20h],10
mov r9d,5
mov r8d,ILC_COLOR16
mov edx,16
mov ecx,edx ;16
call ImageList_Create
mov hImageList,rax

mov edx,IDB_TREE
mov ecx,IMAGE_BASE;hInstance
call LoadBitmap
mov edi,eax;mov hBitmap,rax

xor r8d,r8d;NULL
mov edx,eax;hBitmap
mov rcx,hImageList
call ImageList_Add

mov ecx,edi;hBitmap
call DeleteObject

mov r9,hImageList
xor r8d,r8d;0
mov edx,TVM_SETIMAGELIST
mov rcx,hWndTree
call SendMessage
;---------- [Fill the tree] ----------
        mov r9d,TVI_ROOT
xor r8d,r8d;0
mov edx,TVM_DELETEITEM
mov rcx,hWndTree
call SendMessage

mov tvis.hParent,rbx;NULL
mov tvis.hInsertAfter,TVI_ROOT
mov tvis.item.imask,TVIF_TEXT or TVIF_IMAGE or TVIF_SELECTEDIMAGE
mov eax,offset Parent0
mov tvis.item.pszText,rax
mov tvis.item.iImage,ebx;0
mov tvis.item.iSelectedImage,1

        lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hParent0,rax

        mov tvis.hParent,rax
        mov eax,offset Parent1
mov tvis.item.pszText,rax

        lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hParent1,rax


mov tvis.hParent,rax
mov tvis.hInsertAfter,TVI_LAST

mov eax,offset Child1
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild1,rax

mov eax,offset Child2
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild2,rax

mov eax,offset Child3
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild3,rax

        mov tvis.hParent,rax
mov eax,offset Child4
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild4,rax

mov eax,offset Child5
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild5,rax

        mov rax,hParent1
        mov tvis.hParent,rax

mov eax,offset Child6
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild6,rax

        mov rax,hParent0
        mov tvis.hParent,rax
        mov tvis.hInsertAfter,TVI_LAST
mov tvis.item.imask,TVIF_TEXT or TVIF_IMAGE or TVIF_SELECTEDIMAGE
mov eax,offset Parent2
mov tvis.item.pszText,rax

        lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hParent2,rax
mov tvis.hParent,rax

        mov eax,offset Child7
mov tvis.item.pszText,rax

lea r9,tvis
xor r8d,r8d;0
mov edx,TVM_INSERTITEM
mov rcx,hWndTree
call SendMessage
        mov hChild7,rax

        mov ecx,000FF00h;green=00FF00h
call CreateSolidBrush
mov GreenBrush,eax
jmp wmBYE
wmLBUTTONUP:cmp DragMode,TRUE
jnz wmBYE
mov rcx,hWndTree
        call ImageList_DragLeave

call ImageList_EndDrag

mov rcx,hDragImageList
call ImageList_Destroy

xor r9d,r9d; Get the currently hilited item
mov r8d,TVGN_DROPHILITE
mov edx,TVM_GETNEXTITEM
mov rcx,hWndTree
call SendMessage

mov r9,rax
mov r8d,TVGN_CARET
mov edx,TVM_SELECTITEM
mov rcx,hWndTree
call SendMessage

xor r9d,r9d
mov r8d,TVGN_DROPHILITE
mov edx,TVM_SELECTITEM
mov rcx,hWndTree
call SendMessage

call ReleaseCapture
mov DragMode,FALSE
jmp wmBYE
wmNOTIFY:cmp r8d,ID_TREEVIEW ; Treeview?
        jne wmBYE
        cmp [r9+NM_TREEVIEW.hdr._code],TVN_ITEMEXPANDING
        jne @f
        cmp [r9+NM_TREEVIEW.action],TVE_COLLAPSE
        jne wmBYE
        xor r9d,r9d
mov r8d,TVGN_CARET
mov edx,TVM_SELECTITEM
mov rcx,hWndTree
call SendMessage
jmp wmBYE
@@: cmp [r9+NM_TREEVIEW.hdr._code],TVN_BEGINDRAG
jnz wmBYE
        mov rdi,r9;lParam
mov r9,[rdi+NM_TREEVIEW.itemNew.hItem]
xor r8d,r8d
mov edx,TVM_CREATEDRAGIMAGE
mov rcx,hWndTree
call SendMessage
mov hDragImageList,rax
xor r9d,r9d
        xor r8d,r8d
xor edx,edx
mov rcx,hDragImageList
call ImageList_BeginDrag
mov r8d,[rdi+NM_TREEVIEW.ptDrag.y]
mov edx,[rdi+NM_TREEVIEW.ptDrag.x]
mov rcx,hWndTree
call ImageList_DragEnter
mov rcx,hWnd
call SetCapture
mov DragMode,TRUE
wmBYE: mov rdi,old_rdi
leave
xor eax,eax
retn
WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #19: Tree View Demo',0
TreeViewClass db "SysTreeView32",0
Parent0 db 'Zero',0
Parent1 db 'One',0
Parent2 db 'Two',0
Child1 db 'Eight',0
Child2 db 'Four',0
Child3 db 'Five',0
Child4 db 'Six',0
Child5 db 'Seven',0
Child6 db 'Three',0
Child7 db 'Nine',0
DragMode db FALSE
GreenBrush dd ?
hWndTree dq ?
hParent0 dq ?
hParent1 dq ?
hParent2 dq ?
hChild1 dq ?
hChild2 dq ?
hChild3 dq ?
hChild4 dq ?
hChild5 dq ?
hChild6 dq ?
hChild7 dq ?
hImageList dq ?
hDragImageList dq ?
end

rc-file#define IDB_TREE 4006
#define IDM_EXPANDALL 0
#define IDM_COLLAPSEALL 1
#define IDM_EXIT 2
#define ZZZ_Menu 30
IDB_TREE BITMAP "Images\\list.bmp"
ZZZ_Menu MENU
{
POPUP "Treeview"
{       MENUITEM "Expand all",IDM_EXPANDALL
MENUITEM "Collapse all",IDM_COLLAPSEALL
                MENUITEM SEPARATOR
MENUITEM "&Exit",IDM_EXIT
}
}

Mikl__

#107
164129 views of topic. It is well. The translation from x32 to x64 was finished. What would you like to supplement the tutorial? Drivers? Graphics? Working with the console? What else? Sorry for my bad english...

jj2007

What else? It's holiday time, take a rest. You've done a fantastic job :t

Maybe you could put all your code into one fat archive. The forum has always been very stable, so I am not worried that this thread might disappear for technical reasons, but still, everything in one archive could be handy.

Don't worry about your English, it's definitely good enough!

TouEnMasm


Something not very good need:
/LARGEADDRESSAWARE:NO     


Fa is a musical note to play with CL

rrr314159

I use /LARGEADDRESSAWARE:NO to quickly get 32-bit code running as 64-bit, but ultimately you want to get rid of it to get full benefit of 64-bit. So one sensible suggestion for Mikl__, now that you've done the first level of conversion (without large addresses) go thru it again and put in large address capability. That's how I do 32-bit conversion, in two stages. It's easier (IMHO) than immediately going all the way to large addresses, which requires converting more dwords to qwords, more "e"'s to "r"'s (like, eax to rax) etc
I am NaN ;)

Mikl__

#111
Hi, ToutEnMasm!
in phrase
QuoteSomething not very good need: /LARGEADDRESSAWARE:NO
the keyword is Something
Win x64 Tutorial #3a:Window with unrectangular shape
asm-fileinclude win64a.inc
include gdi32.inc
includelib gdi32.lib
IMAGE_BASE equ 400000h
bmpWidth equ 200
bmpHeight equ 200
.code
WinMain proc
local msg:MSG
local j:DWORD
local i:DWORD
local bpp:DWORD
local hWnd:QWORD
local ResRgn:DWORD
local maskBitmap:QWORD
local bi:BITMAP

enter (30h+sizeof MSG+4*4+8*2+sizeof BITMAP+15)and(-16),0
xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
        mov qword ptr [rsp+28h],LR_LOADFROMFILE
        mov [rsp+20h],rbx
xor r9d,r9d
xor r8d,r8d
mov edx,edi
mov ecx,esi
call LoadImage
mov maskBitmap,rax
mov ecx,eax
call CreatePatternBrush
        mov ecx,10027h
push rcx ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push rax ;hbrBackground
push 10005h ;hCursor
push rcx        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc      ;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 rsi
push rsi
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
    call CreateWindowEx
mov hWnd,rax
xor r8d,r8d
mov edx,GWL_STYLE
mov ecx,eax
call SetWindowLongPtr
lea edi,bi
mov r8d,edi
mov edx,sizeof BITMAP
mov rcx,maskBitmap
call GetObject
movzx edi,[rdi+BITMAP.mBitsPixel]
shr edi,3
mov bpp,edi;bpp = bi.bmBitsPixel / 8
imul edi,bmpHeight*bmpWidth
call GetProcessHeap
mov r8d,edi
mov edx,HEAP_NO_SERIALIZE
mov ecx,eax
        call HeapAlloc
mov esi,eax
mov r8d,eax
mov edx,edi
mov rcx,maskBitmap
call GetBitmapBits
xor r9d,r9d
xor r8d,r8d
xor edx,edx
xor ecx,ecx
call CreateRectRgn
        mov ResRgn,eax
;--------------------------------------------------
comment $
for (i = 0; i < bi.bmHeight; i++)
{
startx=-1;
for (j = 0; j < bi.bmWidth; j++)
{
pixel = *(DWORD*)(pBits + (i * bi.bmWidth +
j) * bpp) << (32 - bi.bmBitsPixel);
if (pixel != TransPixel)
{
if (startx<0)
{
startx = j;
} else if (j == (bi.bmWidth - 1))
{
Rgn = CreateRectRgn( startx, i, j, i + 1 );
CombineRgn( ResRgn, ResRgn, Rgn, RGN_OR);
startx=-1;
}
} else if (startx>=0)
{
Rgn = CreateRectRgn(startx, i, j, i + 1);
CombineRgn(ResRgn, ResRgn, Rgn, RGN_OR);
startx=-1;
}
}
}
$
;-------------------------------------------------
mov edi,[rsi] ;edi=TransPixel
        xor ecx,ecx ;ecx = 0
mov i,ebx               ;i=0
;--------------------------------------------------
.1: mov j,ebx ;j=0
.2: mov eax,j
cmp [rsi],edi ;pixel == TransPixel ?
        jz @f
        or ecx,ecx ;eax != 0 ?
        jnz .3
        mov ecx,eax ;ecx=j
        jmp .3 ;if(pixel != TransPixel && ecx == 0)  ecx=j;
@@:     jrcxz .3 ;ecx == 0 ?
mov edx,i ;if(pixel == TransPixel && ecx > 0)
        mov r9d,edx
inc r9d ;r9d=i+1
        mov r8d,eax ;r8=j
inc ecx         
        call CreateRectRgn ;hRgn=CreateRectRgn(ecx,i,j-1,i+1);
mov r9d,RGN_OR
mov r8d,eax
mov edx,ResRgn
mov ecx,edx
        call CombineRgn
xor ecx,ecx ;ecx = 0
.3: add esi,bpp
inc j
    cmp byte ptr j,bmpWidth
        jb .2
        inc i
cmp byte ptr i,bmpHeight
        jb .1
;-------------------------------------------------------------
mov r8d,1
mov edx,ResRgn
mov rcx,hWnd
        call SetWindowRgn
        mov edx,SW_SHOWNORMAL
mov rcx,hWnd
call ShowWindow
@@:     lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
        call GetMessage
lea ecx,msg
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hwnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD

enter 20h,0
cmp edx,WM_DESTROY
je wmDESTROY
        cmp edx,WM_LBUTTONDOWN
je wmLBUTTONDOWN
        cmp edx,WM_RBUTTONDOWN
je wmDESTROY
leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmLBUTTONDOWN:mov r8d,2
mov edx,WM_NCLBUTTONDOWN
call PostMessage
leave
retn
WndProc endp
;---------------------------------------
ClassName db 'mask.bmp',0
end

Gunther

Hi Michail,

looks nice, but Christmas is a bit later.  :lol: :lol: :lol: How can one close the program?

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

Mikl__

Hi, Gunther!
Quote from: GuntherHow can one close the program?
Alt+F4 or Right Click on Santa

Gunther

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

Mikl__

Gunther,
if hold down the left mouse button on Santa, then the window can be moved on the screen

Mikl__

#116
That's all Folks!
(End of the first part of the Win64 tutorial)

Mikl__

#117
Win x64 Tutorial #38: Simple console application
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /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
asm-fileinclude win64a.inc
BLACK equ 0
BLUE equ 1
GREEN equ 2
CYAN equ 3
RED equ 4
PURPLE equ 5
YELLOW equ 6
SYSTEM equ 7
GREY equ 8
BRIGHTBLUE equ 9
BRIGHTGREEN equ 10
BRIGHTCYAN equ 11
BRIGHTRED equ 12
BRIGHTPURPLE equ 13
BRIGHTYELLOW equ 14
WHITE equ 15
MAXSCREENX = 80
MAXSCREENY = 25
buffersize = 200
.code
WinMain proc
local LENS:qword
local hOut:qword
local BUFF[buffersize]:byte
local ConsoleWindow:SMALL_RECT
        push rbp
mov ebp,esp
sub esp,(28h+2*8+buffersize+sizeof SMALL_RECT+15)and(-16)

        call FreeConsole;release the existing console
        call AllocConsole;form the console
        mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle;receive the handle for a conclusion
        mov hOut,rax
        mov rcx,rax ; hConsoleOutput
call GetLargestConsoleWindowSize
; rax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize;establish the new size of a window of the console
mov ecx,offset STR2
call SetConsoleTitle;definition of a title bar
        mov edx,0A0000h;Y=10(0Ah)X=0
        mov rcx,hOut
        call SetConsoleCursorPosition;establish a cursor position
        mov edx,BRIGHTGREEN;color of the output text
        mov rcx,hOut
        call SetConsoleTextAttribute;set color attributes of the output text
        mov qword ptr [rsp+20h],0
lea r9d,BUFF
        mov r8d,sizeof STR1
mov edx,offset STR1
mov rcx,hOut
        call WriteConsole;display a line of symbols
        mov edx,STD_INPUT_HANDLE
        mov ecx,3000;small delay
call Sleep
        call FreeConsole;close the console
xor ecx,ecx
        call ExitProcess
WinMain endp
STR1 db 'Win64 Assembly is Great!'
STR2 db 'Iczelion''s tutorial #38',0
end

Mikl__

#118
Win x64 Tutorial #38a: Input and output of line of symbols in console application
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /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
asm-fileinclude win64a.inc
BLACK equ 0
BLUE equ 1
GREEN equ 2
CYAN equ 3
RED equ 4
PURPLE equ 5
YELLOW equ 6
SYSTEM equ 7
GREY equ 8
BRIGHTBLUE equ 9
BRIGHTGREEN equ 10
BRIGHTCYAN equ 11
BRIGHTRED equ 12
BRIGHTPURPLE equ 13
BRIGHTYELLOW equ 14
WHITE equ 15
MAXSCREENX = 80
MAXSCREENY = 25
buffersize = 200

.code
WinMain proc
local LENS:qword
local hOut:qword
local BUFF[buffersize]:byte
local ConsoleWindow:SMALL_RECT

        push rbp
mov ebp,esp
sub esp,(28h+2*8+buffersize+sizeof SMALL_RECT+15)and(-16)

call FreeConsole;release the existing console
        call AllocConsole;create the console
        mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle;receive the handle for a conclusion
        mov hOut,rax
        mov rcx,rax ; hConsoleOutput
call GetLargestConsoleWindowSize
; rax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize;establish the new size of a window of the console
mov ecx,offset STR2
call SetConsoleTitle ;definition of a title bar
        mov edx,0A0000h;Y=10(0Ah)X=0
        mov rcx,hOut
        call SetConsoleCursorPosition;establish a cursor position
        mov edx,BRIGHTGREEN;color of the output text
        mov rcx,hOut
        call SetConsoleTextAttribute ;set color attributes of the output text
        mov qword ptr [rsp+20h],0
lea r9d,BUFF
        mov r8d,sizeof STR1
mov edx,offset STR1
mov rcx,hOut
        call WriteConsole ;display a line of symbols
        mov ecx,STD_INPUT_HANDLE
        call GetStdHandle ;receive HANDLE for input
        mov qword ptr [rsp+20h],0
lea r9d,LENS
        mov r8d,buffersize
lea edx,BUFF
        mov rcx,rax
        call ReadConsole ;wait for input of a line of symbols
        mov edx,BRIGHTCYAN;color of the input text
        mov rcx,hOut
        call SetConsoleTextAttribute ;set color attributes of the output text
        mov qword ptr [rsp+20h],0
lea r9d,LENS
        mov r8d,[r9] ;length of the removed line
lea edx,BUFF
        mov rcx,hOut
        call WriteConsole
        mov ecx,3000 ;small delay
call Sleep
        call FreeConsole ;close the console
mov ecx,ecx
        call ExitProcess
WinMain endp
STR1 db 'Enter line of any symbols and press "Enter":',13,10
STR2 db 'Iczelion''s tutorial #38a',0
end

Mikl__

Win x64 Tutorial #38b: Installation of color of symbols and background of the text of the  console application
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /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
asm-fileinclude win64a.inc
includelib msvcrt.lib
MAXSCREENX = 80
MAXSCREENY = 25
LEFT    = 8
TOP    = 4
buffersize   = 100
.code
WinMain proc
local BUFF[buffersize]:byte   
local hIn:qword
local hOut:qword
local result:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD
local color:dword
local coord:COORD

        push rbp
mov ebp,esp
sub esp,(30h+3*8+4+buffersize+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

call FreeConsole
        call AllocConsole
        mov rcx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov rcx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov ecx,eax;hOut ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ;hConsoleOutput
call SetConsoleScreenBufferSize ;establish the new size of a window of the console
mov ecx,offset Str1
call SetConsoleTitle
;прячем курсор----------------------------------------
lea edx,cci         ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci         ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
        mov qword ptr [rsp+20h],0
lea r9d,result;&result
        mov r8d,sizeof Str2
mov edx,offset Str2     
mov rcx,hOut
        call WriteConsole
        mov coord.x,LEFT

        mov color,0
@0:     mov coord.y,TOP
@@:     mov edx,coord
        mov rcx,hOut
        call SetConsoleCursorPosition   
        ; To establish color and a background of the text of the console
        ; 4-7 bits - background color
        ; 0-3 bits - text color
        ; other bits aren't used
mov edx,color
mov rcx,hOut
        call SetConsoleTextAttribute
mov r8d,color
mov edx,offset fmt
lea ecx,BUFF
call wsprintf
mov qword ptr [rsp+20h],0
        lea r9d,result
        mov r8d,eax
lea edx,BUFF
        mov rcx,hOut
        call WriteConsole
        inc coord.y
inc color
cmp coord.y,TOP+16
jb @b
add coord.x,4
cmp coord.x,16*4+LEFT
jb @0
@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
        call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
Str1 db 'Installation of color of symbols and background of the text of the console',0
Str2 db 'For exit press ESC or CTRL+C'
fmt  db '%.3d',0
end