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

jj2007

Hi Mikl,

You are doing a great job - sometimes I regret that I don't find the time to test coding in 64 bits... :t

Mikl__


Gunther

Hi Micha,

excellent work, молодец. :t

Gunther

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

Mikl__

#78
Win x64 Tutorial  #33: IczEdit version 1.0
rc-file#include "resource.h"
#define IDR_MAINMENU                    101
#define IDD_OPTIONDLG                   101
#define IDC_BACKCOLORBOX                1000
#define IDC_TEXTCOLORBOX                1001
#define IDC_OK 1002
#define IDC_CANCEL 1003
#define IDM_OPEN                        40001
#define IDM_SAVE                        40002
#define IDM_CLOSE                       40003
#define IDM_SAVEAS                      40004
#define IDM_EXIT                        40005
#define IDM_COPY                        40006
#define IDM_CUT                         40007
#define IDM_PASTE                       40008
#define IDM_DELETE                      40009
#define IDM_SELECTALL                   40010
#define IDM_OPTION                      40011
#define IDM_UNDO                        40012
#define IDM_REDO                        40013

IDR_MAINMENU MENU DISCARDABLE
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&Open",                       IDM_OPEN
        MENUITEM "&Close",                      IDM_CLOSE
        MENUITEM "&Save",                       IDM_SAVE
        MENUITEM "Save &As",                    IDM_SAVEAS
        MENUITEM SEPARATOR
        MENUITEM "E&xit",                       IDM_EXIT
    END
    POPUP "&Edit"
    BEGIN
        MENUITEM "&Undo",                       IDM_UNDO
        MENUITEM "&Redo",                       IDM_REDO
        MENUITEM "&Copy",                       IDM_COPY
        MENUITEM "C&ut",                        IDM_CUT
        MENUITEM "&Paste",                      IDM_PASTE
        MENUITEM SEPARATOR
        MENUITEM "&Delete",                     IDM_DELETE
        MENUITEM SEPARATOR
        MENUITEM "Select &All",                 IDM_SELECTALL
    END
    MENUITEM "Options",                     IDM_OPTION
END


IDD_OPTIONDLG DIALOG DISCARDABLE  0, 0, 183, 54
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Options"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDC_OK,137,7,39,14
    PUSHBUTTON      "Cancel",IDC_CANCEL,137,25,39,14
    GROUPBOX        "",IDC_STATIC,5,0,124,49
    LTEXT           "Background Color:",IDC_STATIC,20,14,60,8
    LTEXT           "",IDC_BACKCOLORBOX,85,11,28,14,SS_NOTIFY | WS_BORDER
    LTEXT           "Text Color:",IDC_STATIC,20,33,35,8
    LTEXT           "",IDC_TEXTCOLORBOX,85,29,28,14,SS_NOTIFY | WS_BORDER
END
asm-fileOPTION DOTNAME
include temphls.inc
include win64.inc
include user32.inc
include comdlg32.inc
include gdi32.inc
include kernel32.inc
includelib gdi32.lib
includelib comdlg32.lib
includelib user32.lib
includelib kernel32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
IDR_MAINMENU equ 101
IDM_OPEN equ 40001
IDM_SAVE equ 40002
IDM_CLOSE equ 40003
IDM_SAVEAS equ 40004
IDM_EXIT equ 40005
IDM_COPY equ 40006
IDM_CUT equ 40007
IDM_PASTE equ 40008
IDM_DELETE equ 40009
IDM_SELECTALL equ 40010
IDM_OPTION equ 40011
IDM_UNDO equ 40012
IDM_REDO equ 40013
IDD_OPTIONDLG equ 101
IDC_BACKCOLORBOX equ 1000
IDC_TEXTCOLORBOX equ 1001
IDC_OK equ 1002
IDC_CANCEL equ 1003
RichEditID equ 300

.code
WinMain proc
LOCAL msg:MSG
local hwnd:QWORD

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

mov ecx,offset RichEditDLL
call LoadLibrary
or eax,eax
jnz @f
mov r9d,MB_OK or MB_ICONERROR
mov r8d,offset ClassName
mov edx,offset NoRichEdit
xor ecx,ecx
call MessageBox
        xor ecx,ecx
call ExitProcess

@@: mov hRichEdit,rax
xor ebx,ebx
mov esi,IMAGE_BASE
mov eax,10029h
mov edi,offset ClassName
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW+1;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
sub esp,20h
    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 hwnd,rax

    mov edx,offset rect
mov ecx,eax
call GetClientRect

        push rbx;0
push IMAGE_BASE
push RichEditID
push hwnd
mov eax,rect.bottom
push rax
mov eax,rect.right
push rax
push rbx
push rbx
        mov r9d,WS_CHILD or WS_VISIBLE or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or ES_NOHIDESEL
mov r8,rbx;0
mov edx,offset RichEditClass
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
mov hwndRichEdit,rax

mov r9,rbx
or r8,-1
mov edx,EM_LIMITTEXT
mov rcx,hwndRichEdit
call SendMessage
call SetColor
mov r9,rbx
mov r8,rbx;FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov r9,rbx
mov r8,rbx
mov edx,EM_EMPTYUNDOBUFFER
mov rcx,hwndRichEdit
call SendMessage

    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
;-----------------------------------------------------------
StreamInProc proc hFile:QWORD,pBuffer:QWORD, NumBytes:QWORD, pBytesRead:QWORD
push rbp
mov ebp,esp
sub esp,30h
mov qword ptr [esp+20h],0
call ReadFile;,hFile,pBuffer,NumBytes,pBytesRead,0
xor eax,1
leave
retn
StreamInProc endp
;---------------------------------------------------------
StreamOutProc proc hFile:QWORD,pBuffer:QWORD, NumBytes:QWORD, pBytesWritten:QWORD
push rbp
mov ebp,esp
sub esp,30h
mov qword ptr [esp+20h],0
call WriteFile;,hFile,pBuffer,NumBytes,pBytesWritten,0
xor eax,1
leave
retn
StreamOutProc endp
;----------------------------------------------------------
CheckModifyState proc hWnd:QWORD
push rbp
mov ebp,esp
sub esp,20h

mov hWnd,rcx

xor r9d,r9d
mov r8d,r9d
mov edx,EM_GETMODIFY
mov rcx,hwndRichEdit
call SendMessage
or eax,eax;.if eax!=0
jz wmBYE
mov r9d,MB_YESNOCANCEL
mov r8d,offset ClassName
mov edx,offset WannaSave
mov rcx,hWnd
call MessageBox
cmp eax,IDYES;.if eax==IDYES
jnz @f
xor r9d,r9d
mov r8d,IDM_SAVE
mov edx,WM_COMMAND
mov rcx,hWnd
call SendMessage
jmp wmBYE
@@: cmp eax,IDCANCEL;.elseif eax==IDCANCEL
jnz wmBYE
xor eax,eax;mov eax,FALSE
jmp @f
wmBYE: mov eax,TRUE
@@: leave
ret
CheckModifyState endp
;--------------------------------------------------------------
SetColor proc
LOCAL cfm1:CHARFORMAT

push rbp
mov ebp,esp
sub esp,(20h+sizeof CHARFORMAT+15)and(-16)
;Установка цвета фона richedit контрола
mov r9d,BackgroundColor
xor r8,r8;rbx
mov edx,EM_SETBKGNDCOLOR
mov rcx,hwndRichEdit
call SendMessage
;заполняем члены структуры CHARFORMAT, чтобы установить цвет текста
mov edx,sizeof CHARFORMAT
lea ecx,cfm1
call RtlZeroMemory
lea r9,cfm1
mov [r9+CHARFORMAT.cbSize],sizeof CHARFORMAT
mov [r9+CHARFORMAT.dwMask],CFM_COLOR
mov eax,TextColor
mov [r9+CHARFORMAT.crTextColor],eax
mov r8d,SCF_ALL
mov edx,EM_SETCHARFORMAT
mov rcx,hwndRichEdit
call SendMessage
leave
retn
SetColor endp
OptionProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL clr:CHOOSECOLOR
local temp:QWORD

push rbp
mov ebp,esp
sub esp,(28h+sizeof CHOOSECOLOR+15)and(-16)

mov hWnd,rcx
;mov uMsg,rdx
mov wParam,r8
mov lParam,r9

cmp edx,WM_INITDIALOG
je wmBYE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CTLCOLORSTATIC
je wmCTLCOLORSTATIC
cmp edx,WM_CLOSE
je wmCLOSE
wmDEFAULT:xor eax,eax;mov eax,FALSE
leave
ret

wmCOMMAND:mov eax,r8d;wParam
shr eax,16
or eax,eax;.if ax==BN_CLICKED
jnz wmBYE
mov eax,r8d;wParam
        sub eax,IDC_BACKCOLORBOX
cmp eax,IDC_CANCEL-IDC_BACKCOLORBOX
ja wmBYE
jmp handle[rax*8]
CANCEL: xor r9d,r9d;0
mov r8d,r9d
mov edx,WM_CLOSE
;mov rcx,hWnd
call SendMessage
jmp wmBYE
BACKCOLORBOX:
mov edx,sizeof clr
lea ecx,clr
call RtlZeroMemory
mov eax,BackgroundColor
lea ecx,clr
mov [rcx+CHOOSECOLOR.rgbResult],eax
mov [rcx+CHOOSECOLOR.lStructSize],sizeof clr
mov rax,hWnd
mov [rcx+CHOOSECOLOR.hwndOwner],rax
mov [rcx+CHOOSECOLOR.hInstance],IMAGE_BASE
mov eax,offset CustomColors
mov [rcx+CHOOSECOLOR.lpCustColors],rax
mov [rcx+CHOOSECOLOR.Flags],CC_ANYCOLOR or CC_RGBINIT
call ChooseColor
or eax,eax;.if eax!=0
jz wmBYE
mov eax,clr.rgbResult
mov BackgroundColor,eax
mov edx,IDC_BACKCOLORBOX
jmp @f
TEXTCOLORBOX:
mov edx,sizeof clr
lea ecx,clr
call RtlZeroMemory
mov eax,TextColor
        lea ecx,clr
mov [rcx+CHOOSECOLOR.rgbResult],eax
mov [rcx+CHOOSECOLOR.lStructSize],sizeof clr
mov rax,hWnd
mov [rcx+CHOOSECOLOR.hwndOwner],rax
mov [rcx+CHOOSECOLOR.hInstance],IMAGE_BASE
mov eax,offset CustomColors
mov [rcx+CHOOSECOLOR.lpCustColors],rax
mov [rcx+CHOOSECOLOR.Flags],CC_ANYCOLOR or CC_RGBINIT
call ChooseColor
or eax,eax;.if eax!=0
jz wmBYE
mov eax,clr.rgbResult
mov TextColor,eax
mov edx,IDC_TEXTCOLORBOX
@@: mov rcx,hWnd
call GetDlgItem
mov r8d,TRUE
xor edx,edx
mov ecx,eax
call InvalidateRect
jmp wmBYE
OK: xor r9d,r9d
mov r8d,r9d
mov edx,EM_GETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov temp,rax
call SetColor
mov r8,temp
xor r9d,r9d
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
xor edx,edx
mov rcx,hWnd
call EndDialog
jmp wmBYE
wmCTLCOLORSTATIC:mov edx,IDC_BACKCOLORBOX
call GetDlgItem
cmp rax,lParam;.if eax==lParam
jnz @f
mov ecx,BackgroundColor
jmp @0
@@: mov edx,IDC_TEXTCOLORBOX
mov rcx,hWnd
call GetDlgItem
cmp rax,lParam;.if eax==lParam
jnz wmDEFAULT
mov ecx,TextColor
@0: call CreateSolidBrush
jmp @f
wmCLOSE:xor edx,edx
call EndDialog
wmBYE: mov eax,TRUE
@@: leave
retn
handle dq BACKCOLORBOX,TEXTCOLORBOX,OK,CANCEL
OptionProc endp
WndProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL chrg:CHARRANGE
LOCAL ofn:OPENFILENAME
LOCAL buffer[256]:BYTE
LOCAL editstream:EDITSTREAM
LOCAL hFile:QWORD

push rbp
mov ebp,esp
sub esp,(40h+sizeof EDITSTREAM+sizeof OPENFILENAME+\
sizeof CHARRANGE+8+256+15)and(-16)
mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
mov lParam,r9

cmp edx,WM_INITMENUPOPUP
je wmINITMENUPOPUP
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_SIZE
je wmSIZE
cmp edx,WM_DESTROY
je wmDESTROY
wmDEFAULT:leave
jmp DefWindowProc

wmDESTROY:mov rcx,hRichEdit
call FreeLibrary
xor ecx,ecx
call ExitProcess
wmINITMENUPOPUP:
mov eax,r9d;lParam
or ax,ax;.if ax==0 ; file menu
jnz @f
cmp FileOpened,TRUE;.if FileOpened==TRUE ; a file is already opened
setne bl;в ebx MF_ENABLED=0 или MF_GRAYED=1
mov r8d,ebx;MF_ENABLED
mov edx,IDM_CLOSE
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_SAVE
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_SAVEAS
mov rcx,wParam
call EnableMenuItem
xor ebx,1
mov r8d,ebx;MF_GRAYED
mov edx,IDM_OPEN
mov rcx,wParam
call EnableMenuItem
xor ebx,ebx
jmp wmBYE
@@: cmp ax,1;.elseif ax==1 ; edit menu
jnz wmBYE
xor r9d,r9d
mov r8d,CF_TEXT
mov edx,EM_CANPASTE
mov rcx,hwndRichEdit
call SendMessage
or eax,eax; .if eax==0 ; no text in the clipboard
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_PASTE
mov rcx,wParam
call EnableMenuItem
xor r9d,r9d
mov r8d,r9d
mov edx,EM_CANUNDO
mov rcx,hwndRichEdit
call SendMessage
or eax,eax; .if eax==0
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_UNDO
mov rcx,wParam
call EnableMenuItem
xor r9d,r9d
mov r8d,r9d
mov edx,EM_CANREDO
mov rcx,hwndRichEdit
call SendMessage
or eax,eax; .if eax==0
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_REDO
mov rcx,wParam
call EnableMenuItem
lea r9,chrg
xor r8d,r8d
mov edx,EM_EXGETSEL
mov rcx,hwndRichEdit
call SendMessage
mov eax,chrg.cpMin
cmp eax,chrg.cpMax
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_COPY
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_CUT
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_DELETE
mov rcx,wParam
call EnableMenuItem
xor ebx,ebx
jmp wmBYE
wmCOMMAND:or r9,r9;.if lParam==0 ; menu commands
jnz wmBYE
movzx eax,r8w;mov eax,wParam
sub eax,IDM_OPEN;.if ax==IDM_OPEN
cmp eax,IDM_REDO-IDM_OPEN
ja wmBYE
jmp handle1[rax*8]
OPEN: mov edx,sizeof ofn
lea ecx,ofn
call RtlZeroMemory
lea ecx,ofn
mov [rcx+OPENFILENAME.lStructSize],sizeof ofn
mov rax,hWnd
mov [rcx+OPENFILENAME.hwndOwner],rax
mov [rcx+OPENFILENAME.hInstance],IMAGE_BASE
mov eax,offset ASMFilterString
mov [rcx+OPENFILENAME.lpstrFilter],rax
mov eax,offset FileName
mov [rcx+OPENFILENAME.lpstrFile],rax
mov byte ptr [FileName],0
mov [rcx+OPENFILENAME.nMaxFile],sizeof FileName
mov [rcx+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
call GetOpenFileName
or eax,eax; .if eax!=0
jz wmBYE
mov qword ptr [rsp+30h],0
mov qword ptr [rsp+28h],FILE_ATTRIBUTE_NORMAL
mov qword ptr [rsp+20h],OPEN_EXISTING
mov r9d,NULL
mov r8d,FILE_SHARE_READ
mov edx,GENERIC_READ
mov ecx,offset FileName
call CreateFile
inc eax;.if eax!=INVALID_HANDLE_VALUE
jz @f
dec eax
mov hFile,rax
lea r9,editstream
mov [r9+EDITSTREAM.dwCookie],rax
mov eax,offset StreamInProc
mov [r9+EDITSTREAM.pfnCallback],rax
mov r8d,SF_TEXT
mov edx,EM_STREAMIN
mov rcx,hwndRichEdit
call SendMessage
xor r9d,r9d
mov r8d,FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov rcx,hFile
call CloseHandle
mov FileOpened,TRUE
jmp wmBYE
@@: mov r9d,MB_OK or MB_ICONERROR
        mov r8d,offset ClassName
        mov edx,offset OpenFileFail
mov rcx,hWnd
        call MessageBox
jmp wmBYE

CLOSE1: mov rcx,hWnd
call CheckModifyState
or eax,eax
jz wmBYE
xor edx,edx
mov rcx,hwndRichEdit
call SetWindowText
mov FileOpened,FALSE
jmp wmBYE
SAVE: mov ecx,offset FileName
jmp @f

SAVEAS: mov edx,sizeof ofn
lea ecx,ofn
call RtlZeroMemory
lea ecx,ofn
mov [rcx+OPENFILENAME.lStructSize],sizeof ofn
mov rax,hWnd
mov [rcx+OPENFILENAME.hwndOwner],rax
mov [rcx+OPENFILENAME.hInstance],IMAGE_BASE
mov eax,offset ASMFilterString
mov [rcx+OPENFILENAME.lpstrFilter],rax
mov eax,offset AlternateFileName
mov [rcx+OPENFILENAME.lpstrFile],rax
mov byte ptr [AlternateFileName],0
mov [rcx+OPENFILENAME.nMaxFile],sizeof AlternateFileName
mov [rcx+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
call GetSaveFileName
or eax,eax;.if eax!=0
jz wmBYE
mov ecx,offset AlternateFileName
@@: mov qword ptr [rsp+30h],0
mov qword ptr [rsp+28h],FILE_ATTRIBUTE_NORMAL
mov qword ptr [rsp+20h],CREATE_ALWAYS
mov r9d,NULL
mov r8d,FILE_SHARE_READ
mov edx,GENERIC_WRITE
call CreateFile
inc eax;.if eax!=INVALID_HANDLE_VALUE
jz wmBYE
dec eax
mov hFile,rax
lea r9,editstream
mov [r9+EDITSTREAM.dwCookie],rax
mov eax,offset StreamOutProc
mov [r9+EDITSTREAM.pfnCallback],rax
mov r8d,SF_TEXT
mov edx,EM_STREAMOUT
mov rcx,hwndRichEdit
call SendMessage
xor r9d,r9d
mov r8d,FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov rcx,hFile
call CloseHandle
jmp wmBYE
COPY: mov edx,WM_COPY
jmp @19
CUT: mov edx,WM_CUT
jmp @19
PASTE: mov edx,WM_PASTE
jmp @19
DELETE1:xor r9d,r9d
mov r8d,TRUE
mov edx,EM_REPLACESEL
jmp @21
SELECTALL:
mov chrg.cpMin,0
mov chrg.cpMax,-1
lea r9,chrg
mov edx,EM_EXSETSEL
jmp @20
UNDO: mov edx,EM_UNDO
jmp @19
REDO: mov edx,EM_REDO
@19: xor r9d,r9d
@20: xor r8d,r8d
@21: mov rcx,hwndRichEdit
jmp @f

EXIT:   mov edx,WM_CLOSE
xor r9d,r9d
mov r8d,r9d
mov rcx,hWnd
@@: call SendMessage
jmp wmBYE

OPTIONS:mov qword ptr [rsp+20h],0
mov r9d,offset OptionProc
mov r8,hWnd
mov edx,IDD_OPTIONDLG
mov ecx,IMAGE_BASE
call DialogBoxParam
jmp wmBYE

wmCLOSE:;mov rcx,hWnd
call CheckModifyState
or eax,eax; .if eax==TRUE
jz wmBYE
        mov rcx,hWnd
call DestroyWindow
jmp wmBYE

wmSIZE: mov eax,r9d;lParam
and r9,0FFFFh
        shr  eax,16
mov qword ptr [rsp+28h],TRUE
mov [rsp+20h],rax
xor edx,edx
mov r8,rdx
mov rcx,hwndRichEdit
call MoveWindow
wmBYE: leave
ret
handle1 dq OPEN,SAVE,CLOSE1,SAVEAS,EXIT,COPY,CUT,PASTE,DELETE1
        dq SELECTALL,OPTIONS,UNDO,REDO
WndProc endp
;----------------------------------------------------------------
ClassName db 'IczEdit version 1.0',0
RichEditDLL db "riched20.dll",0
RichEditClass db "RichEdit20A",0
NoRichEdit db "Cannot find riched20.dll",0
ASMFilterString db "ASM Source code (*.asm)",0,"*.asm",0
db "All Files (*.*)",0,"*.*",0,0
OpenFileFail db "Cannot open the file",0
WannaSave db "The data in the control is modified. Want to save it?",0
FileOpened dq FALSE
BackgroundColor dd 0FFFFFFh; default to white
TextColor dd 0 ; default to black
hRichEdit dq ?
hwndRichEdit dq ?
FileName db 256 dup(?)
AlternateFileName db 256 dup(?)
CustomColors dd 16 dup(?)
rect RECT <?>
end

Mikl__

Win x64 Tutorial  #34: IczEdit version 2.0
due to limitations of forum
Quotemessage should not contain more than 20,000 characters
we divide the text into two parts
rc-file#include "resource.h"
#define IDC_NEXT                        1003
#define IDR_MAINMENU                    101

#define IDD_OPTIONDLG                   101
#define IDD_FINDDLG                     102
#define IDD_GOTODLG                     103
#define IDD_REPLACEDLG                  104
#define IDR_MAINACCEL                   105

#define IDC_BACKCOLORBOX                1000
#define IDC_TEXTCOLORBOX                1001
#define IDC_OK 1002
#define IDC_CANCEL 1003
#define IDC_FINDEDIT                    1000
#define IDC_MATCHCASE                   1001
#define IDC_REPLACEEDIT                 1001
#define IDC_WHOLEWORD                   1002
#define IDC_DOWN                        1003
#define IDC_UP                          1004
#define IDC_LINENO                      1005
#define IDM_OPEN                        40001
#define IDM_SAVE                        40002
#define IDM_CLOSE                       40003
#define IDM_SAVEAS                      40004
#define IDM_EXIT                        40005
#define IDM_COPY                        40006
#define IDM_CUT                         40007
#define IDM_PASTE                       40008
#define IDM_DELETE                      40009
#define IDM_SELECTALL                   40010
#define IDM_OPTION                      40011
#define IDM_UNDO                        40012
#define IDM_REDO                        40013
#define IDM_FIND                        40014
#define IDM_FINDNEXT                    40015
#define IDM_REPLACE                     40016
#define IDM_GOTOLINE                    40017
#define IDM_FINDPREV                    40018

IDR_MAINMENU MENU DISCARDABLE
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&Open",                       IDM_OPEN
        MENUITEM "&Close",                      IDM_CLOSE
        MENUITEM "&Save",                       IDM_SAVE
        MENUITEM "Save &As",                    IDM_SAVEAS
        MENUITEM SEPARATOR
        MENUITEM "E&xit",                       IDM_EXIT
    END
    POPUP "&Edit"
    BEGIN
        MENUITEM "&Undo",                       IDM_UNDO
        MENUITEM "&Redo",                       IDM_REDO
        MENUITEM "&Copy",                       IDM_COPY
        MENUITEM "C&ut",                        IDM_CUT
        MENUITEM "&Paste",                      IDM_PASTE
        MENUITEM SEPARATOR
        MENUITEM "&Delete",                     IDM_DELETE
        MENUITEM SEPARATOR
        MENUITEM "Select &All",                 IDM_SELECTALL
    END
    POPUP "&Search"
    BEGIN
        MENUITEM "&Find...\tCtrl+F",            IDM_FIND
        MENUITEM "Find &Next\tF3",              IDM_FINDNEXT
        MENUITEM "Find &Prev.\tCtrl+F3",        IDM_FINDPREV
        MENUITEM "&Replace..\tCtrl+R",          IDM_REPLACE
        MENUITEM SEPARATOR
        MENUITEM "&Go To Line\tCtrl+G",         IDM_GOTOLINE
    END
    MENUITEM "Options",                     IDM_OPTION
END

IDD_OPTIONDLG DIALOG DISCARDABLE  0, 0, 183, 54
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION |
    WS_SYSMENU
CAPTION "Options"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDC_OK,137,7,39,14
    PUSHBUTTON      "Cancel",IDC_CANCEL,137,25,39,14
    GROUPBOX        "",IDC_STATIC,5,0,124,49
    LTEXT           "Background Color:",IDC_STATIC,20,14,60,8
    LTEXT           "",IDC_BACKCOLORBOX,85,11,28,14,SS_NOTIFY | WS_BORDER
    LTEXT           "Text Color:",IDC_STATIC,20,33,35,8
    LTEXT           "",IDC_TEXTCOLORBOX,85,29,28,14,SS_NOTIFY | WS_BORDER
END

IDD_FINDDLG DIALOG DISCARDABLE  0, 0, 186, 54
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Find.."
FONT 8, "MS Sans Serif"
BEGIN
    EDITTEXT        IDC_FINDEDIT,42,3,94,12,ES_AUTOHSCROLL
    CONTROL         "Match Case",IDC_MATCHCASE,"Button",BS_AUTOCHECKBOX |
                    WS_TABSTOP,6,24,54,10
    CONTROL         "Whole Word",IDC_WHOLEWORD,"Button",BS_AUTOCHECKBOX |
                    WS_TABSTOP,6,37,56,10
    CONTROL         "Down",IDC_DOWN,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
                    83,27,35,10
    CONTROL         "Up",IDC_UP,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,83,
                    38,25,10
    DEFPUSHBUTTON   "OK",IDC_OK,141,3,39,12
    PUSHBUTTON      "Cancel",IDC_CANCEL,141,18,39,12
    LTEXT           "Find what:",IDC_STATIC,5,4,34,8
    GROUPBOX        "Direction",IDC_STATIC,70,18,64,32
END

IDD_GOTODLG DIALOGEX 0, 0, 106, 30
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Go To Line"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
    EDITTEXT        IDC_LINENO,29,4,35,11,ES_AUTOHSCROLL | ES_NUMBER,
                    WS_EX_CLIENTEDGE
    DEFPUSHBUTTON   "OK",IDC_OK,70,4,31,11
    PUSHBUTTON      "Cancel",IDC_CANCEL,70,17,31,11
    LTEXT           "Line :",IDC_STATIC,8,5,18,8
END

IDD_REPLACEDLG DIALOG DISCARDABLE  0, 0, 186, 33
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Replace"
FONT 8, "MS Sans Serif"
BEGIN
    EDITTEXT        IDC_FINDEDIT,51,3,84,12,ES_AUTOHSCROLL
    EDITTEXT        IDC_REPLACEEDIT,51,17,84,11,ES_AUTOHSCROLL
    DEFPUSHBUTTON   "OK",IDC_OK,142,3,39,11
    PUSHBUTTON      "Cancel",IDC_CANCEL,142,17,39,11
    LTEXT           "Find what:",IDC_STATIC,3,4,34,8
    LTEXT           "Replace with",IDC_STATIC,3,18,42,8
END

IDR_MAINACCEL ACCELERATORS DISCARDABLE
BEGIN
    "F",            IDM_FIND,               VIRTKEY, CONTROL, NOINVERT
    "G",            IDM_GOTOLINE,           VIRTKEY, CONTROL, NOINVERT
    "R",            IDM_REPLACE,            VIRTKEY, CONTROL, NOINVERT
    VK_F3,          IDM_FINDNEXT,           VIRTKEY, NOINVERT
    VK_F3,          IDM_FINDPREV,           VIRTKEY, CONTROL, NOINVERT
END
asm-file (part first)OPTION DOTNAME
include temphls.inc
include win64.inc
include user32.inc
include comdlg32.inc
include gdi32.inc
include kernel32.inc
includelib gdi32.lib
includelib comdlg32.lib
includelib user32.lib
includelib kernel32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
IDR_MAINMENU equ 101
IDM_OPEN equ 40001
IDM_SAVE equ 40002
IDM_CLOSE equ 40003
IDM_SAVEAS equ 40004
IDM_EXIT equ 40005
IDM_COPY equ 40006
IDM_CUT equ 40007
IDM_PASTE equ 40008
IDM_DELETE equ 40009
IDM_SELECTALL equ 40010
IDM_OPTION equ 40011
IDM_UNDO equ 40012
IDM_REDO equ 40013
IDM_FIND                equ 40014
IDM_FINDNEXT            equ 40015
IDM_REPLACE             equ 40016
IDM_GOTOLINE            equ 40017
IDM_FINDPREV            equ 40018

IDD_OPTIONDLG equ 101
IDD_FINDDLG             equ 102
IDD_GOTODLG             equ 103
IDD_REPLACEDLG          equ 104
IDR_MAINACCEL           equ 105

IDC_BACKCOLORBOX equ 1000
IDC_TEXTCOLORBOX equ 1001
IDC_OK equ 1002
IDC_CANCEL equ 1003

IDC_FINDEDIT            equ 1000
IDC_MATCHCASE           equ 1001
IDC_REPLACEEDIT         equ 1001
IDC_WHOLEWORD           equ 1002
IDC_DOWN                equ 1003
IDC_UP                  equ 1004
IDC_LINENO              equ 1005

RichEditID equ 300

.code
WinMain proc
LOCAL msg:MSG
local hwnd:QWORD

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

mov ecx,offset RichEditDLL
call LoadLibrary
or eax,eax
jnz @f
mov r9d,MB_OK or MB_ICONERROR
mov r8d,offset AppName
mov edx,offset NoRichEdit
xor ecx,ecx
call MessageBox
xor ecx,ecx
call ExitProcess

@@: mov hRichEdit,rax
        mov byte ptr [FindBuffer],0
mov byte ptr [ReplaceBuffer],0

xor ebx,ebx
mov esi,IMAGE_BASE
mov eax,10029h
mov edi,offset ClassName
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW+1;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
sub esp,20h
    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 hwnd,rax

        mov edx,offset rect
mov ecx,eax
call GetClientRect

        push rbx;0
push IMAGE_BASE
push RichEditID
push hwnd
mov eax,rect.bottom
push rax
mov eax,rect.right
push rax
push rbx
push rbx
        mov r9d,WS_CHILD or WS_VISIBLE or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or ES_NOHIDESEL
mov r8d,ebx;0
mov edx,offset RichEditClass
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
mov hwndRichEdit,rax

mov r9,rbx;0
or r8,-1
mov edx,EM_LIMITTEXT
mov rcx,hwndRichEdit
call SendMessage

call SetColor
mov r9,rbx;0
mov r8,rbx;FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
; mov r9d,ENM_MOUSEEVENTS
; xor r8d,r8d
; mov edx,EM_SETEVENTMASK
; mov rcx,hwndRichEdit
; call SendMessage

mov r9,rbx;0
mov r8,rbx;0
mov edx,EM_EMPTYUNDOBUFFER
mov rcx,hwndRichEdit
call SendMessage

mov ecx,IDR_MAINACCEL
mov edx,IMAGE_BASE
        call LoadAccelerators
mov hAccel,rax
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov edx,edi
mov rcx,hSearch
        call IsDialogMessage
or eax,eax;.if eax==FALSE
jnz @b
mov r8,rdi
mov rdx,hAccel
mov rcx,hwnd
call TranslateAccelerator
or eax,eax;.if eax==0
jnz @b
mov ecx,edi
call TranslateMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp

StreamInProc proc hFile:QWORD,pBuffer:QWORD, NumBytes:QWORD, pBytesRead:QWORD
push rbp
mov ebp,esp
sub esp,30h
mov qword ptr [esp+20h],0
call ReadFile;,hFile,pBuffer,NumBytes,pBytesRead,0
xor eax,1
leave
retn
StreamInProc endp

StreamOutProc proc hFile:QWORD,pBuffer:QWORD, NumBytes:QWORD, pBytesWritten:QWORD
push rbp
mov ebp,esp
sub esp,30h
mov qword ptr [esp+20h],0
call WriteFile;,hFile,pBuffer,NumBytes,pBytesWritten,0
xor eax,1
leave
retn
StreamOutProc endp

CheckModifyState proc hWnd:QWORD
push rbp
mov ebp,esp
sub esp,20h

mov hWnd,rcx

xor r9d,r9d
xor r8d,r8d
mov edx,EM_GETMODIFY
mov rcx,hwndRichEdit
call SendMessage
or eax,eax;.if eax!=0
jz wmBYE
mov r9d,MB_YESNOCANCEL
mov r8d,offset AppName
mov edx,offset WannaSave
mov rcx,hWnd
call MessageBox
cmp eax,IDYES;.if eax==IDYES
jnz @f
xor r9d,r9d
mov r8d,IDM_SAVE
mov edx,WM_COMMAND
mov rcx,hWnd
call SendMessage
jmp wmBYE
@@: cmp eax,IDCANCEL;.elseif eax==IDCANCEL
jnz wmBYE
xor eax,eax;mov eax,FALSE
jmp @f
wmBYE: mov eax,TRUE
@@: leave
ret
CheckModifyState endp

SetColor proc
local cfm:CHARFORMAT

push rbp
mov ebp,esp
sub esp,(20h+sizeof CHARFORMAT+15)and(-16)
mov r9d,BackgroundColor
xor r8d,r8d
mov edx,EM_SETBKGNDCOLOR
mov rcx,hwndRichEdit
call SendMessage
mov edx,sizeof CHARFORMAT
lea ecx,cfm
call RtlZeroMemory
lea r9d,cfm
mov [r9+CHARFORMAT.cbSize],sizeof CHARFORMAT
mov [r9+CHARFORMAT.dwMask],CFM_COLOR
mov eax,TextColor
mov [r9+CHARFORMAT.crTextColor],eax
mov r8d,SCF_ALL
mov edx,EM_SETCHARFORMAT
mov rcx,hwndRichEdit
call SendMessage
leave
retn
SetColor endp

OptionProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL clr:CHOOSECOLOR
local temp:QWORD
push rbp
mov ebp,esp
sub esp,(28h+sizeof CHOOSECOLOR+15)and(-16)

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

cmp edx,WM_INITDIALOG
je wmBYE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CTLCOLORSTATIC
je wmCTLCOLORSTATIC
cmp edx,WM_CLOSE
je wmCLOSE
wmDEFAULT:xor eax,eax;mov eax,FALSE
leave
ret

wmCOMMAND:mov eax,r8d;wParam
shr eax,16
or eax,eax;.if ax==BN_CLICKED
jnz wmBYE
mov eax,r8d;wParam
sub eax,IDC_BACKCOLORBOX
cmp eax,IDC_CANCEL-IDC_BACKCOLORBOX
ja wmBYE
jmp handle[rax*8]
CANCEL: xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
call SendMessage
jmp wmBYE
BACKCOLORBOX:
mov edx,sizeof clr
lea ecx,clr
call RtlZeroMemory
lea ecx,clr
mov [rcx+CHOOSECOLOR.lStructSize],sizeof clr
mov rax,hWnd
mov [rcx+CHOOSECOLOR.hwndOwner],rax
mov [rcx+CHOOSECOLOR.hInstance],IMAGE_BASE
mov eax,BackgroundColor
mov [rcx+CHOOSECOLOR.rgbResult],eax
mov eax,offset CustomColors
mov [rcx+CHOOSECOLOR.lpCustColors],rax
mov [rcx+CHOOSECOLOR.Flags],CC_ANYCOLOR or CC_RGBINIT
call ChooseColor
or eax,eax;.if eax!=0
jz wmBYE
mov eax,clr.rgbResult
mov BackgroundColor,eax
        mov edx,IDC_BACKCOLORBOX
jmp @f
TEXTCOLORBOX:
mov edx,sizeof clr
lea ecx,clr
call RtlZeroMemory
        lea ecx,clr
mov [rcx+CHOOSECOLOR.lStructSize],sizeof clr
mov rax,hWnd
mov [rcx+CHOOSECOLOR.hwndOwner],rax
mov [rcx+CHOOSECOLOR.hInstance],IMAGE_BASE
mov eax,TextColor
mov [rcx+CHOOSECOLOR.rgbResult],eax
mov eax,offset CustomColors
mov [rcx+CHOOSECOLOR.lpCustColors],rax
mov [rcx+CHOOSECOLOR.Flags],CC_ANYCOLOR or CC_RGBINIT
call ChooseColor
or eax,eax;.if eax!=0
jz wmBYE
mov eax,clr.rgbResult
mov TextColor,eax
mov edx,IDC_TEXTCOLORBOX
@@: mov rcx,hWnd
call GetDlgItem
mov r8d,TRUE
xor edx,edx
mov ecx,eax
call InvalidateRect
jmp wmBYE

OK: xor r9d,r9d
xor r8d,r8d
mov edx,EM_GETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov temp,rax
call SetColor
mov r8,temp
xor r9d,r9d
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
xor edx,edx
mov rcx,hWnd
call EndDialog
jmp wmBYE
wmCTLCOLORSTATIC:mov edx,IDC_BACKCOLORBOX
call GetDlgItem
cmp rax,lParam;.if eax==lParam
jnz @f
mov ecx,BackgroundColor
jmp @0
@@: mov edx,IDC_TEXTCOLORBOX
mov rcx,hWnd
call GetDlgItem
cmp rax,lParam;.if eax==lParam
jnz wmDEFAULT
mov ecx,TextColor
@0: call CreateSolidBrush
jmp @1
wmCLOSE:xor edx,edx
mov rcx,hWnd
call EndDialog
wmBYE: mov eax,TRUE
@1: leave
retn
handle dq BACKCOLORBOX,TEXTCOLORBOX,OK,CANCEL
OptionProc endp
to be continue

Mikl__

#80
Win x64 Tutorial  #34: IczEdit version 2.0
asm-file (part second)SearchProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
push rbp
mov ebp,esp
sub esp,30h
mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CLOSE
je wmCLOSE
wmDEFAULT:xor eax,eax;mov eax,FALSE
leave
ret
wmINITDIALOG:mov hSearch,rcx;hWnd
;===================================================
; Select the default search down option
;===================================================
mov r9d,IDC_DOWN
mov r8d,IDC_UP
mov edx,IDC_DOWN
;mov rcx,hWnd
call CheckRadioButton
mov eax,offset FindBuffer
mov [rsp+20h],rax
xor r9d,r9d
mov r8d,WM_SETTEXT
mov edx,IDC_FINDEDIT
mov rcx,hWnd
call SendDlgItemMessage
jmp wmBYE
wmCOMMAND:mov eax,r8d;wParam
shr eax,16
or eax,eax;.if ax==BN_CLICKED
jnz wmBYE
mov eax,r8d;wParam
        sub eax,IDC_OK
cmp eax,IDC_CANCEL-IDC_OK
ja wmBYE
jmp handle3[rax*8]
OK3:    mov uFlags,0
mov r9d,offset findtext.chrg
xor r8d,r8d
mov edx,EM_EXGETSEL
mov rcx,hwndRichEdit
call SendMessage
mov r9d,sizeof FindBuffer
mov r8d,offset FindBuffer
mov edx,IDC_FINDEDIT
mov rcx,hWnd
call GetDlgItemText
or eax,eax;.if eax!=0
jz wmBYE
mov edx,IDC_DOWN
mov rcx,hWnd
call IsDlgButtonChecked
cmp eax,BST_CHECKED
jnz @10
or uFlags,FR_DOWN
mov eax,findtext.chrg.cpMin
cmp eax,findtext.chrg.cpMax
jz @f
mov eax,findtext.chrg.cpMax
mov findtext.chrg.cpMin,eax
@@: mov findtext.chrg.cpMax,-1
jmp @f
@10: mov findtext.chrg.cpMax,0
@@: mov edx,IDC_MATCHCASE
mov rcx,hWnd
call IsDlgButtonChecked
cmp eax,BST_CHECKED
jnz @f
or uFlags,FR_MATCHCASE
@@: mov edx,IDC_WHOLEWORD
mov rcx,hWnd
call IsDlgButtonChecked
cmp eax,BST_CHECKED
jnz @f
or uFlags,FR_WHOLEWORD
@@: mov eax,offset FindBuffer
mov findtext.lpstrText,rax
mov r9d,offset findtext
mov r8d,uFlags
mov edx,EM_FINDTEXTEX
mov rcx,hwndRichEdit
call SendMessage
inc eax;.if eax!=-1
jz wmBYE
mov r9d,offset findtext.chrgText
xor r8d,r8d
mov edx,EM_EXSETSEL
mov rcx,hwndRichEdit
call SendMessage
jmp wmBYE
CANCEL3:xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
mov rcx,hWnd
call SendMessage
jmp wmBYE
wmCLOSE:xor edx,edx
mov hSearch,rdx
;mov rcx,hWnd
call EndDialog
wmBYE: mov eax,TRUE
leave
ret
handle3 dq OK3,CANCEL3
SearchProc endp
;-------------------------------------
ReplaceProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL settext:SETTEXTEX
push rbp
mov ebp,esp
sub esp,(20h+sizeof SETTEXTEX+15)and(-16)
mov hWnd,rcx
;mov uMsg,rdx
mov wParam,r8
mov lParam,r9

cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CLOSE
je wmCLOSE
wmDEFAULT:xor eax,eax;mov eax,FALSE
leave
retn
wmINITDIALOG:mov hSearch,rcx;hWnd
mov r8d,offset FindBuffer
mov edx,IDC_FINDEDIT
mov rcx,hWnd
call SetDlgItemText
mov r8d,offset ReplaceBuffer
mov edx,IDC_REPLACEEDIT
mov rcx,hWnd
call SetDlgItemText
jmp wmBYE
wmCOMMAND:mov eax,r8d;wParam
shr eax,16
or eax,eax;.if ax==BN_CLICKED
jnz wmBYE
mov eax,r8d;wParam
sub eax,IDC_OK
cmp eax,IDC_CANCEL-IDC_OK
ja wmBYE
jmp handle2[rax*8]
CANCEL: xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
mov rcx,hWnd
call SendMessage
jmp wmBYE
OK:     mov r9d,sizeof FindBuffer
mov r8d,offset FindBuffer
mov edx,IDC_FINDEDIT
mov rcx,hWnd
call GetDlgItemText
mov r9d,sizeof ReplaceBuffer
mov r8d,offset ReplaceBuffer
mov edx,IDC_REPLACEEDIT
mov rcx,hWnd
call GetDlgItemText
mov findtext.chrg.cpMin,0
mov findtext.chrg.cpMax,-1
mov eax,offset FindBuffer
mov findtext.lpstrText,rax
mov settext.flags,ST_SELECTION
mov settext.codepage,CP_ACP
@@: mov r9d,offset findtext
mov r8d,FR_DOWN
mov edx,EM_FINDTEXTEX
mov rcx,hwndRichEdit
call SendMessage
inc eax;.if eax==-1
jz wmBYE;.break
mov r9d,offset findtext.chrgText
xor r8d,r8d
mov edx,EM_EXSETSEL
mov rcx,hwndRichEdit
call SendMessage
mov r9d,offset ReplaceBuffer
lea r8,settext
mov edx,EM_SETTEXTEX
mov rcx,hwndRichEdit
call SendMessage
jmp @b
wmCLOSE:xor edx,edx
mov hSearch,rdx
;mov rcx,hWnd
call EndDialog
wmBYE: mov eax,TRUE
leave
retn
handle2 dq OK,CANCEL
ReplaceProc endp
;---------------------------------------------
GoToProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL LineNo:QWORD
LOCAL chrg:CHARRANGE
push rbp
mov ebp,esp
sub esp,(28h+sizeof CHARRANGE+15)and(-16)
mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
wmDEFAULT:xor eax,eax;mov eax,FALSE
leave
retn
wmINITDIALOG:mov hSearch,rcx;hWnd
jmp wmBYE
wmCOMMAND:mov eax,r8d;wParam
shr eax,16
or eax,eax;.if ax==BN_CLICKED
jnz wmBYE
mov eax,r8d;wParam
cmp ax,IDCANCEL
jnz @f
xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
call SendMessage
jmp wmBYE
@@: cmp ax,IDOK
jnz wmBYE
;Когда пользователь набирает номер строки и нажимает кнопку 'Ok',
;начинаем операцию
xor r9d,r9d;FALSE
xor r8d,r8d
mov edx,IDC_LINENO
mov rcx,hWnd
call GetDlgItemInt
mov LineNo,rax
;Получаем номер строки из edit control'а
xor r9d,r9d
xor r8d,r8d
mov edx,EM_GETLINECOUNT
mov rcx,hwndRichEdit
invoke SendMessage
cmp rax,LineNo
jbe wmBYE
;Получаем количество строк в контроле. Проверяем, не указал ли
;пользователь номер строки, который выходит за рамки допустимых
;значений.
xor r9d,r9d
mov r8,LineNo
mov edx,EM_LINEINDEX
mov rcx,hwndRichEdit
call SendMessage
;Если номер строки правильный, мы передвигает курсор к первому символу в
;этой строке. Поэтому мы посылаем сообщение EM_LINEINDEX контролу
;richedit. Это сообщение возвращает индекс первого символа
;в заданной строке. Мы посылаем номер строки через wParam,
;а получаем индекс символа
;Чтобы установить текущее выделение, в этот раз мы используем
;EM_SETSEL, потому что индексы символов уже не находятся в структуре
;CHARRANGE, что сохраняет нам две инструкции (помещение этих индексов
;в структуру CHARRANGE).
mov r9,rax
mov r8,rax
mov edx,EM_SETSEL
mov rcx,hwndRichEdit
call SendMessage
;Курсор не будет отображен, пока контрол RichEdit не получит фокус.
;Поэтому мы вызываем SetFocus
mov rcx,hwndRichEdit
call SetFocus
jmp wmBYE
wmCLOSE:xor edx,edx
mov hSearch,rdx
call EndDialog
wmBYE: mov eax,TRUE
leave
ret
GoToProc endp
;--------------------------------------------------
PrepareEditMenu proc hSubMenu:QWORD
LOCAL chrg:CHARRANGE
push rbp
mov ebp,esp
sub esp,(20h+sizeof CHARRANGE+15)and(-16)
mov hSubMenu,rcx
;=============================================================================
; Check whether there is some text in the clipboard. If so, we enable the paste menuitem
;=============================================================================
xor r9d,r9d
mov r8d,CF_TEXT
mov edx,EM_CANPASTE
mov rcx,hwndRichEdit
call SendMessage
or eax,eax;.if eax==0 ; no text in the clipboard
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_PASTE
mov rcx,hSubMenu
call EnableMenuItem
;==========================================================
; check whether the undo queue is empty
;==========================================================
xor r9d,r9d
xor r8d,r8d
mov edx,EM_CANUNDO
mov rcx,hwndRichEdit
call SendMessage
or eax,eax; .if eax==0
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_UNDO
mov rcx,hSubMenu
call EnableMenuItem
;=========================================================
; check whether the redo queue is empty
;=========================================================
xor r9d,r9d
xor r8d,r8d
mov edx,EM_CANREDO
mov rcx,hwndRichEdit
call SendMessage
or eax,eax; .if eax==0
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_REDO
mov rcx,hSubMenu
call EnableMenuItem
;=========================================================
; check whether there is a current selection in the richedit control.
; If there is, we enable the cut/copy/delete menuitem
;=========================================================
lea r9,chrg
xor r8d,r8d
mov edx,EM_EXGETSEL
mov rcx,hwndRichEdit
call SendMessage
mov eax,chrg.cpMin
cmp eax,chrg.cpMax; .if eax==chrg.cpMax ; no current selection
; no current selection
sete bl;MF_ENABLED=0 MF_GRAYED=1
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_COPY
mov rcx,hSubMenu
call EnableMenuItem
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_CUT
mov rcx,hSubMenu
call EnableMenuItem
mov r8d,ebx;MF_GRAYED/MF_ENABLED
mov edx,IDM_DELETE
mov rcx,hSubMenu
call EnableMenuItem
xor ebx,ebx
leave
ret
PrepareEditMenu endp
;-------------------------------------------
WndProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL ofn:OPENFILENAME
LOCAL buffer[256]:BYTE
LOCAL editstream:EDITSTREAM
LOCAL hFile:QWORD
LOCAL hPopup:QWORD
LOCAL old_rsi:QWORD
LOCAL pt:POINT
LOCAL chrg:CHARRANGE


push rbp
mov ebp,esp
sub esp,(40h+sizeof OPENFILENAME+256+sizeof EDITSTREAM+\
3*8+sizeof POINT+sizeof CHARRANGE+15)and(-16)
mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
mov lParam,r9

cmp edx,WM_NOTIFY
je wmNOTIFY
cmp edx,WM_INITMENUPOPUP
je wmINITMENUPOPUP
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_SIZE
je wmSIZE
cmp edx,WM_DESTROY
je wmDESTROY
wmDEFAULT:leave
jmp DefWindowProc

wmDESTROY:mov rcx,hRichEdit
call FreeLibrary
xor ecx,ecx
call ExitProcess

wmNOTIFY:mov old_rsi,rsi
mov rsi,r9;lParam;assume esi:ptr NMHDR
cmp [rsi+NMHDR._code],EN_MSGFILTER;.if [esi]._code==EN_MSGFILTER
jnz @f;assume esi:ptr MSGFILTER
cmp [rsi+MSGFILTER.msg],WM_RBUTTONDOWN;.if [esi].msg==WM_RBUTTONDOWN
jnz @f
mov rcx,hWnd
call GetMenu
mov edx,1
mov ecx,eax
call GetSubMenu
mov hPopup,rax
mov ecx,eax;hPopup
call PrepareEditMenu
mov rdx,[rsi+MSGFILTER.lParam]
mov ecx,edx
and edx,0FFFFh
shr ecx,16
mov pt.x,edx
mov pt.y,ecx
lea edx,pt
mov rcx,hWnd
call ClientToScreen
mov qword ptr [rsp+30h],NULL
mov rax,hWnd
mov [rsp+28h],rax
mov qword ptr [rsp+20h],NULL
mov r9d,pt.y
mov r8d,pt.x
mov edx,TPM_LEFTALIGN or TPM_BOTTOMALIGN
mov rcx,hPopup
call TrackPopupMenu
@@: mov rsi,old_rsi
jmp wmBYE
wmINITMENUPOPUP:
mov eax,r9d;lParam
or ax,ax;.if ax==0; file menu
jnz @0
cmp FileOpened,TRUE;.if FileOpened==TRUE ; a file is already opened
setne bl;в ebx MF_ENABLED=0 или MF_GRAYED=1
mov r8d,ebx;MF_ENABLED
mov edx,IDM_CLOSE
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_SAVE
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_SAVEAS
mov rcx,wParam
call EnableMenuItem
xor ebx,1
mov r8d,ebx;MF_GRAYED
mov edx,IDM_OPEN
mov rcx,wParam
call EnableMenuItem
xor ebx,ebx
jmp wmBYE; .endif
@0: cmp ax,1;.elseif ax==1 ; edit menu
jnz @f
mov rcx,wParam
        call PrepareEditMenu
jmp wmBYE
@@:     cmp ax,2;.elseif ax==2 ; search menu bar
        jnz wmBYE
cmp FileOpened,TRUE;.if FileOpened==TRUE
setne bl;в ebx MF_ENABLED=0 или MF_GRAYED=1
mov r8d,ebx;MF_ENABLED
mov edx,IDM_FIND
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_FINDNEXT
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_FINDPREV
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_REPLACE
mov rcx,wParam
call EnableMenuItem
mov r8d,ebx;MF_ENABLED
mov edx,IDM_GOTOLINE
mov rcx,wParam
call EnableMenuItem
xor ebx,ebx
jmp wmBYE
wmCOMMAND:
or r9,r9;.if lParam==0 ; menu commands
jnz wmBYE
mov eax,r8d;mov eax,wParam
sub eax,IDM_OPEN;.if ax==IDM_OPEN
cmp eax,IDM_FINDPREV-IDM_OPEN
ja wmBYE
jmp handle1[rax*8]
OPEN:   mov edx,sizeof OPENFILENAME
lea ecx,ofn
call RtlZeroMemory
lea ecx,ofn
mov [rcx+OPENFILENAME.lStructSize],sizeof ofn
mov rax,hWnd
mov [rcx+OPENFILENAME.hwndOwner],rax
mov [rcx+OPENFILENAME.hInstance],IMAGE_BASE
mov eax,offset ASMFilterString
mov [rcx+OPENFILENAME.lpstrFilter],rax
mov eax,offset FileName
mov [rcx+OPENFILENAME.lpstrFile],rax
mov byte ptr [FileName],0
mov [rcx+OPENFILENAME.nMaxFile],sizeof FileName
mov [rcx+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
call GetOpenFileName
or eax,eax; .if eax!=0
jz wmBYE
mov qword ptr [rsp+30h],0
mov qword ptr [rsp+28h],FILE_ATTRIBUTE_NORMAL
mov qword ptr [rsp+20h],OPEN_EXISTING
mov r9d,NULL
mov r8d,FILE_SHARE_READ
mov edx,GENERIC_READ
mov ecx,offset FileName
call CreateFile
inc eax;.if eax!=INVALID_HANDLE_VALUE
jz @f
dec eax
mov hFile,rax
;================================================================
; stream the text into the richedit control
;================================================================
lea r9,editstream
mov [r9+EDITSTREAM.dwCookie],rax
mov eax,offset StreamInProc
mov [r9+EDITSTREAM.pfnCallback],rax

mov r8d,SF_TEXT
mov edx,EM_STREAMIN
mov rcx,hwndRichEdit
call SendMessage
;==========================================================
; Initialize the modify state to false
;==========================================================
xor r9d,r9d
mov r8d,FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov rcx,hFile
call CloseHandle
mov FileOpened,TRUE
jmp wmBYE
@@: mov r9d,MB_OK or MB_ICONERROR
        mov r8d,offset AppName
        mov edx,offset OpenFileFail
mov rcx,hWnd
        call MessageBox
jmp wmBYE
CLOSE1: mov rcx,hWnd
call CheckModifyState
or eax,eax;.if eax==TRUE
jz wmBYE
xor edx,edx
mov rcx,hwndRichEdit
call SetWindowText
mov FileOpened,FALSE
jmp wmBYE
SAVE:   mov ecx,offset FileName
jmp @f
SAVEAS:
mov edx,sizeof ofn
lea ecx,ofn
call RtlZeroMemory
lea ecx,ofn
mov [rcx+OPENFILENAME.lStructSize],sizeof ofn
mov rax,hWnd
mov [rcx+OPENFILENAME.hwndOwner],rax
mov [rcx+OPENFILENAME.hInstance],IMAGE_BASE
mov eax,offset ASMFilterString
mov [rcx+OPENFILENAME.lpstrFilter],rax
mov eax,offset AlternateFileName
mov [rcx+OPENFILENAME.lpstrFile],rax
mov byte ptr [AlternateFileName],0
mov [rcx+OPENFILENAME.nMaxFile],sizeof AlternateFileName
mov [rcx+OPENFILENAME.Flags],OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
call GetSaveFileName
or eax,eax;.if eax!=0
jz wmBYE
mov ecx,offset AlternateFileName
@@: mov qword ptr [rsp+30h],0
mov qword ptr [rsp+28h],FILE_ATTRIBUTE_NORMAL
mov qword ptr [rsp+20h],CREATE_ALWAYS
mov r9d,NULL
mov r8d,FILE_SHARE_READ
mov edx,GENERIC_WRITE
call CreateFile
inc eax;.if eax!=INVALID_HANDLE_VALUE
jz wmBYE
dec eax
mov hFile,rax
;================================================================
; stream the text to the file
;==============================================================
lea r9,editstream
mov [r9+EDITSTREAM.dwCookie],rax
mov eax,offset StreamOutProc
mov [r9+EDITSTREAM.pfnCallback],rax
mov r8d,SF_TEXT
mov edx,EM_STREAMOUT
mov rcx,hwndRichEdit
call SendMessage
;==========================================================
; Initialize the modify state to false
;==========================================================
xor r9d,r9d
mov r8d,FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
mov rcx,hFile
call CloseHandle
jmp wmBYE
COPY:
mov edx,WM_COPY
jmp @19
CUT:
mov edx,WM_CUT
jmp @19
PASTE:
mov edx,WM_PASTE
jmp @19
DELETE1:
xor r9d,r9d
mov r8d,TRUE
mov edx,EM_REPLACESEL
jmp @21
SELECTALL:
mov chrg.cpMin,0
mov chrg.cpMax,-1
lea r9,chrg
mov edx,EM_EXSETSEL
jmp @20
UNDO:
mov edx,EM_UNDO
jmp @19
REDO:
mov edx,EM_REDO
@19: xor r9d,r9d
@20: xor r8d,r8d
@21: mov rcx,hwndRichEdit
call SendMessage
jmp wmBYE
OPTIONS:mov qword ptr [rsp+20h],0
mov r9d,offset OptionProc
mov r8,hWnd
mov edx,IDD_OPTIONDLG
mov ecx,IMAGE_BASE
call DialogBoxParam
jmp wmBYE
FIND:   cmp hSearch,0;.if hSearch==0
jnz wmBYE
mov r9d,offset SearchProc
mov edx,IDD_FINDDLG
jmp @f
REPLACE:cmp hSearch,0;.if hSearch==0
jnz wmBYE
mov r9d,offset ReplaceProc
        mov edx,IDD_REPLACEDLG
jmp @f
GOTOLINE:cmp hSearch,0;.if hSearch==0
jnz wmBYE
mov r9d,offset GoToProc
mov edx,IDD_GOTODLG
@@: mov ecx,IMAGE_BASE
mov r8,hWnd
mov qword ptr [rsp+20h],0
call CreateDialogParam
jmp wmBYE
FINDNEXT:mov ecx,offset FindBuffer
call lstrlen
or eax,eax;.if eax!=0
jz wmBYE
mov r9d,offset findtext.chrg
xor r8d,r8d
mov edx,EM_EXGETSEL
mov rcx,hwndRichEdit
call SendMessage
mov eax,findtext.chrg.cpMin
cmp eax,findtext.chrg.cpMax;.if eax!=findtext.chrg.cpMax
jz @f
mov eax,findtext.chrg.cpMax
mov findtext.chrg.cpMin,eax
@@: mov findtext.chrg.cpMax,-1
mov r8d,FR_DOWN
jmp @f
FINDPREV:
mov ecx,offset FindBuffer
call lstrlen
or eax,eax;.if eax!=0
jz wmBYE
mov r9d,offset findtext.chrg
xor r8d,r8d
mov edx,EM_EXGETSEL
mov rcx,hwndRichEdit
call SendMessage
mov findtext.chrg.cpMax,0
xor r8d,r8d
@@: mov eax,offset FindBuffer
mov findtext.lpstrText,rax
mov r9d,offset findtext
mov edx,EM_FINDTEXTEX
mov rcx,hwndRichEdit
call SendMessage
inc eax;.if eax!=-1
jz wmBYE
mov r9d,offset findtext.chrgText
xor r8d,r8d
mov edx,EM_EXSETSEL
mov rcx,hwndRichEdit
call SendMessage
jmp wmBYE
EXIT:   xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
mov rcx,hWnd
call SendMessage
jmp wmBYE
wmCLOSE:call CheckModifyState
or eax,eax ;.if eax==TRUE
jz wmBYE
        mov rcx,hWnd
call DestroyWindow
jmp wmBYE
wmSIZE: mov eax,r9d;lParam
and r9,0FFFFh
        shr  eax,16
mov qword ptr [rsp+28h],TRUE
mov [rsp+20h],rax
xor edx,edx
mov r8,rdx
mov rcx,hwndRichEdit
call MoveWindow
wmBYE: leave
ret
handle1 dq OPEN,SAVE,CLOSE1,SAVEAS,EXIT,COPY,CUT,PASTE,DELETE1,SELECTALL
dq OPTIONS,UNDO,REDO,FIND,FINDNEXT,REPLACE,GOTOLINE,FINDPREV
WndProc endp
;----------------------------------------------------------------
ClassName db "IczEditClass",0
AppName db "IczEdit version 2.0",0
RichEditDLL db "riched20.dll",0
RichEditClass db "RichEdit20A",0
NoRichEdit db "Cannot find riched20.dll",0
ASMFilterString db "ASM Source code (*.asm)",0,"*.asm",0
db "All Files (*.*)",0,"*.*",0,0
OpenFileFail db "Cannot open the file",0
WannaSave db "The data in the control is modified. Want to save it?",0
FileOpened dq FALSE
BackgroundColor dd 0FFFFFFh; default to white
TextColor dd 0 ; default to black
hSearch dq ? ; handle to the search/replace dialog box
hAccel dq ?
hRichEdit dq ?
hwndRichEdit dq ?
FileName db 256 dup(?)
AlternateFileName db 256 dup(?)
CustomColors dd 16 dup(?)
FindBuffer db 256 dup(?)
ReplaceBuffer db 256 dup(?)
uFlags dd ?
findtext FINDTEXTEX <>
rect RECT <?>
end

Gunther

Hi Micha,

Эти интересные комментарии на русском языке.

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

Mikl__

Hi, Gunter !
This is a test program, when the programs will be ready must to insert comments in any language, as long as the programmer captured the essence of the fragment
Dies ist ein Testprogramm, das Programm bereit, Kommentare in allen Sprachen einsetzen zu können, so lange wie der Programmierer die Essenz des Fragments

Gunther

Micha,

Quote from: Mikl__ on July 02, 2015, 08:12:03 PM
This is a test program, when the programs will be ready must to insert comments in any language, as long as the programmer captured the essence of the fragment
Dies ist ein Testprogramm, das Programm bereit, Kommentare in allen Sprachen einsetzen zu können, so lange wie der Programmierer die Essenz des Fragments

that's clear, no offense. I made a little joke, not more.

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

Mikl__

Win x64 Tutorial  #31b: listview
asm-fileOPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comctl32.inc
includelib comctl32.lib
include gdi32.inc
includelib gdi32.lib
include ole32.inc
includelib ole32.lib
include shell32.inc
includelib shell32.lib

OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
M_MAIN equ 10000
MI_ICON equ 0
MI_SMALLICON equ 2
MI_LIST equ 3
MI_REPORT equ 1
.code
WinMain proc
local msg:MSG
local rect:RECT

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

xor ebx,ebx
call InitCommonControls
mov edi,offset ClassName
mov eax,10027h
mov esi,IMAGE_BASE
; +------------------------------+
; | registering the window class |
; +------------------------------+
push rax ;hIconSm
push rdi ;lpszClassName
push M_MAIN     ;lpszMenuName
push COLOR_WINDOW+1;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 rcx,rsp ;addr WNDCLASSEX
call RegisterClassEx
; +--------------------------+
; | creating the main window |
; +--------------------------+
push rbx
push rsi
shl esi,9
push rbx
push rbx
push 240
push 400
push rsi
push rsi
mov r9d,WS_OVERLAPPEDWINDOW+WS_VISIBLE
mov r8d,edi
mov edx,edi
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
        mov hwnd,rax

        lea edx,rect
mov ecx,eax
call GetClientRect

        push rbx;<-- align 10h
push IMAGE_BASE
push rbx
push hwnd
mov eax,rect.bottom
push rax
mov eax,rect.right
push rax
push rbx
push rbx
mov r9d,LVS_REPORT + WS_CHILD + WS_VISIBLE
mov r8,rbx
mov edx,offset ctlClsNameLv
xor ecx,ecx
sub esp,20h
call CreateWindowEx
mov hList,rax

call lv_col_insert
call lv_col_info_fill

mov r9d,0C9B5AFh
mov r8,rbx
mov edx,LVM_SETTEXTCOLOR
mov rcx,hList
call SendMessage
mov r9d,50352Eh
mov r8,rbx
mov edx,LVM_SETBKCOLOR
mov rcx,hList
call SendMessage
mov r9d,50352Eh
mov r8,rbx
mov edx,LVM_SETTEXTBKCOLOR
mov rcx,hList
call SendMessage
mov rcx,hwnd
call GetMenu
mov menuH,rax
mov qword ptr [rsp+20h],MF_CHECKED
mov r9d,MI_REPORT
mov r8d,MI_LIST
mov edx,MI_ICON
mov ecx,eax
call CheckMenuRadioItem

lea edi,msg
;+---------------------------+
;| entering the message loop |
;+---------------------------+
window_message_loop_start:
mov ecx,edi
xor edx,edx
mov r8,rbx
mov r9,rbx
        call GetMessage
mov ecx,edi
        call DispatchMessage
jmp window_message_loop_start
WinMain endp
;+----------------------+
;| the window procedure |
;+----------------------+
WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

push rbp
mov ebp,esp
sub esp,30h
mov hWnd,rcx
mov wParam,r8
mov lParam,r9

mov rdi,r9;lParam

cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_SIZE
je wmSIZE
cmp edx,WM_NOTIFY
je wmNOTIFY
cmp edx,WM_COMMAND
je wmCOMMAND
wmDEFAULT:leave
jmp DefWindowProc

wmDESTROY:xor ecx,ecx
call ExitProcess
wmSIZE: mov eax,r9d;eax=[lParam]
shr eax,16;eax=[lParam+2]
and r9,0FFFFh
mov qword ptr [rsp+28h],TRUE
mov [rsp+20h],rax
xor edx,edx
mov r8,rdx
mov rcx,hList
call MoveWindow
jmp  wmBYE
wmNOTIFY:mov rdi,r9;lParam
mov rax,[rdi + NMHDR.hwndFrom]
cmp rax,hList
jne wmDEFAULT
cmp [rdi + NMHDR._code],LVN_COLUMNCLICK
je wmNOTIFY_LVN_COLUMNCLICK
cmp [rdi + NMHDR._code],NM_DBLCLK
jne wmDEFAULT
wmNOTIFY_NM_DBLCLK:call lv_item_focus
jmp  wmBYE
wmNOTIFY_LVN_COLUMNCLICK:
cmp [rdi + NM_LISTVIEW.iSubItem+4],1
jne  COLUMNCLICK_FILE
COLUMNCLICK_SIZE:xor lvSortSize,1
mov r8d,lvSortSize
jmp @f
COLUMNCLICK_FILE:xor lvSortFile,1
mov r8d,lvSortFile
@@: mov r9d,offset lv_compare
mov edx,LVM_SORTITEMS
mov rcx,hList
call SendMessage
call lv_param_update
jmp wmBYE
wmCOMMAND:or r9,r9;cmp  [lParam],0
jne  wmBYE
mov edx,GWL_STYLE
mov rcx,hList
call GetWindowLongPtr
and eax,not LVS_TYPEMASK
movzx edi,word ptr wParam
or eax,edi
mov r8,rax
mov edx,GWL_STYLE
mov rcx,hList
call SetWindowLongPtr
push MF_CHECKED
mov r9,rdi
mov r8d,MI_LIST
mov edx,MI_ICON
mov rcx,menuH
call CheckMenuRadioItem
wmBYE: leave
retn
WndProc endp

lv_item_focus proc
local lvi4:LV_ITEM
local buf4[256]:BYTE

push rbp
mov ebp,esp
sub esp,(20h+sizeof LV_ITEM+256+15)and(-16)
mov r9d,LVNI_FOCUSED
or r8d,-1
mov edx,LVM_GETNEXTITEM
mov rcx,hList
call SendMessage
lea r9,lvi4
mov lvi4.iItem,eax
mov lvi4.iSubItem,0;ebx
mov lvi4.imask,LVIF_TEXT
lea eax,buf4
mov lvi4.pszText,rax
mov lvi4.cchTextMax,256
xor r8d,r8d
mov edx,LVM_GETITEM
mov rcx,hList
call SendMessage
xor r9d,r9d;MB_OK
mov r8d,offset ClassName
lea edx,buf4
xor ecx,ecx
call MessageBox
leave
retn
lv_item_focus endp

lv_param_update proc
local lvi1:LV_ITEM
local old_rdi:QWORD

        push rbp
mov ebp,esp
sub esp,(28h+sizeof LV_ITEM+15)and(-16)
mov old_rdi,rdi
xor r9d,r9d
xor r8d,r8d
mov edx,LVM_GETITEMCOUNT
mov rcx,hList
call SendMessage
mov edi,eax
mov lvi1.imask,LVIF_PARAM
mov lvi1.iSubItem,0
mov lvi1.iItem,0
mov lvi1.lParam,0
or eax,eax
je wmBYE
@@: lea r9,lvi1
xor r8d,r8d
mov edx,LVM_SETITEM
mov rcx,hList
call SendMessage
inc lvi1.iItem
        inc lvi1.lParam
dec  edi
jnz  @b
wmBYE: mov rdi,old_rdi
leave
retn
lv_param_update endp

convert_strhval proc
sub esp,28h
mov ecx,esi
call lstrlen
or eax,eax
je f12
mov ecx,eax
xor eax,eax
cqo
@@: imul edx,10 ; edx=edx*10
lodsb ; mov al,[esi]/inc esi
lea edx,[rax+rdx-'0'] ; edx=edx*10+eax
loop @b
mov eax,edx
f12:    add esp,28h
retn
convert_strhval endp

lv_compare proc lParam1:QWORD,lParam2:QWORD,lParamSort:QWORD
local lvi0:LV_ITEM
local buf1[255]:BYTE
local buf2[255]:BYTE
local old_rdi:QWORD
local old_rsi:QWORD

push rbp
mov ebp,esp
sub esp,(30h+510+sizeof LV_ITEM+15)and(-16)

mov lParam1,rcx
mov lParam2,rdx
mov lParamSort,r8
        mov old_rdi,rdi
        mov old_rsi,rsi

mov lvi0.imask,LVIF_TEXT
lea eax,buf1
mov lvi0.pszText,rax
mov lvi0.cchTextMax,255
cmp lParamSort,1
ja compare_3

compare_1:lea r9,lvi0
mov [r9+LV_ITEM.iSubItem],1
mov r8,lParam1
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea esi,buf1
call convert_strhval
mov edi,eax
        lea r9,lvi0
mov r8,lParam2
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea esi,buf1
call convert_strhval
sub edi,eax
cmp lParamSort,1
jne compare_3_exit
mov eax,edi
jmp compare_3_exit

compare_3:lea r9,lvi0
mov [r9+LV_ITEM.iSubItem],0
mov r8,lParam1
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea ecx,buf2 ;destination
lea edx,buf1 ;source
call lstrcpy
        lea r9,lvi0
mov r8,lParam2
mov edx,LVM_GETITEMTEXT
mov rcx,hList
call SendMessage
lea edx,buf2
lea ecx,buf1
cmp lParamSort,3
jne  @f
xchg edx,ecx
@@: call lstrcmpi
compare_3_exit:mov rdi,old_rdi
mov rsi,old_rsi
leave
ret
lv_compare endp

lv_col_insert proc
local lvCol:LV_COLUMN
push rbp
mov ebp,esp
sub esp,(20h+sizeof LV_COLUMN+15)and(-16)

mov lvCol.imask,LVCF_TEXT + LVCF_WIDTH
mov eax,offset lvTxt1
mov lvCol.pszText,rax
mov lvCol.lx,150
lea r9,lvCol
mov r8,rbx
mov edx,LVM_INSERTCOLUMN
mov rcx,hList
call SendMessage
or lvCol.imask,LVCF_FMT
mov lvCol.fmt,LVCFMT_RIGHT
mov eax,offset lvTxt2
mov lvCol.pszText,rax
mov lvCol.lx,100
lea r9,lvCol
mov r8d,1
mov edx,LVM_INSERTCOLUMN
mov rcx,hList
call SendMessage
leave
retn
lv_col_insert endp

lv_col_info_fill proc
local old_rdi:QWORD
push rbp
mov ebp,esp
sub esp,30h
mov old_rdi,rdi
mov edx,offset fData
mov ecx,offset fTxt1
call FindFirstFile
inc eax ; eax = INVALID_HANDLE_VALUE ?
je fill_exit
dec eax
mov fFileH,rax
xor edi,edi
fill_start:cmp fData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY
je @f
call lv_col_info_insert
inc  edi
@@: mov edx,offset fData
mov rcx,fFileH
call FindNextFile
or eax,eax ; eax <> 0 ?
jne fill_start
fill_end:mov rcx,fFileH
call FindClose
fill_exit:mov rdi,old_rdi
leave
retn
lv_col_info_fill endp

lv_col_info_insert proc
local lvi2:LV_ITEM
local buf3[20]:BYTE
push rbp
mov ebp,esp
sub esp,(20h+20+sizeof LV_ITEM+15)and(-16)

lea r9,lvi2
mov [r9+LV_ITEM.imask],LVIF_TEXT + LVIF_PARAM
mov eax,offset fData.cFileName
mov [r9+LV_ITEM.pszText],rax
mov [r9+LV_ITEM.iSubItem],ebx
mov [r9+LV_ITEM.iItem],edi;?
mov [r9+LV_ITEM.lParam],edi
mov r8,rbx
mov edx,LVM_INSERTITEM
mov rcx,hList
call SendMessage
mov lvi2.imask,LVIF_TEXT
inc lvi2.iSubItem
lea eax,buf3
mov lvi2.pszText,rax
mov r8d,fData.nFileSizeLow
mov edx,offset lvTxt3
mov ecx,eax
call wsprintf
lea r9,lvi2
mov r8,rbx
mov edx,LVM_SETITEM
mov rcx,hList
call SendMessage
leave
ret
lv_col_info_insert endp
;------------------------------------------------------------------------
hwnd dq ?
ClassName db 'Win64 Iczelion''s lesson #31b: listview',0
ctlClsNameLv db 'SysListView32',0
hList dq ?
lvTxt1 db 'File Name',0
lvTxt2 db 'Size',0
lvTxt3 db '%lu',0
lvSortSize dd 0
lvSortFile dd 2;0
menuH dq ?
fFileH dq ?
fData WIN32_FIND_DATA <>
fTxt1 db '*.*',0
end
rc-file#define MI_ICON 0
#define MI_REPORT 1
#define MI_SMALLICON 2
#define MI_LIST 3
#define M_MAIN 10000

M_MAIN MENU
{
POPUP "&View"
{       MENUITEM "Lar&ge Icons",MI_ICON
MENUITEM "S&mall Icons",MI_SMALLICON
MENUITEM "&List",MI_LIST
MENUITEM "&Details",MI_REPORT
}
}

Mikl__

#85
Wow!
Quotetut33.zip (181.14 kB - downloaded 129 times.)
with an average of about 20 downloads somebody's attention was drawn to this particular tut33.zip
wildly popular!

Mikl__

Win x64 Tutorial #37a: The simplest animation
asm-fileOPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comctl32.inc
includelib comctl32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
ACM_OPEN = WM_USER + 100
ACS_AUTOPLAY = 4
ID_ANIMATE = 101
.code
WinMain proc
local msg:MSG
local hwnd:QWORD

push rbp
mov ebp,esp
sub esp,sizeof MSG+8

xor ebx,ebx
mov esi,IMAGE_BASE
mov eax,10027h
mov edi,offset ClassName
push rax ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;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
push rbx
push rbx
push 244
push 300
push 300
push 300
mov r9d,WS_CAPTION or WS_SYSMENU or WS_VISIBLE
mov r8d,edi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h
    call CreateWindowEx
mov hwnd,rax

push rbx
push rsi;IMAGE_BASE
push ID_ANIMATE
push rax;hwnd
push 128
push 162
push 48
push 66
mov r9d,WS_CHILD+WS_VISIBLE+WS_TABSTOP+ACS_AUTOPLAY
mov r8d,offset NoText
mov edx,offset Animate32
mov ecx,WS_EX_STATICEDGE+WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx

mov eax,offset AviFile
mov [rsp+20h],rax
mov r9d,IMAGE_BASE
mov r8d,ACM_OPEN
mov edx,ID_ANIMATE
mov rcx,hwnd
    call SendDlgItemMessage

    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 'Win64 Iczelion''s Tutorial #37a: Animation',0
AviFile db 'skeleton.avi',0
Animate32 db "SysAnimate32"
NoText db 0
end
There are asm-, exe-, bat-files and skeleton.avi in attachment

Mikl__

Win x64 Tutorial #37b: Slightly more complex player of avi/wmv-files
asm-fileOPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include comctl32.inc
includelib comctl32.lib
include winmm.inc
includelib winmm.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
MCI_ANIM_OPEN_PARMS STRUCT
  dwCallback        QWORD      ?
  wDeviceID         DWORD      ?
  lpstrDeviceType   QWORD      ?
  lpstrElementName  QWORD      ?
  lpstrAlias        QWORD      ?
  dwStyle           DWORD      ?
  hWndParent        QWORD      ?
MCI_ANIM_OPEN_PARMS ENDS
MCI_ANIM_PLAY_PARMS STRUCT
  dwCallback    QWORD      ?
  dwFrom        DWORD      ?
  dwTo          DWORD      ?
  dwSpeed       DWORD      ?
MCI_ANIM_PLAY_PARMS ENDS
MCI_GENERIC_PARMS STRUCT
  dwCallback  QWORD      ?
MCI_GENERIC_PARMS ENDS
.code
WinMain proc
local msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov eax,10027h
mov edi,offset ClassName
push rax ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW;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
push rbx
push rbx
push 508;640x480
push 645
push rsi
push rsi
mov r9d,WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX or WS_VISIBLE
mov r8d,edi ;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 buff[96]:BYTE

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

mov hWnd,rcx
mov wParam,r8
mov lParam,r9
cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_CREATE
je wmCREATE
cmp edx,MM_MCINOTIFY
je mmMCINOTIFY
leave
        jmp DefWindowProc
wmDESTROY:mov r9d,offset mciCP
xor r8d,r8d
mov edx,MCI_CLOSE
mov ecx,mciOP.wDeviceID
call mciSendCommand
xor ecx,ecx
        call ExitProcess
wmCREATE:mov mciOP.hWndParent,rcx
mov r9d,offset mciOP
mov r8d,MCI_WAIT or MCI_OPEN_ELEMENT or MCI_ANIM_OPEN_WS or MCI_ANIM_OPEN_PARENT
mov edx,MCI_OPEN
xor ecx,ecx
call mciSendCommand
or eax,eax
je @f
CALL MCIError
;--------------------------------------------------------------------- EOF AVI
mmMCINOTIFY:;mov rcx,hWnd
call DestroyWindow
jmp wmBYE
;-------------------------------------------------------------------- Play AVI
@@:     mov rax,hWnd
mov mciPP.dwCallback,rax
mov r9d,offset mciPP
mov r8d,MCI_NOTIFY
mov edx,MCI_PLAY
mov ecx,mciOP.wDeviceID
call mciSendCommand
or eax,eax
je wmBYE
MCIError:sub esp,28h
mov r8d,96
lea edx,buff
mov ecx,eax
call mciGetErrorString
mov r9d,MB_OK or MB_ICONSTOP
mov r8d,offset aMCIError
lea edx,buff
mov rcx,hWnd
call MessageBox
wmBYE: leave
ret
WndProc endp
ClassName db 'Win64 Iczelion''s Tutorial #37b: Animation',0
mciOP  MCI_ANIM_OPEN_PARMS <0,0,DeviceType,ElementName,0,WS_CHILD,0>
mciPP  MCI_ANIM_PLAY_PARMS <0>
mciCP  MCI_GENERIC_PARMS   <1>
aMCIError db "MCI Error",0
DeviceType DB 'AVIVideo',0
ElementName DB 'movie.wmv',0
end

Mikl__

Win x64 Tutorial #37с: play AVI-files using the ShellExecute
asm-fileinclude win64.inc
include shell32.inc
includelib shell32.lib
include comctl32.inc
includelib comctl32.lib
.code
WinMain proc
sub esp,7*8
mov qword ptr [rsp+28h],SW_SHOWNORMAL
xor ecx,ecx
mov [rsp+20h],rcx
xor r9d,r9d
mov r8d,offset szFilm
mov edx,offset szOpen
call ShellExecute
        add esp,7*8
ret
WinMain endp
szFilm db 'movie.wmv',0
szOpen db 'open',0
end
If you want to modify the program - insert call of the function GetOpenFileName and upload the name of file in the second parameter instead of a fixed szFilm, if you want to full-screen playback, then you change SW_SHOWNORMAL to SW_SHOWMAXIMIZED.

Mikl__

Win x64 Tutorial #37d: play AVI-files using the ShellExecuteEx
typedef struct _SHELLEXECUTEINFO {
  DWORD     cbSize;
  ULONG     fMask;
  HWND      hwnd;
  LPCTSTR   lpVerb;
  LPCTSTR   lpFile;
  LPCTSTR   lpParameters;
  LPCTSTR   lpDirectory;
  int       nShow;
  HINSTANCE hInstApp;
  LPVOID    lpIDList;
  LPCTSTR   lpClass;
  HKEY      hkeyClass;
  DWORD     dwHotKey;
  union {
    HANDLE hIcon;
    HANDLE hMonitor;
  } DUMMYUNIONNAME;
  HANDLE    hProcess;
} SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO;
asm-fileOPTION DOTNAME
include temphls.inc
include win64.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include shell32.inc
includelib shell32.lib
include comctl32.inc
includelib comctl32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
.code
WinMain proc
        sub esp,8       ;<--16bit align
xor ebx,ebx
push rbx ;rcx+68h hProcess
push rbx ;rcx+60h      hMonitor
push rbx ;rcx+58h      hIcon
push rbx ;rcx+54h      dwHotKey
push rbx ;rcx+4Ch      hkeyClass
push rbx ;rcx+44h      lpClass
push rbx ;rcx+3Ch      lpIDList
push SW_SHOWNORMAL;rcx+30h nShow     rcx+34h hInstapp
push rbx ;rcx+28h      lpdirectory
push rbx ;rcx+20h      lpParameters
db 68h
dd szFilm ;rcx+18h      lpFile
db 68h
dd szOpen ;rcx+10h      lpVerb
push rbx ;rcx+08h      hWnd
mov rax,(1500h shl 32 + 70h) ;cbSize=sizeof SHELLEXECUTEINFO  fMask=1500h
push rax ;rcx+0 cbSize   rcx+4 fMask
mov ecx,esp ;<-- SHELLEXECUTEINFO
call ShellExecuteEx
        xor ecx,ecx
call ExitProcess
WinMain endp
szFilm db 'movie.wmv',0
szOpen db 'open',0
end