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__

#90
Win x64 Tutorial #37e: Yet another video-player
asm-fileinclude win64a.inc
include shell32.inc
includelib shell32.lib
include comdlg32.inc
includelib comdlg32.lib
include msvfw32.inc
includelib msvfw32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
MENU_FILE            equ 0
MENU_CD              equ 1
MENU_VIDEODISK       equ 2
MENU_VIDEOPLAYER     equ 3
MENU_FULLSCREEN      equ 4
MENU_ABOUT           equ 5
MCIWNDF_NOAUTOSIZEWINDOW    equ 0001h
MCIWNDF_NOPLAYBAR           equ 0002h
MCIWNDF_NOAUTOSIZEMOVIE     equ 0004h
MCIWNDF_NOMENU              equ 0008h
MCIWNDF_SHOWNAME            equ 0010h
MCIWNDF_SHOWPOS             equ 0020h
MCIWNDF_SHOWMODE            equ 0040h
MCIWNDF_SHOWALL             equ 0070h
MCIWNDF_NOTIFYMODE          equ 0100h
MCIWNDF_NOTIFYPOS           equ 0200h
MCIWNDF_NOTIFYSIZE          equ 0400h
MCIWNDF_NOTIFYERROR         equ 1000h
MCIWNDF_NOTIFYALL           equ 1F00h
MCIWNDF_NOTIFYANSI          equ 0080h
MCIWNDF_NOTIFYMEDIAA        equ 0880h
MCIWNDF_NOTIFYMEDIAW        equ 0800h
;IFDEF __UNICODE__
;    MCIWNDF_NOTIFYMEDIA equ MCIWNDF_NOTIFYMEDIAW
;ELSE
;    MCIWNDF_NOTIFYMEDIA equ MCIWNDF_NOTIFYMEDIAA
;ENDIF

MCIWNDF_RECORD              equ 2000h
MCIWNDF_NOERRORDLG          equ 4000h
MCIWNDF_NOOPEN              equ 8000h
MCIWNDM_GETDEVICEID         equ WM_USER+100
MCIWNDM_GETSTART            equ WM_USER+103
MCIWNDM_GETLENGTH           equ WM_USER+104
MCIWNDM_GETEND              equ WM_USER+105
MCIWNDM_EJECT               equ WM_USER+107
MCIWNDM_SETZOOM             equ WM_USER+108
MCIWNDM_GETZOOM             equ WM_USER+109
MCIWNDM_SETVOLUME           equ WM_USER+110
MCIWNDM_GETVOLUME           equ WM_USER+111
MCIWNDM_SETSPEED            equ WM_USER+112
MCIWNDM_GETSPEED            equ WM_USER+113
MCIWNDM_SETREPEAT           equ WM_USER+114
MCIWNDM_GETREPEAT           equ WM_USER+115
MCIWNDM_REALIZE             equ WM_USER+118
MCIWNDM_VALIDATEMEDIA       equ WM_USER+121
MCIWNDM_PLAYFROM            equ WM_USER+122
MCIWNDM_PLAYTO              equ WM_USER+123
MCIWNDM_GETPALETTE          equ WM_USER+126
MCIWNDM_SETPALETTE          equ WM_USER+127
MCIWNDM_SETTIMERS           equ WM_USER+129
MCIWNDM_SETACTIVETIMER      equ WM_USER+130
MCIWNDM_SETINACTIVETIMER    equ WM_USER+131
MCIWNDM_GETACTIVETIMER      equ WM_USER+132
MCIWNDM_GETINACTIVETIMER    equ WM_USER+133
MCIWNDM_CHANGESTYLES        equ WM_USER+135
MCIWNDM_GETSTYLES           equ WM_USER+136
MCIWNDM_GETALIAS            equ WM_USER+137
MCIWNDM_PLAYREVERSE         equ WM_USER+139
MCIWNDM_GET_SOURCE          equ WM_USER+140
MCIWNDM_PUT_SOURCE          equ WM_USER+141
MCIWNDM_GET_DEST            equ WM_USER+142
MCIWNDM_PUT_DEST            equ WM_USER+143
MCIWNDM_CAN_PLAY            equ WM_USER+144
MCIWNDM_CAN_WINDOW          equ WM_USER+145
MCIWNDM_CAN_RECORD          equ WM_USER+146
MCIWNDM_CAN_SAVE            equ WM_USER+147
MCIWNDM_CAN_EJECT           equ WM_USER+148
MCIWNDM_CAN_CONFIG          equ WM_USER+149
MCIWNDM_PALETTEKICK         equ WM_USER+150
MCIWNDM_OPENINTERFACE       equ WM_USER+151
MCIWNDM_SETOWNER            equ WM_USER+152

MCIWNDM_GETMODEA            equ WM_USER+106
MCIWNDM_GETMODEW            equ WM_USER+206
MCIWNDM_SETTIMEFORMATA      equ WM_USER+119
MCIWNDM_SETTIMEFORMATW      equ WM_USER+219
MCIWNDM_GETTIMEFORMATA      equ WM_USER+120
MCIWNDM_GETTIMEFORMATW      equ WM_USER+220
MCIWNDM_GETFILENAMEA        equ WM_USER+124
MCIWNDM_GETFILENAMEW        equ WM_USER+224
MCIWNDM_GETDEVICEA          equ WM_USER+125
MCIWNDM_GETDEVICEW          equ WM_USER+225
MCIWNDM_GETERRORA           equ WM_USER+128
MCIWNDM_GETERRORW           equ WM_USER+228
MCIWNDM_NEWA                equ WM_USER+134
MCIWNDM_NEWW                equ WM_USER+234
MCIWNDM_RETURNSTRINGA       equ WM_USER+138
MCIWNDM_RETURNSTRINGW       equ WM_USER+238
MCIWNDM_OPENA               equ WM_USER+153
MCIWNDM_OPENW               equ WM_USER+252
MCIWNDM_SENDSTRINGA         equ WM_USER+101
MCIWNDM_SENDSTRINGW         equ WM_USER+201
MCIWNDM_GETPOSITIONA        equ WM_USER+102
MCIWNDM_GETPOSITIONW        equ WM_USER+202
MCIWNDM_NOTIFYMODE          equ WM_USER+200
MCIWNDM_NOTIFYPOS           equ WM_USER+201
MCIWNDM_NOTIFYSIZE          equ WM_USER+202
MCIWNDM_NOTIFYMEDIA         equ WM_USER+203
MCIWNDM_NOTIFYERROR         equ WM_USER+205

.code
WinMain proc
local buffer[128]:BYTE
local msg:MSG

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

xor ebx,ebx
lea eax,buffer
mov pBuffer,rax
mov r9d,offset MediaFileName;имя устройства или путь к файлу
mov r8d,WS_VISIBLE or WS_OVERLAPPEDWINDOW or MCIWNDF_NOMENU;стиль
mov edx,IMAGE_BASE;идентификатор приложения
xor ecx,ecx ;идентификатор родительского окна
call MCIWndCreate
        mov mcihWnd,rax

mov edx,TRUE
mov ecx,eax;mcihWnd
        invoke DragAcceptFiles
;-----------------------------------------------
xor edx,edx;FALSE
mov rcx,mcihWnd 
        call GetSystemMenu
        mov hMenu,rax;в edi handleMenu
; дописываю новые пункты в системное меню
xor esi,esi
@@: mov rax,[handle1+rsi*8]
mov [rsp+20h],rax
mov r9d,esi
mov r8d,MF_BYPOSITION
mov edx,esi
mov rcx,hMenu
        call InsertMenu
        inc esi
cmp esi,5
jna @b

mov r8d,offset WndProc
mov edx,GWL_WNDPROC
mov rcx,mcihWnd
        invoke SetWindowLongPtr
        mov prevWindow,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:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD

push rbp
mov ebp,esp
sub esp,30h

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


        cmp  edx,WM_CLOSE
        je   wmCLOSE
        cmp  edx,WM_SYSCOMMAND
        je   wmSYSCOMMAND
        cmp  edx,WM_DROPFILES
        je   wmDROPFILES
        cmp  edx,MM_MCINOTIFY
        je   mmMCINOTIFY
        cmp  edx,WM_CLOSE
        je   wmCLOSE
        cmp  edx,WM_DESTROY
        jne  default
wmDESTROY: xor ecx,ecx
        call ExitProcess
mmMCINOTIFY:mov edx,SW_MINIMIZE or SW_SHOWNORMAL
        mov rcx,hWnd
call ShowWindow
xor r9d,r9d; FALSE
mov r8d,MCIWNDF_NOMENU
mov edx,MCIWNDM_CHANGESTYLES
mov rcx,hWnd
        call SendMessage
mov r9d,offset szStop
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
        call SendMessage
jmp default
wmDROPFILES:mov r9d,128
mov r8,pBuffer
xor edx,edx
mov rcx,wParam
call DragQueryFile
mov rcx,wParam
        call DragFinish
jmp a1
wmSYSCOMMAND:
mov eax,r8d;wParam
cmp eax,MENU_ABOUT
ja default
jmp [handle+rax*8]
wmCLOSE:mov r9d,offset szStop
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
call SendMessage
mov r9d,offset szClose
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
        call SendMessage
        mov rcx,hWnd
call DestroyWindow
jmp default
mnuFILE:mov rdx,pBuffer
mov [rdx],rbx; ноль в начало буфера для названия файла
;заполняю OPENFILENAME
        push rbx; <-- align 16-bits

push rbx;lpTemplateName
push rbx;lpfnHook
push rbx;lCustData
push rbx;lpstrDefExt
push OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES \
or OFN_EXPLORER or OFN_HIDEREADONLY;Flags & nFileOffset & nFileExtension
push rbx;lpstrTitle
push rbx;lpstrInitialDir
push rbx;nMaxFileTitle
push rbx;lpstrFileTitle
push 124;nMaxFile
push rbx;lpstrFile
push rbx;nMaxCustFilter & nFilterIndex
push rbx;lpstrCustomFilter
mov eax,offset LoadFileFilter
push rax;lpstrFilter
push IMAGE_BASE;hInstance
push hWnd;hwndOwner
push sizeof OPENFILENAME;lStructSize
;----------------------------------------------------
mov ecx,esp;адрес OPENFILENAME
mov edi,ecx
        call GetOpenFileName
test eax,eax
jz wmCLOSE; если не выбран никакой файл
        movzx edx,word ptr [rdi+OPENFILENAME.nFileExtension]
        add rdx,[rdi+OPENFILENAME.lpstrFile];offset LoadFileBuffer
;add esp,4Ch; удаляю OPENFILENAME
        mov eax,[rdx];в регисре еах расширение файла
        or eax,202020h;приводим к нижнему регистру
        cmp eax,"adc"
jnz a1
mnuCD:  mov r8d,offset cdaudioDev
jmp @f
mnuVIDEODISK: mov r8d,offset videodiscDev
jmp @f;wmBYE
mnuVIDEOPLAYER: mov r8d,offset szVideoPlayer
@@: mov rcx,pBuffer
call lstrcpy
a1: mov r9d,offset szStop
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
        call SendMessage
mov r9,pBuffer
xor r8d,r8d
mov edx,MCIWNDM_OPENA
mov rcx,hWnd
        call SendMessage
        test eax,eax
jnz NoMedia;        .if eax = 0
mov r9d,offset szPlay
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
        call SendMessage
        test eax,eax
jnz NoMedia;            .if eax = 0
mov edx,SW_SHOWNORMAL
mov rcx,hWnd
        call ShowWindow
xor r9d,r9d
mov r8d,MCIWNDF_NOPLAYBAR
mov edx,MCIWNDM_CHANGESTYLES
mov rcx,hWnd
        call SendMessage
mov r9d,100
xor r8d,r8d
mov edx,MCIWNDM_SETZOOM
mov rcx,hWnd;hWnd
        call SendMessage
mov flag_fullscreen,TRUE
        jmp @f
NoMedia:mov flag_fullscreen,rbx;FALSE
mov r9d,offset szClose
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
        call SendMessage
mov r9d,MCIWNDF_NOPLAYBAR
mov r8d,MCIWNDF_NOPLAYBAR
mov edx,MCIWNDM_CHANGESTYLES
mov rcx,hWnd
        call SendMessage
@@:     mov edx,TRUE
mov rcx,mcihWnd
call DragAcceptFiles
jmp default
mnuFULLSCREEN:mov edx,SW_SHOWNORMAL
mov rcx,hWnd
call ShowWindow
mov r9d,offset szPlayfullscreen
xor r8d,r8d
mov edx,MCIWNDM_SENDSTRINGA
mov rcx,hWnd
        call SendMessage
        test eax,eax;.if eax=0
jnz default
mov r9d,MCIWNDF_NOPLAYBAR
mov r8d,MCIWNDF_NOPLAYBAR
mov edx,MCIWNDM_CHANGESTYLES
mov rcx,hWnd;hWnd
        call SendMessage
        jmp default
mnuABOUT:mov r9d,MB_OK+MB_ICONINFORMATION
mov r8d,offset szAbout
mov edx,offset szAboutText
        mov rcx,hWnd
call MessageBox
default:mov rax,lParam
mov [rsp+20h],rax
mov r9,wParam
mov r8,uMsg
mov rdx,hWnd
        mov rcx,prevWindow
call CallWindowProc
leave
        retn
handle dq mnuFILE,mnuCD,mnuVIDEODISK,mnuVIDEOPLAYER,mnuFULLSCREEN,mnuABOUT
WndProc endp
;---------------------------------------
mcihWnd                 dq ?
prevWindow              dq ?   
pBuffer dq ?
hMenu dq ?
flag_fullscreen dq FALSE
szFile                  db "File",0
szCD                    db "Audio CD",0
szVideoDisk             db "Video CD",0
szVideoPlayer           db "vcr",0
szFullScreen            db "Full screen",0
LoadFileFilter          db "All files",0,"*",0,0;
szAbout                 db "About program...",0
szPlay                  db "PLAY",0
szStop                  db "STOP",0
szClose                 db "CLOSE",0
szPlayfullscreen        db "PLAY FULLSCREEN NOTIFY",0
szAboutText             db "Mini-media player",0Dh,0Ah,\
                           "Based on JTG coding",0
cdaudioDev              db "cdaudio",0
vcrExt                  db "UNKNOWN",0     
videodiscDev            db "videodisk",0
MediaFileName           db "movie.wmv"
handle1 dq szFile,szCD,szVideoDisk,szVideoPlayer,szFullScreen,szAbout
end

Mikl__

#91
Win x64 Tutorial #37f: video-player and Component Object Model
OPTION 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 comdlg32.inc
includelib comdlg32.lib
include ole32.inc
includelib ole32.lib
OPTION PROLOGUE:none
OPTION EPILOGUE:none
IMAGE_BASE equ 400000h
;-------------------------------
CLSCTX_INPROC_SERVER equ  1
WM_GRAPHNOTIFY equ 40Dh
Size_of_buffer equ 100h
;-------------------------------
;  IGraphBuilder  virtual method table
;-------------------------------
IGraphBuilderVtbl STRUCT
;IUnknown methods
QueryInterface QWORD ?
AddRef QWORD ?
Release QWORD ?
;IGraphBuilder methods
AddFilter QWORD ?
RemoveFilter QWORD ?
EnumFilters QWORD ?
FindFilterByName QWORD ?
ConnectDirect QWORD ?
Reconnect QWORD ?
Disconnect QWORD ?
SetDefaultSyncSource QWORD ?
Connect QWORD ?
Render QWORD ?
RenderFile QWORD ?
AddSourceFilter QWORD ?
SetLogFile QWORD ?
Abort QWORD ?
ShouldOperationContinue QWORD ?
IGraphBuilderVtbl ENDS
;-------------------------------
IMediaControlVtbl STRUCT
;IUnknown methods
QueryInterface QWORD ?
AddRef QWORD ?
Release QWORD ?
;IMediaControl methods
GetTypeInfoCount QWORD ?
GetTypeInfo QWORD ?
GetIDsOfNames QWORD ?
Invoke_ QWORD ?
Run QWORD ?
Pause_ QWORD ?
Stop QWORD ?
GetState QWORD ?
RenderFile QWORD ?
    AddSourceFilter QWORD ?
    get_FilterCollection QWORD ?
    get_RegFilterCollection QWORD ?
    StopWhenReady QWORD ?
IMediaControlVtbl ENDS
;-------------------------------
;  IMediaEventEx  virtual method table
;-------------------------------
IMediaEventExVtbl STRUCT
;IUnknown methods
    QueryInterface QWORD ?
    AddRef QWORD ?
    Release QWORD ?
;IMediaEventEx methods
    GetTypeInfoCount QWORD ?
    GetTypeInfo QWORD ?
    GetIDsOfNames QWORD ?
    Invoke_ QWORD ?
    GetEventHandle QWORD ?
    GetEvent QWORD ?
    WaitForCompletion QWORD ?
    CancelDefaultHandling QWORD ?
    RestoreDefaultHandling QWORD ?
    FreeEventParams QWORD ?
    SetNotifyWindow QWORD ?
    SetNotifyFlags QWORD ?
    GetNotifyFlags QWORD ?
IMediaEventExVtbl ENDS
;-----------------------------------------------------
;  IGraphBuilder  virtual method table
;-----------------------------------------------------
IGraphBuilderVtbl STRUCT
;IUnknown methods
    QueryInterface QWORD ?
    AddRef QWORD ?
    Release QWORD ?
;IGraphBuilder methods
    AddFilter         QWORD ?
    RemoveFilter QWORD ?
    EnumFilters             QWORD ?
FindFilterByName        QWORD ?
ConnectDirect           QWORD ?
Reconnect               QWORD ?
Disconnect QWORD ?
SetDefaultSyncSource    QWORD ?
Connect         QWORD ?
Render         QWORD ?
RenderFile QWORD ?
AddSourceFilter QWORD ?
SetLogFile QWORD ?
Abort         QWORD ?
ShouldOperationContinue QWORD ?
IGraphBuilderVtbl ENDS
;-----------------------------------------------------
;  IVideoWindow  virtual method table
;------------------------------------------------
IVideoWindowVtbl STRUCT
;IUnknown methods
    QueryInterface QWORD ?
    AddRef QWORD ?
    Release QWORD ?
;IVideoWindow methods
    GetTypeInfoCount       QWORD ?
    GetTypeInfo       QWORD ?
    GetIDsOfNames                QWORD ?
    Invoke_                      QWORD ?
    put_Caption                  QWORD ?
    get_Caption                  QWORD ?
    put_WindowStyle              QWORD ?
    get_WindowStyle              QWORD ?
    put_WindowStyleEx            QWORD ?
    get_WindowStyleEx            QWORD ?
    put_AutoShow                 QWORD ?
    get_AutoShow                 QWORD ?
    put_WindowState              QWORD ?
    get_WindowState              QWORD ?
    put_BackgroundPalette        QWORD ?
    get_BackgroundPalette        QWORD ?
    put_Visible                  QWORD ?
    get_Visible                  QWORD ?
    put_Left                     QWORD ?
    get_Left                     QWORD ?
    put_Width                    QWORD ?
    get_Width                    QWORD ?
    put_Top                      QWORD ?
    get_Top                      QWORD ?
    put_Height                   QWORD ?
    get_Height                   QWORD ?
    put_Owner                    QWORD ?
    get_Owner                    QWORD ?
    put_MessageDrain             QWORD ?
    get_MessageDrain             QWORD ?
    get_BorderColor              QWORD ?
    put_BorderColor QWORD ?
    get_FullScreenMode QWORD ?
    put_FullScreenMode QWORD ?
    SetWindowForeground QWORD ?
    NotifyOwnerMessage QWORD ?
    SetWindowPosition QWORD ?
    GetWindowPosition QWORD ?
    GetMinIdealImageSize QWORD ?
    GetMaxIdealImageSize QWORD ?
    GetRestorePosition QWORD ?
    HideCursor QWORD ?
    IsCursorHidden QWORD ?
IVideoWindowVtbl ENDS
.code
WinMain proc
local bufferANSI[Size_of_buffer]:BYTE
local bufferUNICODE[Size_of_buffer*2]:BYTE
local pGraph:QWORD
local pControl:QWORD
local pEvent:QWORD
local pWindow:QWORD

push rbp
mov ebp,esp
sub esp,(30h+4*8+sizeof Size_of_buffer*3+15)and(-16)
;AVIOpenFile-------------------------------------------------
;fill OPENFILENAME
push rbx ;<--- align 16 bytes

push rbx;lpTemplateName
push rbx;lpfnHook
push rbx;lCustData
push rbx;lpstrDefExt
push OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or \
OFN_EXPLORER or OFN_HIDEREADONLY;Flags & nFileOffset & nFileExtension
push rbx;lpstrTitle
push rbx;lpstrInitialDir
push rbx;nMaxFileTitle
push rbx;lpstrFileTitle
push Size_of_buffer;nMaxFile
lea eax,bufferANSI
push rax;lpstrFile
push rbx;nMaxCustFilter & nFilterIndex
push rbx;lpstrCustomFilter
mov eax,offset Filter
push rax;lpstrFilter
push IMAGE_BASE;hInstance
push rbx;hwndOwner
push sizeof OPENFILENAME;lStructSize
;----------------------------------------------------
mov ecx,esp;адрес OPENFILENAME
mov esi,ecx;
call GetOpenFileName
test eax,eax
jz Exit ; user clicks "Cancel"
inc count
mov qword ptr [rsp+28h],Size_of_buffer*2
lea eax,bufferUNICODE
mov [rsp+20h],rax
or r9d,-1
lea r8d,bufferANSI
xor edx,edx
xor ecx,ecx
call MultiByteToWideChar
;AVIInit -----------------------------------------
xor ecx,ecx
call CoInitialize
lea eax,pGraph
mov [rsp+20h],rax
mov r9d,offset ID_IGraphBuilder
mov r8d,CLSCTX_INPROC_SERVER
xor edx,edx
mov ecx,offset CLSID_FilterGraph
call CoCreateInstance
test eax,eax
jnz Exit ;Unable to create GraphBuilder
inc count
lea r8d,pControl
        mov edx,offset ID_IMediaControl
        mov rcx,pGraph
        mov eax,[rcx]
        call [rax].IMediaControlVtbl.QueryInterface;pMC->QueryInterface(IID_IMediaEventEx, (void **)&pME);
test eax,eax
jnz Exit ;Unable to get interface IMediaControl
inc count
lea r8d,pEvent
        mov edx,offset ID_IMediaEventEx
        mov rcx,pGraph
        mov eax,[rcx]
        call [rax].IMediaEventExVtbl.QueryInterface
test eax,eax
jnz Exit ;Unable to get interface IMediaEventEx
inc count
        lea r8d,pWindow
mov edx,offset ID_IVideoWindow
mov rcx,pGraph
mov eax,[rcx]
call [rax].IVideoWindowVtbl.QueryInterface;pMC->QueryInterface(IID_IVideoWindow, (void**)&pVW);
;AVIRenderFile----------------------------------------------
xor r8d,r8d
lea rdx,bufferUNICODE
mov rcx,pGraph
mov eax,[rcx]
call [rax].IGraphBuilderVtbl.RenderFile;pGB->RenderFile(FileNameW, NULL);
        test eax,eax
jnz Exit ;We can not open file
inc count
;AVIPlay-----------------------------------
mov rcx,pControl
        mov eax,[rcx]
        call [rax].IMediaControlVtbl.Run ;pMC->Run()
;------------------------------------------
lea r8d,pWindow
mov edx,INFINITE
        mov rcx,pEvent
        mov eax,[rcx]
        call [rax].IMediaEventExVtbl.WaitForCompletion
;AVIClose------------------------------------------
mov rcx,pControl
mov eax,[rcx]
call [rax].IMediaControlVtbl.Release
mov rcx,pEvent
mov eax,[rcx]
call [rax].IMediaEventExVtbl.Release
mov rcx,pGraph
mov eax,[rcx]
call [rax].IGraphBuilderVtbl.Release
call CoUninitialize
;---------------------------------------
Exit: xor r9d,r9d
xor r8d,r8d
mov eax,count
mov rdx,[hande+rax*8]
xor ecx,ecx
call MessageBox
xor ecx,ecx
        call ExitProcess
WinMain endp
;---------------------------------------
CLSID_FilterGraph GUID  <0E436EBB3h,524Fh,11CEh,{09Fh,053h,0,020h,0AFh,0Bh,0A7h,70h}>
;db "NB10"; dd 3031424Eh
ID_IGraphBuilder  GUID  <056A868A9h,0AD4h,11CEh,{0B0h,03Ah,0,20h,0AFh,0Bh,0A7h,70h}>;56A868A9h, 11CE0AD4h, 20003AB0h, 70A70BAFh
ID_IMediaControl  GUID  <056A868B1h,0AD4h,11CEh,{0B0h,03Ah,0,20h,0AFh,0Bh,0A7h,70h}>;56A868B1h, 11CE0AD4h, 20003AB0h, 70A70BAFh
ID_IMediaEventEx  GUID  <056A868B6h,0AD4h,11CEh,{0B0h,03Ah,0,20h,0AFh,0Bh,0A7h,70h}>;56A868C0h, 11CE0AD4h, 20003AB0h, 70A70BAFh
ID_IVideoWindow   GUID  <056A868B4h,0AD4h,11CEh,{0B0h,03Ah,0,20h,0AFh,0Bh,0A7h,70h}>
Filter db "Video files *.avi; *.qt; *.mov; *.mpg; *.mpeg; *.m1v; *.vob",0
                db " *.qt; *.mov; *.mpg; *.mpeg; *.m1v; *.vob; *.wmv",0,0
szAVIOpenError db "Unable to open the video file",0
szGoodbye db "Bye-bye!",0
hande dq str1,str2,str3,str4,szAVIOpenError,szGoodbye
str1 db "Do not select any media files!",0
str2 db "Unable to create GraphBuilder",0
str3 db "Unable to get interface IMediaControl",0
str4 db 'Unable to get interface IMEdiaEvent',0
count dd 0
end

Mikl__

#92
to All
Work on the project "Iczelion's Tutoral x64" supposed to work together with the exchange of opinions, bugs, suggestions. Judging by the number of downloads interested in the project about 20 people. I'm interested in whether the examples were run under Windows Seven or Eight or Windows XP x64. Which applications worked without error, and any errors and what these mistakes were concluded. Please do not be silent, feedback is very important for work on the project
Excuse me for my bad english

avcaballero

I've checked some of them in W7 64bits and seem to be ok. Thank you.

Mikl__


Mikl__

#95
Win x64 Tutorial #27: Tooltip Example
asm-fileinclude win64a.inc
IMAGE_BASE equ 400000h
IDD_MAINDIALOG equ 101
.code
WinMain proc
sub esp,38h
xor r8d,r8d
mov [rsp+20h],r8
mov r9d,offset dialog_procedure
mov edx,IDD_MAINDIALOG
mov ecx,IMAGE_BASE
call DialogBoxParam
xor ecx,ecx
call ExitProcess
        call InitCommonControls
WinMain endp
dialog_procedure proc hDlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
local ti:TOOLINFO
local rect:RECT
push rbp
mov ebp,esp
sub esp,(20h+sizeof TOOLINFO+sizeof RECT+15)and(-16)
mov hDlg,rcx

cmp edx,WM_INITDIALOG
je wmINITDIALOG
cmp edx,WM_CLOSE
je wmCLOSE
xor eax,eax
jmp wmBYE

wmINITDIALOG:xor ecx,ecx
mov esi,IMAGE_BASE
push rcx
push rsi
push rcx
push rcx
shl esi,9
push rsi
push rsi
push rsi
push rsi
mov r9d,TTS_ALWAYSTIP
xor r8d,r8d
mov edx,offset ToolTipsClassName
sub esp,20h
call CreateWindowEx
mov hwndTool,rax
mov ti.cbSize,sizeof TOOLINFO
mov ti.uFlags,TTF_SUBCLASS
mov rcx,hDlg
mov ti.hwnd,rcx
lea edx,rect
call GetWindowRect
mov ebx,3
@@: lea ecx,rect
mov r9d,ebx
mov r8,handle[rbx*8]
lea edx,ti
call SetDlgToolArea
dec ebx
jns @b

lea r8d,ti
mov edx,offset EnumChild
mov rcx,hDlg
call EnumChildWindows
jmp wmBYE
wmCLOSE:xor edx,edx
;mov rcx,hDlg
call EndDialog
wmBYE: leave
ret
dialog_procedure endp
EnumChild proc hwndChild:QWORD,lParam:QWORD
local buffer[256]:BYTE
push rbp
mov ebp,esp
sub esp,(20h+256+15)and(-16)
mov lParam,rdx
mov [rdx+TOOLINFO.uId],rcx;rcx=hwndChild
or [rdx+TOOLINFO.uFlags],TTF_IDISHWND
mov r8d,255
lea edx,buffer
;mov rcx,hwndChild
invoke GetWindowText
lea eax,buffer
mov r9,lParam
mov [r9+TOOLINFO.lpszText],rax
xor r8d,r8d
mov edx,TTM_ADDTOOL
mov rcx,hwndTool
call SendMessage
leave
retn
EnumChild endp
SetDlgToolArea proc lprect:QWORD,lpti:QWORD,lpText:QWORD,id:QWORD
push rbp
mov ebp,esp
sub esp,20h

jmp [handels+r9*8]
id_0: mov [rdx+TOOLINFO.Rect.left],0
mov [rdx+TOOLINFO.Rect.top],0
mov eax,[rcx+RECT.right]
sub eax,[rcx+RECT.left]
shr eax,1
mov [rdx+TOOLINFO.Rect.right],eax
mov eax,[rcx+RECT.bottom]
sub eax,[rcx+RECT.top]
shr eax,1
jmp wmBYE
id_1: mov eax,[rcx+RECT.right]
sub eax,[rcx+RECT.left]
shr eax,1
inc eax
mov [rdx+TOOLINFO.Rect.left],eax
mov [rdx+TOOLINFO.Rect.top],0
mov eax,[rcx+RECT.right]
sub eax,[rcx+RECT.left]
jmp a1
id_2: mov [rdx+TOOLINFO.Rect.left],0
mov eax,[rcx+RECT.bottom]
sub eax,[rcx+RECT.top]
shr eax,1
inc eax
mov [rdx+TOOLINFO.Rect.top],eax
mov eax,[rcx+RECT.right]
sub eax,[rcx+RECT.left]
shr eax,1
jmp a1
id_3: mov eax,[rcx+RECT.right]
sub eax,[rcx+RECT.left]
shr eax,1
inc eax
mov [rdx+TOOLINFO.Rect.left],eax
mov eax,[rcx+RECT.bottom]
sub eax,[rcx+RECT.top]
shr eax,1
inc eax
mov [rdx+TOOLINFO.Rect.top],eax
mov eax,[rcx+RECT.right]
sub eax,[rcx+RECT.left]
a1: mov [rdx+TOOLINFO.Rect.right],eax
mov eax,[rcx+RECT.bottom]
sub eax,[rcx+RECT.top]
wmBYE: mov [rdx+TOOLINFO.Rect.bottom],eax
mov [rdx+TOOLINFO.lpszText],r8;lpText
mov r9d,edx;lpti
xor r8d,r8d;NULL
mov edx,TTM_ADDTOOL
mov rcx,hwndTool
call SendMessage
leave
ret
handels dq id_0, id_1, id_2, id_3
SetDlgToolArea endp
;---------------------------------------------------------
ToolTipsClassName db "Tooltips_class32",0
MainDialogText1 db "This is the upper left area of the dialog",0
MainDialogText2 db "This is the upper right area of the dialog",0
MainDialogText3 db "This is the lower left area of the dialog",0
MainDialogText4 db "This is the lower right area of the dialog",0
handle dq MainDialogText1,MainDialogText2,MainDialogText3,MainDialogText4
hwndTool dq ?
end
rc-file#include "resource.h"
#define IDD_MAINDIALOG                  101
#define IDC_OK                          1000
#define IDC_EXIT                        1001
IDD_MAINDIALOG DIALOG DISCARDABLE  0, 0, 229, 96
STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION |
    WS_SYSMENU | DS_CENTER
CAPTION "Tooltip Example"
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "",  -1,0,  -4,115,51,WS_VISIBLE+BS_GROUPBOX
    PUSHBUTTON      "",  -1,114,43,115,53,WS_VISIBLE+BS_GROUPBOX
    PUSHBUTTON      "OK",IDC_OK,55,68,50,14
    PUSHBUTTON      "E&xit",IDC_EXIT,123,68,50,14
END

Mikl__

#96
Win x64 Tutorial #23-1: TrayIcon Demo
asm-fileinclude win64a.inc
include shell32.inc
includelib shell32.lib
IMAGE_BASE equ 400000h
WM_SHELLNOTIFY equ WM_USER+5
IDI_TRAY equ 0
IDM_RESTORE equ 1000
IDM_EXIT equ 1010
.code
WinMain proc
local msg:MSG
push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov ecx,offset FileName
call LoadCursorFromFile
        mov note.hIcon,rax
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 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 350
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
xor r8d,r8d
xor r9d,r9d
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
local pt:POINT
push rbp
mov ebp,esp
sub esp,(40h+sizeof POINT+15)and(-16)
mov hWnd,rcx
mov wParam,r8

cmp edx,WM_DESTROY
je wmDESTROY
        cmp edx,WM_CREATE
je wmCREATE
cmp edx,WM_SHELLNOTIFY
je wmSHELLNOTIFY
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_SIZE
je wmSIZE
leave
        jmp DefWindowProc
wmDESTROY:mov rcx,hPopupMenu
call DestroyMenu
xor ecx,ecx
        call ExitProcess
wmCREATE:mov note.hWnd,rcx;rcx=hWnd
call CreatePopupMenu
mov hPopupMenu,rax
mov r9d,offset RestoreString
mov r8d,IDM_RESTORE
xor edx,edx;mov edx,MF_STRING
mov ecx,eax;hPopupMenu
call AppendMenu
mov r9d,offset ExitString
mov r8d,IDM_EXIT
xor edx,edx;mov edx,MF_STRING
mov rcx,hPopupMenu
call AppendMenu
jmp wmBYE
wmSHELLNOTIFY:or r8,r8;.if wParam==IDI_TRAY
jne wmBYE
cmp r9,WM_RBUTTONDOWN
jne @f
wmSHELLNOTIFY_WM_RBUTTONDOWN:
lea ecx,pt
call GetCursorPos
mov rcx,hWnd
        call SetForegroundWindow
        mov [rsp+30h],rbx;0
mov rax,hWnd
        mov [rsp+28h],rax
mov [rsp+20h],rbx;0
mov r9d,pt.y
mov r8d,pt.x
mov edx,TPM_RIGHTALIGN
mov rcx,hPopupMenu
call TrackPopupMenu
xor r9d,r9d
xor r8d,r8d
mov edx,WM_NULL
mov rcx,hWnd
        call PostMessage
jmp wmBYE
@@: cmp r9,WM_LBUTTONDBLCLK
jne wmBYE
wmSHELLNOTIFY_WM_LBUTTONDBLCLK:
xor r9d,r9d;0
mov r8d,IDM_RESTORE
mov edx,WM_COMMAND
mov rcx,hWnd
call SendMessage
jmp wmBYE
wmCOMMAND:or r9,r9;.if lParam==0 message is not from control
jnz wmBYE
mov edx,offset note
mov ecx,NIM_DELETE
call Shell_NotifyIcon
        mov rcx,hWnd
cmp word ptr wParam,IDM_RESTORE
jne @f
wmCOMMAND_IDM_RESTORE:
mov edx,SW_RESTORE
call ShowWindow
jmp wmBYE
@@: call DestroyWindow
jmp wmBYE
wmSIZE: cmp r8d,SIZE_MINIMIZED;.if wParam==SIZE_MINIMIZED
        jnz wmBYE
xor edx,edx;mov edx,SW_HIDE
call ShowWindow
mov edx,offset note
xor ecx,ecx;mov ecx,NIM_ADD
call Shell_NotifyIcon
wmBYE: leave
retn
WndProc endp
;---------------------------------------
RestoreString db "&Restore",0
ExitString db "E&xit Program",0
FileName db "..\Images\Cursor.cur",0
note label NOTIFYICONDATA
dd sizeof NOTIFYICONDATA,0
dq ?
dd IDI_TRAY
dd NIF_ICON+NIF_MESSAGE+NIF_TIP
dd WM_SHELLNOTIFY,0
dq ?
ClassName db 'Win64 Iczelion''s lesson #23-1: TrayIcon Demo'
db 64-(lengthof ClassName) dup(0)
hPopupMenu dq ?
end

Mikl__

Win x64 Tutorial #23-2: TrayIcon Demo
asm-fileinclude win64a.inc
include shell32.inc
includelib shell32.lib
IMAGE_BASE equ 400000h
WM_SHELLNOTIFY equ WM_USER+5
IDI_TRAY equ 0
IDM_SHOWHIDE equ 100
IDM_EXIT equ 101
.code
WinMain proc
local msg:MSG
push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov ecx,offset FileName
call LoadCursorFromFile
        mov note.hIcon,rax
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 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 350
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
xor r8d,r8d
xor r9d,r9d
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
local pt:POINT
push rbp
mov ebp,esp
sub esp,(40h+sizeof POINT+15)and(-16)
mov hWnd,rcx
mov wParam,r8

cmp edx,WM_DESTROY
je wmDESTROY
        cmp edx,WM_CREATE
je wmCREATE
cmp edx,WM_SHELLNOTIFY
je wmSHELLNOTIFY
cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_SYSCOMMAND
je wmSYSCOMMAND
defwndproc:leave
        jmp DefWindowProc
wmDESTROY:mov edx,offset note
mov ecx,NIM_DELETE
call Shell_NotifyIcon
mov rcx,hPopupMenu
call DestroyMenu
xor ecx,ecx
        call ExitProcess
wmCOMMAND:or r9,r9;.if lParam==0 message is not from control
jnz wmBYE
cmp word ptr wParam,IDM_SHOWHIDE
je showhide
        cmp word ptr wParam,IDM_EXIT
        jne wmBYE
@@: call DestroyWindow
jmp wmBYE
wmSYSCOMMAND:cmp r8,SC_MINIMIZE; when user presses "minimize" button, main window
jne defwndproc; should be hidden
showhide:xor showflag,1
mov edx,showflag
lea edx,[rdx+rdx*4]
call ShowWindow
jmp wmBYE
wmSHELLNOTIFY:or r8,r8;.if wParam==IDI_TRAY WM_SHELLNOTIFY handler - here we handle actions
jne wmBYE; like clicking on our icon
cmp r9,WM_LBUTTONDOWN
je showhide
cmp r9,WM_RBUTTONDOWN
jne wmBYE
wmSHELLNOTIFY_WM_RBUTTONDOWN:
lea ecx,pt
call GetCursorPos
mov rcx,hWnd
        call SetForegroundWindow
        mov [rsp+30h],rbx;0
mov rax,hWnd
        mov [rsp+28h],rax
mov [rsp+20h],rbx;0
mov r9d,pt.y
mov r8d,pt.x
mov edx,TPM_RIGHTALIGN
mov rcx,hPopupMenu
call TrackPopupMenu
xor r9d,r9d
xor r8d,r8d
mov edx,WM_NULL
mov rcx,hWnd
        call PostMessage
jmp wmBYE

wmCREATE:mov note.hWnd,rcx;rcx=hWnd
mov edx,offset note
xor ecx,ecx;NIM_ADD=0
call Shell_NotifyIcon
call CreatePopupMenu
mov hPopupMenu,rax
mov r9d,offset szShowHide
mov r8d,IDM_SHOWHIDE
xor edx,edx;MF_STRING=0
mov ecx,eax;hPopupMenu
call AppendMenu
mov r9d,offset szExit
mov r8d,IDM_EXIT
xor edx,edx;MF_STRING=0
mov rcx,hPopupMenu
call AppendMenu
wmBYE: leave
retn
WndProc endp
;---------------------------------------
szShowHide db "&Show/Hide",0
szExit db "E&xit",0
FileName db "..\Images\Cursor.cur",0
showflag  dd 1   ;if main window is visible showflag=1
note label NOTIFYICONDATA
dd sizeof NOTIFYICONDATA,0
dq ?
dd IDI_TRAY
dd NIF_ICON+NIF_MESSAGE+NIF_TIP
dd WM_SHELLNOTIFY,0
dq ?
ClassName db 'Win64 Iczelion''s lesson #23-2: TrayIcon Demo'
db 64-(lengthof ClassName) dup(0)
hPopupMenu dq ?
end

Mikl__

Win x64 Tutorial #23-3: TrayIcon Animation
asm-fileinclude win64a.inc
include shell32.inc
includelib shell32.lib
IMAGE_BASE equ 400000h
WM_SHELLNOTIFY equ WM_USER+5
IDI_TRAY equ 0
IDM_SHOWHIDE equ 100
IDM_EXIT equ 101
.code
WinMain proc
local msg:MSG
push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov ecx,offset FileName
call LoadCursorFromFile
        mov note.hIcon,rax
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 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 408
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
xor r8d,r8d
xor r9d,r9d
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
local ps:PAINTSTRUCT
push rbp
mov ebp,esp
sub esp,(40h+sizeof PAINTSTRUCT+20h+15)and(-16)
mov hWnd,rcx

cmp edx,WM_DESTROY
je wmDESTROY
        cmp edx,WM_CREATE
je wmCREATE
cmp edx,WM_TIMER
je wmTIMER
cmp edx,WM_PAINT
je wmPAINT
defwndproc:leave
        jmp DefWindowProc
wmDESTROY:xor edx,edx
call KillTimer
mov edx,offset note
mov ecx,NIM_DELETE
call Shell_NotifyIcon
xor ecx,ecx
        call ExitProcess
wmPAINT:lea edx,ps
call BeginPaint
        mov r9,note.hIcon
mov r8d,100
mov edx,330
mov ecx,eax
call DrawIcon
        lea edx,ps
mov rcx,hWnd
call EndPaint
jmp wmBYE
wmTIMER:mov rdx,index
inc edx
cmp dl,11
jb @f
xor edx,edx
@@: mov index,rdx
mov rdx,[hIcon2+rdx*8]
mov note.hIcon,rdx
mov edx,offset note
mov ecx,NIM_MODIFY
call Shell_NotifyIcon
mov r8d,TRUE
        xor edx,edx
mov rcx,hWnd
        call InvalidateRect;send WM_PAINT
jmp wmBYE
wmCREATE:mov note.hWnd,rcx;rcx=hWnd
mov edx,offset note
xor ecx,ecx;NIM_ADD=0
call Shell_NotifyIcon
mov ebx,11
@@: mov qword ptr [rsp+28h],0
        mov r9d,16
mov [rsp+20h],r9
        mov r8d,IMAGE_ICON
        mov edx,ebx
        mov ecx,IMAGE_BASE
call LoadImage
mov hIcon2[rbx*8-8],rax
dec ebx
jnz @b
xor r9d,r9d
mov r8d,500
xor edx,edx
mov rcx,hWnd
call SetTimer
wmBYE: leave
retn
WndProc endp
;---------------------------------------
FileName db "..\Images\Cursor.cur",0
note label NOTIFYICONDATA
dd sizeof NOTIFYICONDATA,0
dq ?
dd IDI_TRAY
dd NIF_ICON+NIF_MESSAGE+NIF_TIP
dd WM_SHELLNOTIFY,0
dq ?
ClassName db 'Win64 Iczelion''s lesson #23-2: TrayIcon Animation'
db 64-(lengthof ClassName) dup(0)
index dq 0
hIcon2 dq 12 dup(?)
end
rc-file#define icon1  1
#define icon2  2
#define icon3  3
#define icon4  4
#define icon5  5
#define icon6  6
#define icon7  7
#define icon8  8
#define icon9  9
#define icon10  10
#define icon11  11

icon1 ICON "..\\Images\\01.ico"
icon2 ICON "..\\Images\\02.ico"
icon3 ICON "..\\Images\\03.ico"
icon4 ICON "..\\Images\\04.ico"
icon5 ICON "..\\Images\\05.ico"
icon6 ICON "..\\Images\\06.ico"
icon7 ICON "..\\Images\\07.ico"
icon8 ICON "..\\Images\\08.ico"
icon9 ICON "..\\Images\\09.ico"
icon10 ICON "..\\Images\\10.ico"
icon11 ICON "..\\Images\\11.ico"

Mikl__

#99
Win x64 Tutorial #5a: few ways of Text output
asm-fileinclude win64a.inc
include gdi32.inc
includelib gdi32.lib
IMAGE_BASE equ 400000h

.code
WinMain proc
local msg:MSG
local WinDim:RECT
local hwnd:QWORD
local tci:TCITEMA

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

call InitCommonControls

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 ;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

lea edx,WinDim
mov ecx,eax
call GetClientRect
push rbx
push IMAGE_BASE
push rbx
push hwnd
mov eax,WinDim.bottom
push rax
mov eax,WinDim.right
push rax
push rbx
push rbx
mov r9d,WS_VISIBLE or WS_TABSTOP or WS_CHILD
mov r8d,offset NullString
mov edx,offset aSysTabControl32
mov ecx,WS_EX_RIGHTSCROLLBAR
sub esp,20h
call CreateWindowEx
mov hTabWnd,rax

        push rbx
push IMAGE_BASE
push rbx
push rax
push 256
push 512
push 180
push 120
mov r9d,SS_LEFT or WS_CHILD
mov r8d,offset expTxt0
mov edx,offset aStatic
xor ecx,ecx
sub esp,20h
call CreateWindowEx
mov hStaticText,rax
mov tci.imask,TCIF_TEXT
        or  tci.iImage, -1

@@:     mov rax,handle1[rbx*8]
mov tci.pszText,rax
mov tci.lParam,rbx
neg rax
add rax,handle1[rbx*8+8]
mov tci.cchTextMax,eax
        lea r9d,tci
mov r8d,ebx
mov edx,TCM_INSERTITEMA
mov rcx,hTabWnd
call SendMessage
inc ebx
        cmp bl,8
        jb @b
        xor ebx,ebx

; mov pptxt.x,0
; mov pptxt.y,40
; mov pptxt.n,expTxt7-expTxt6
; mov eax,offset expTxt6
; mov pptxt.lpStr,rax
; mov pptxt.uiFlags,ETO_OPAQUE
; mov pptxt.icl.left,0
; mov pptxt.icl.top,0
; mov pptxt.icl.right,100
; mov pptxt.icl.bottom,200
; mov pptxt.pdx,0

    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
xor r8d,r8d
xor r9d,r9d
        call GetMessage
mov ecx,edi
        call DispatchMessage
        jmp @b
WinMain endp
WndProc proc hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
local expRect:RECT
local ps:PAINTSTRUCT
local hdc:QWORD

        push rbp
mov ebp,esp
sub esp,(48h+sizeof PAINTSTRUCT+sizeof RECT+15)and(-16)
mov hWnd,rcx
mov wParam,r8
mov lParam,r9

cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_NOTIFY
je wmNOTIFY
        cmp  edx,WM_PAINT
        je   wmPAINT
cmp edx,WM_CTLCOLORSTATIC;WM_CTLCOLORSTATIC=138h
je wmCTLCOLORSTATIC
wmDEFAULT:leave
        jmp DefWindowProc
wmDESTROY: xor ecx,ecx
        call ExitProcess
wmCTLCOLORSTATIC:mov edx,0DEEBEFh
mov ecx,r8d
call SetBkColor
mov ecx,NULL_BRUSH
call GetStockObject
jmp wmBYE
wmNOTIFY:cmp [r9+NMHDR._code],TCN_SELCHANGE
jne wmDEFAULT
xor r9d,r9d
xor r8d,r8d
mov edx,TCM_GETCURSEL
        mov rcx,hTabWnd
call SendMessage
mov _Page,eax
        mov r9d,offset ClassName
xor r8d,r8d
mov edx,WM_SETTEXT
mov rcx,hWnd
call SendMessage
mov edx,SW_HIDE
mov rcx,hStaticText
call ShowWindow
; xor r8d,r8d
; xor edx,edx
; mov rcx,hWnd
; call InvalidateRect
; jmp wmBYE
wmPAINT:lea edx,expRect
mov rcx,hTabWnd
call GetClientRect
add expRect.bottom,400
lea edx,ps
mov rcx,hWnd
call BeginPaint
        lea edx,expRect
        mov rcx,hTabWnd
call GetClientRect
add expRect.top,40
        mov rcx,hTabWnd
call GetDC
mov hdc,rax
mov r8d,COLOR_BTNFACE+1
lea edx,expRect
mov ecx,eax
call FillRect
mov edx,TRANSPARENT
mov rcx,hdc
call SetBkMode

mov eax,_Page
jmp [handle+rax*8];Tab selection
ExtTextOut1::mov qword ptr [rsp+38h],0;rbx
        mov qword ptr [rsp+30h],lengthof expTxt2-1
        mov eax,offset expTxt2
        mov [rsp+28h],rax
        lea eax,expRect
        mov [rsp+20h],rax
        xor r9d,r9d
        mov r8d,40
mov edx,40
        mov rcx,hdc
call ExtTextOut
       jmp a1
STATICText::mov edx,SW_SHOW
        mov rcx,hStaticText
    call ShowWindow
       jmp a1
DrawTextEx1::
mov qword ptr [rsp+28h],0;rbx
        mov qword ptr [rsp+20h],DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or \
DT_END_ELLIPSIS or DT_MODIFYSTRING or DT_WORD_ELLIPSIS
        lea r9,expRect
        or r8,-1
        mov edx,offset expTxt5
mov rcx,hdc
call DrawTextEx
       jmp a1
PolyTextOut1::mov r8d,6
mov edx,offset pptxt
mov rcx,hdc
call PolyTextOut
jmp a1
TextOut1::mov qword ptr [rsp+20h],lengthof expTxt3A-1
mov r9d,offset expTxt3A
mov r8d,100
mov edx,40
mov rcx,hdc
call TextOut
        mov qword ptr [rsp+20h],lengthof expTxt3B-1
mov r9d,offset expTxt3B
mov r8d,120
mov edx,40
mov rcx,hdc
call TextOut
        mov qword ptr [rsp+20h],lengthof expTxt3C-1
mov r9d,offset expTxt3C
mov r8d,140
mov edx,40
mov rcx,hdc
call TextOut
mov qword ptr [rsp+20h],lengthof expTxt3D-1
mov r9d,offset expTxt3D
mov r8d,160
mov edx,40
mov rcx,hdc
call TextOut
mov qword ptr [rsp+20h],lengthof expTxt3E-1
mov r9d,offset expTxt3E
mov r8d,180
mov edx,40
mov rcx,hdc
call TextOut
jmp a1
DrawText1::mov qword ptr [rsp+20h],DT_WORDBREAK
        lea r9d,expRect
        or r8,-1
        mov edx,offset expTxt1
        mov rcx,hdc
call DrawText
       jmp a1
TabbedTextOut1::mov qword ptr [rsp+38h],0;rbx
        mov qword ptr [rsp+30h],0;rbx
        mov qword ptr [rsp+28h],0;rbx
        or qword ptr [rsp+20h],-1
        mov r9d,offset expTxt4
        mov r8d,40
        mov edx,40
        mov rcx,hdc
call TabbedTextOut
jmp a1
SetText1::mov r9d,offset expTxt7
xor r8d,r8d
mov edx,WM_SETTEXT
mov rcx,hWnd
call SendMessage
a1: mov rdx,hdc
mov rcx,hTabWnd
call ReleaseDC
lea edx,ps
mov rcx,hWnd
call EndPaint
wmBYE: leave
ret
WndProc endp
;---------------------------------------
ClassName db 'Win64 Iczelion''s lesson #5a: few ways of Text output'
NullString db 0
hTabWnd dq ?
aSysTabControl32 db "SysTabControl32",0
tab0      db "Static",0
tab1      db "DrawTextEx",0
tab2         db "TextOut",0
tab3      db "TabbedTextOut",0
tab4      db "DrawText",0
tab5         db "PolyTextOut",0
tab6      db "ExtTextOut",0
tab7      db "SetText",0
handle1 dq tab0,tab1,tab2,tab3,tab4,tab5,tab6,tab7,handle1
handle  dq STATICText,DrawTextEx1,TextOut1,TabbedTextOut1,DrawText1
dq PolyTextOut1,ExtTextOut1,SetText1
;---------------------------------------------------------------------------------------------
expTxt0 db '1) Text output using STATIC ', 10,' Understands newlines and tabs line ', 10
       db 'does not require processing WM_PAINT messages',0
;---------------------------------------------------------------------------------------------
expTxt1 db   '5) To display multiple lines of text within the boundaries of a given rectangular area using DrawText API ', 10,' description ', 10
db 'function DrawText (DC: HDC; Str: PChar; Count: Integer; var Rect: TRect; Format: Word): Integer;', 10
db 'Draws fopmatipovanny text. Type fopmatipovaniya indicated PARAMETERS Format. If not explicitly dt_NoClip, ', 10
db 'text vypezaetsya in ogpanichivayuschy ppyamougolnik.', 10, 'PARAMETERS:', 10
db 'DC: symbols are device context.', 10, 'Str: you draw with string. If Count = -1, it must end with a null character. ', 10
db 'Rect: TRect, ogpanichivayuschy text.', 10, 'Format: One or more constants: dt_Bottom, dt_CalcRect, dt_Center, dt_ExpandTabs,', 10
db 'dt_ExternalLeading, dt_Left, dt_NoClip, dt_NoPrefix, dt_Right, dt_SingleLine, dt_TabStop, dt_Top, dt_VCenter and', 10
db 'dt_WordBreak. See. Section "Flags fopmatipovaniya text DURING pisovanii, dt_" in Chapter 1. ', 10
db 'Return value: The height of the text.', 10, 'function is in a file user32.dll',0
;---------------------------------------------------------------------------------------------
expTxt2 db   '7) ExtTextOut function allows you to output text string '
db 'in the specified rectangle using the current font and manages Background mode',0;разобраться
;---------------------------------------------------------------------------------------------
expTxt3A db '3) Text output using TextOut. Function displays the text ',0
expTxt3B db 'in the given coordinates, which are always given with respect',0
expTxt3C db 'to the (upper left corner) of the window. Does not understand hyphens and',0
expTxt3D db 'tabs line. When redrawing the workspace required to provide processing',0
expTxt3E db 'WM_PAINT. To display these lines TextOut function calls five times!',0
;---------------------------------------------------------------------------------------------
expTxt4 db   'To create a multi-column table with aligned columns of text, use ',9,' TabbedTextOut API',0
;---------------------------------------------------------------------------------------------
expTxt5   db   '2) The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth). '
db ' To specify additional formatting options, use the DrawTextEx function.',0
;---------------------------------------------------------------------------------------------
expTxt6a db   '6) API draws several strings using the font and text colors currently selected in the specified device context. '
expTxt6b db 'BOOL PolyTextOut('
expTxt6c db '    HDC hdc,    // handle of device context'
expTxt6d db '    CONST POLYTEXT *pptxt,      // address of array of structures that identify strings'
expTxt6e db '    int cStrings        // number of structures in array'
expTxt6f db '   );'
;---------------------------------------------------------------------------------------------
expTxt7   db   'Text output in the window title through SendMessage',0
expTxt8   db 'Text output using PolyTextOut API',0
pptxt POLYTEXT <0,40,expTxt6b-expTxt6a,expTxt6a,ETO_OPAQUE,{0,0,100,200},0>
      POLYTEXT <0,60,expTxt6c-expTxt6b,expTxt6b,ETO_OPAQUE,{0,0,100,200},0>
      POLYTEXT <0,80,expTxt6d-expTxt6c,expTxt6c,ETO_OPAQUE,{0,0,100,200},0>
      POLYTEXT <0,100,expTxt6e-expTxt6d,expTxt6d,ETO_OPAQUE,{0,0,100,200},0>
      POLYTEXT <0,120,expTxt6f-expTxt6e,expTxt6e,ETO_OPAQUE,{0,0,100,200},0>
      POLYTEXT <0,140,expTxt7-expTxt6f,expTxt6f,ETO_OPAQUE,{0,0,100,200},0>
aStatic db 'STATIC',0
hStaticText dq ?
_Page dd ?
end

Mikl__

#100
Win x64 Tutorial #35: IczEdit version 3.0
rc-file#include "c:\\masm64\\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
wordfile.txt[ASSEMBLY]
C1=aaa aad aam aas adc add and arpl bound bsf bsr bswap bt btc btr bts call cbw cdq clc cld cli clts cmc cmov cmp cmps cmpsb cmpsd cmpsw cmpxchg cmpxchg8b cpuid cwd cwde daa das dec div emms enter esc fcmov fcomi fwait hlt idiv imul in inc ins insb insd insw int into invd invlpg iret iretd ja jae jb jbe jc jcxz je jecxz jg jge jl jle jmp jna jnae jnb jnbe jnc jne jng jnge jnl jnle jno jnp jns jnz jo jp jpe jpo js jz lahf lar lds lea leave les lfs lgdt lgs lidt lldt lmsw lock lods lodsb lodsd lodsw loop loope loopne loopnz loopz lsl lss ltr mov movd movq movs movsb movsd movsw movsx movzx msw mul neg nop not or out outs outsb outsd outsw packsswb packssdw paddb paddw paddd paddsb paddsw paddusb paddusw pand pandn
C2=%out .186 .286 .286c .286p .287 .386 .386p .387 .8086 .8087 .alpha .seq .code .const .cref .data .data? .err .err1 .err2 .errb .errdef .errdif .erre .fardata .fardata? .lall .lfcond .list .model .msfloat .radix .sall .sfcond .stack .type .xall .xcref .xlist @curseg @filename @code @codesize @datasize @const @data @data? @fardata @fardata? @stack align assume at byte comm comment common compact d db dd df dosseg dup fq dt dw dword else end endif endm endp ends eq equ even exitm extrn far ge group h high huge ifdef include includelib irp irpc label large le length low local lt macro mask medium memory name near offset org page para proc public purge q record rept seg segment shl short size shr small stack struct subttl this tiny title type use16 use32 width word xor
C3=ah al ax bh bl bp bx ch cl cs cx dh di dl ds dx eax ebx ecx edi edx esi es ip si sp
C4=.if .else .elseif .endif .while .endw
C5=setng setnge setnl setnle setno setnp setns setnz seto setp setpe setpo sets setz sgdt  shld shrd sidt sldt smsw stc std sti stos stosb stosd stosw str sub test verr verw wbinvd wrmsr xadd xchg xlat xlatb invoke addr
C6=pcmpeqb pcmpeqw pcmpeqd pcmpgtb pcmpgtw pcmpgtd pmulhw pmullw pmaddwd pop popa popad popf popfd por psllw pslld psllq psrlw psrld psrlq psraw psrad psubb psubw psubd psubsb psubsw psubusb psubusw punpckhbw punpckhwd punpckhdq punpcklbw punpcklwd punpckldq push pusha pushad pushf pushfd rcl rcr rdmsr rdpmc rdtsc rep repe repne repnz repz ret retf retn rol ror rsm sahf sal sar sbb  scas scasb scasd scasw setae setb setbe setc sete setg setge setl setle setna setnae setnb setnc setne
C7=
C8=
C9=
C10=
asm-file first partinclude win64a.inc
include comdlg32.inc
include gdi32.inc
includelib gdi32.lib
includelib comdlg32.lib
IMAGE_BASE equ 400000h
WORDINFO struct
WordLen dd ? ; the length of the word: used as a quick comparison
pszWord dd ? ; pointer to the word
pColor dd ? ; point to the dword that contains the color used to hilite the word
NextLink dd ? ; point to the next WORDINFO structure
WORDINFO ends

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 ClassName
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
invoke GetProcessHeap
mov hMainHeap,rax
;===========================================================
; Load the words to be hilighted
;===========================================================
call FillHiliteInfo
xor ebx,ebx
mov esi,IMAGE_BASE
mov eax,10027h
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
    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 r8d,edi ;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
mov edx,offset RichEditClass
mov ecx,WS_EX_CLIENTEDGE
sub esp,20h
call CreateWindowEx
mov hwndRichEdit,rax
;=======================================================
; Check the richedit version
;=======================================================
mov r9d,TO_SIMPLELINEBREAK
mov r8d,TO_SIMPLELINEBREAK
mov edx,EM_SETTYPOGRAPHYOPTIONS
mov rcx,hwndRichEdit
call SendMessage
mov r9d,1
mov r8d,1
mov edx,EM_GETTYPOGRAPHYOPTIONS
mov rcx,hwndRichEdit
call SendMessage
or eax,eax; means this message is not processed
        mov RichEditVersion,2
je @f
inc RichEditVersion
;=============================================================================
; Make it emulate system edit control so the text color update doesn't  take very long
;=============================================================================
mov r9d,SES_EMULATESYSEDIT
mov r8d,SES_EMULATESYSEDIT
mov edx,EM_SETEDITSTYLE
mov rcx,hwndRichEdit
call SendMessage
;=======================================================
; Subclass the richedit control
;=======================================================
@@: mov r8d,offset NewRichEditProc
mov edx,GWL_WNDPROC
mov rcx,hwndRichEdit
call SetWindowLongPtr
mov OldWndProc,rax
;=============================================================
; Set the text limit. The default is 64K
;=============================================================
mov r9d,ebx;0
or r8d,-1
mov edx,EM_LIMITTEXT
mov rcx,hwndRichEdit
call SendMessage

Mikl__

asm-file second part;=============================================================
; Set the default text/background color
;=============================================================
call SetColor
mov r9d,ebx;0
mov r8d,ebx;FALSE
mov edx,EM_SETMODIFY
mov rcx,hwndRichEdit
call SendMessage
;============================================================
; set event mask
;============================================================
mov r9d,ENM_MOUSEEVENTS
xor r8d,r8d
mov edx,EM_SETEVENTMASK
mov rcx,hwndRichEdit
call SendMessage

mov r9d,ebx;0
mov r8d,ebx;0
mov edx,EM_EMPTYUNDOBUFFER
mov rcx,hwndRichEdit
call SendMessage

mov edx,IDR_MAINACCEL
mov ecx,IMAGE_BASE
call LoadAccelerators
mov hAccel,rax
    lea edi,msg
@@:     mov ecx,edi
xor edx,edx
mov r8d,ebx
mov r9d,ebx
        call GetMessage
mov edx,edi
mov rcx,hSearch
call IsDialogMessage
or eax,eax;.if eax==FALSE
jnz @b
mov r9d,edi
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 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 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
ret
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
;mov rcx,hWnd
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
        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
;==================================================================================
; Save the modify state of the richedit control because changing the text color changes the
; modify state of the richedit control.
;==================================================================================
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 @f
wmCLOSE:xor edx,edx
mov rcx,hWnd
call EndDialog
wmBYE: mov eax,TRUE
@@: leave
retn
handle dq BACKCOLORBOX,TEXTCOLORBOX,OK,CANCEL
OptionProc endp

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
db 48h;mov eax,offset FindBuffer
dd 202444C7h,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
retn
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 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,IDC_CANCEL
jnz @f
xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
call SendMessage
jmp wmBYE
@@: cmp ax,IDC_OK
jnz wmBYE
xor r9d,r9d;FALSE
xor r8d,r8d
mov edx,IDC_LINENO
mov rcx,hWnd
call GetDlgItemInt
mov LineNo,rax
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
mov r9,rax
mov r8,rax
mov edx,EM_SETSEL
mov rcx,hwndRichEdit
call SendMessage
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
; 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
asm-file third part[code];----------------------------------------------------------
;функция ParseBuffer принимает буфер, содержащий слова, которые должны быть
;выделены, парсит их на отдельные слова и сохраняет каждое из них в массиве
;структур WORDINFO, к которому можно получить доступ из ASMSyntaxArray.
;---------------------------------------------------------------------
ParseBuffer proc hHeap:QWORD,pBuffer:QWORD, nSize:QWORD, ArrayOffset:QWORD,pArray:QWORD
LOCAL buffer[128]:BYTE
LOCAL InProgress:QWORD
LOCAL old_rdi:QWORD
LOCAL old_rsi:QWORD
LOCAL old_rcx:QWORD

push rbp
mov ebp,esp
sub esp,(20h+128+4*8+15)and(-16)

mov hHeap,rcx
mov pBuffer,rdx
mov nSize,r8
mov ArrayOffset,r9
mov old_rdi,rdi
mov old_rsi,rsi

mov InProgress,FALSE
;InProgress - флаг, который дает возможность определить, начался ли процесс
;сканирования. Если значение равно FALSE, тогда edi указывает на буфер,
;который будет содержать слово, взятое нами из списка слов. esi указывает на
;строку-список слов. Чтобы упростить поиск, приводим все символы к нижнему
;регистру.
lea edi,buffer
mov rsi,pBuffer
mov ecx,esi
call CharLower
mov rcx,nSize
jrcxz @f
;Сканируем весь список слов в буфере, ориентируясь по пробелам или табуляции,
;по которым определяем конец или начало слова. Если оказывается, что байт не
;является пробелом, тогда копируем его в буфер, где создается слово, а затем
;продолжаем поиск.
SearchLoop:cmp byte ptr [rsi]," "
je EndOfWord
cmp byte ptr [rsi],9 ; tab
je EndOfWord
mov InProgress,TRUE
movsb;mov al,byte ptr [rsi]
dec esi
SkipIt: inc esi
loop SearchLoop
@@: jmp Finished
EndOfWord:cmp InProgress,TRUE
jne SkipIt
WordFound:mov byte ptr [rdi],0
mov old_rcx,rcx
;========================================================
; store the word in a WORDINFO structure
;========================================================
mov r8d,sizeof WORDINFO
mov edx,HEAP_ZERO_MEMORY
mov rcx,hHeap
call HeapAlloc
mov edi,eax
lea ecx,buffer
call lstrlen
mov [rdi+WORDINFO.WordLen],eax
        mov rcx,ArrayOffset
mov [rdi+WORDINFO.pColor],ecx
inc eax
mov r8d,eax
mov edx,HEAP_ZERO_MEMORY
mov rcx,hHeap
call HeapAlloc
        lea edx,buffer
mov [rdi+WORDINFO.pszWord],eax
mov ecx,eax
call lstrcpy
mov rax,pArray
movzx rdx,byte ptr buffer
lea eax,[rax+4*rdx]
cmp dword ptr [rax],0
jz @f
mov ecx,dword ptr [rax]
mov [rdi+WORDINFO.NextLink],ecx
@@: mov dword ptr [rax],edi
mov rcx,old_rcx
lea edi,buffer
mov InProgress,FALSE
jmp SkipIt
Finished:cmp InProgress,TRUE
jnz a2
;========================================================
; store the word in a WORDINFO structure
;========================================================
mov r8d,sizeof WORDINFO
mov edx,HEAP_ZERO_MEMORY
mov rcx,hHeap
call HeapAlloc
mov edi,eax
lea ecx,buffer
call lstrlen
mov [rdi+WORDINFO.WordLen],eax
mov rcx,ArrayOffset
mov [rdi+WORDINFO.pColor],ecx
inc eax
mov r8d,eax
mov edx,HEAP_ZERO_MEMORY
mov rcx,hHeap
call HeapAlloc
mov [rdi+WORDINFO.pszWord],eax
lea esi,buffer
mov ecx,eax
mov edx,esi
call lstrcpy
mov rax,pArray
movzx edx,byte ptr [esi];buffer
lea eax,[rax+rdx*4]
cmp dword ptr [rax],0
jz @f
mov ecx,dword ptr [rax]
mov [rdi+WORDINFO.NextLink],ecx
@@: mov dword ptr [rax],edi
a2: mov rsi,old_rsi
mov rdi,old_rdi
leave
retn
ParseBuffer endp
FillHiliteInfo proc
LOCAL buffer[1024]:BYTE
local CKeyIndex:QWORD
local ASMColorArrayIndex:QWORD
LOCAL BlockSize:QWORD
LOCAL pTemp:QWORD
LOCAL old_rdi:QWORD
LOCAL temp1:QWORD
LOCAL temp2:QWORD

push rbp
mov ebp,esp
sub esp,(30h+1024+5*8+15)and(-16)
mov old_rdi,rdi
;===================================================================
; Zero out the array
;===================================================================
mov edx,sizeof ASMSyntaxArray
mov ecx,offset ASMSyntaxArray
call RtlZeroMemory
;===================================================================
; obtaining the path of this program instance
;===================================================================
mov r8d,sizeof buffer
lea edi,buffer
mov edx,edi
mov ecx,IMAGE_BASE
call GetModuleFileName
mov temp1,rdi
mov ecx,eax
dec ecx
add edi,ecx
std
mov al,"\"
repne scasb
cld
add edi,2
mov temp2,rsi
mov esi,offset WordFileName;mov byte ptr [rdi],0
mov ecx,sizeof WordFileName;mov edx,offset WordFileName
rep movsb;lea ecx,buffer
mov rsi,temp2;call lstrcat
        mov rdi,temp1;
;==================================================================
; Check whether the file exists
;==================================================================
mov ecx,edi;lea ecx,buffer
call GetFileAttributes
inc eax;.if eax!=-1
jz a0

Mikl__

#102
; allocate a block of memory from the heap for the strings
mov BlockSize,1024*10
mov r8,BlockSize
xor edx,edx
mov rcx,hMainHeap
call HeapAlloc
mov pTemp,rax
mov eax,offset C1Key
mov CKeyIndex,rax
mov eax,offset ASMColorArray
        mov ASMColorArrayIndex,rax
@@:     mov [rsp+28h],rdi;rax
mov rax,BlockSize
mov [rsp+20h],rax
mov r9,pTemp
        mov r8d,offset ZeroString
mov rdx,CKeyIndex
mov ecx,offset ASMSection
call GetPrivateProfileString
or eax,eax;.if eax!=0
jz @f
inc eax
cmp rax,BlockSize ; the buffer is too small
jnz a2
add BlockSize,1024*10
mov r9,BlockSize
mov r8,pTemp
xor edx,edx
mov rcx,hMainHeap
call HeapReAlloc
mov pTemp,rax
jmp @B
a2: mov ecx,10;offset ASMSyntaxArray
a4:     mov temp1,rcx
db 48h;mov ecx,offset ASMSyntaxArray
dd 202444C7h,ASMSyntaxArray;mov [rsp+20h],rcx
mov r9,ASMColorArrayIndex
mov r8d,eax
mov rdx,pTemp
mov rcx,hMainHeap
call ParseBuffer
add CKeyIndex,3
add ASMColorArrayIndex,4
@@:     mov [rsp+28],rdi
mov rax,BlockSize
mov [rsp+20h],rax
mov r9,pTemp
mov r8d,offset ZeroString
mov rdx,CKeyIndex
mov ecx,offset ASMSection
call GetPrivateProfileString
or eax,eax;.if eax!=0
jz a3
inc eax
cmp rax,BlockSize ; the buffer is too small
jnz a3
add BlockSize,1024*10
mov r9,BlockSize
mov r8,pTemp
xor edx,edx
mov rcx,hMainHeap
call HeapReAlloc
mov pTemp,rax
jmp @B
a3: mov rcx,temp1
dec ecx;loop a4
jnz a4
mov r8,pTemp
xor edx,edx
mov rcx,hMainHeap
call HeapFree
a0: mov rdi,old_rdi
leave
ret
FillHiliteInfo endp
NewRichEditProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
LOCAL hdc:QWORD
LOCAL hOldFont:QWORD
LOCAL FirstChar:QWORD
LOCAL rect:RECT
LOCAL txtrange:TEXTRANGE
LOCAL buffer[1024*10]:BYTE
LOCAL hRgn:QWORD
LOCAL hOldRgn:QWORD
LOCAL RealRect:RECT
LOCAL pString:QWORD
LOCAL BufferSize:QWORD
LOCAL pt:POINT

push rbp
mov ebp,esp
sub esp,(30h+8*7+2*(sizeof RECT)+sizeof TEXTRANGE+\
sizeof POINT+1024*10+15)and(-16)
mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
mov lParam,r9

cmp edx,WM_PAINT
je wmPAINT
cmp edx,WM_CLOSE
je wmCLOSE
wmDEFAULT:mov [rsp+20h],r9
mov r9,r8
mov r8d,edx
mov edx,ecx
mov rcx,OldWndProc
call CallWindowProc
leave
retn

wmPAINT:push rdi
push rsi
sub esp,30h
mov rcx,hWnd
call HideCaret
mov rax,lParam
mov [rsp+20h],rax
mov r9,wParam
mov r8,uMsg
mov rdx,hWnd
mov rcx,OldWndProc
call CallWindowProc
add esp,10h
mov edx,eax
mov rcx,hWnd
call GetDC
mov hdc,rax
mov edx,TRANSPARENT
mov ecx,eax
call SetBkMode
; Do syntax hiliting here!
        lea edi,rect
mov r9d,edi;lea r9d,rect
xor r8d,r8d
mov edx,EM_GETRECT
mov rcx,hWnd
call SendMessage
mov r9d,edi;lea r9d,rect
xor r8d,r8d
mov edx,EM_CHARFROMPOS
mov rcx,hWnd
call SendMessage
; obtain the line number
xor r9d,r9d
mov r8d,eax
mov edx,EM_LINEFROMCHAR
mov rcx,hWnd
call SendMessage
xor r9d,r9d
mov r8d,eax
mov edx,EM_LINEINDEX
mov rcx,hWnd
call SendMessage
mov txtrange.chrg.cpMin,eax
mov FirstChar,rax
lea r9d,rect.right
xor r8d,r8d
mov edx,EM_CHARFROMPOS
mov rcx,hWnd
call SendMessage
mov txtrange.chrg.cpMax,eax
mov esi,edi
lea edi,RealRect
movsq;
;mov eax,rect.left
;mov RealRect.left,eax
;mov eax, rect.top
;mov RealRect.top,eax
movsq;
;mov eax, rect.right
;mov RealRect.right,eax
;mov eax,rect.bottom
;mov RealRect.bottom,eax
mov r9d,RealRect.bottom
mov r8d,RealRect.right
mov edx,RealRect.top
mov ecx,RealRect.left
call CreateRectRgn
mov hRgn,rax
mov edx,eax;hRgn
mov rcx,hdc
call SelectObject
mov hOldRgn,rax
mov edx,CommentColor
mov rcx,hdc
call SetTextColor
; Get the visible text into buffer
lea eax,buffer
mov txtrange.lpstrText,rax
lea r9d,txtrange
xor r8d,r8d
mov edx,EM_GETTEXTRANGE
mov rcx,hWnd
call SendMessage
add esp,20h
mov esi,eax ; esi == size of the text
cmp esi,0
jbe @0
mov BufferSize,rax
; Search for comments first
        mov edi,offset ASMSyntaxArray
push rdi
push rbx
lea edi,buffer
mov edx,edi ; used as the reference point
mov ecx,esi
mov al,";"
ScanMore:
repne scasb
jne NoMoreHit
NextSkip: dec edi
inc ecx
mov pString,rdi
mov ebx,edi
sub ebx,edx
add rbx,FirstChar
mov txtrange.chrg.cpMin,ebx
; search the end of line or the end of buffer
push rax
mov al,0Dh
repne scasb
pop rax
HiliteTheComment: cmp ecx,0
jbe @1
mov byte ptr [rdi-1],0
@1: mov ebx,edi
sub ebx,edx
add rbx,FirstChar
mov txtrange.chrg.cpMax,ebx
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
; Now we must search the range for the tabs
mov rdi,pString
mov esi,txtrange.chrg.cpMax
sub esi,txtrange.chrg.cpMin; esi contains the length of the buffer
mov eax,esi
        push rdi
push rdi
@3: cmp byte ptr [rdi],9
jnz @4
mov byte ptr [rdi],0
@4: inc edi
dec eax
jnz @3
pop rdi
pop rdi
jmp @5; .while esi>0
@6: cmp byte ptr [rdi],0
jz @7
sub esp,20h
mov ecx,edi
call lstrlen
        add esp,20h
push rax
        push rax
mov ecx,edi
lea edx,buffer
sub ecx,edx
add rcx,FirstChar
cmp RichEditVersion,3
jnz @8
sub esp,20h
mov r9d,ecx
lea r8d,rect
mov edx,EM_POSFROMCHAR
mov rcx,hWnd
call SendMessage
        add esp,20h
jmp @9; .else
@8: sub esp,20h
xor r9d,r9d
mov r8d,ecx
mov edx,EM_POSFROMCHAR
mov rcx,hWnd
call SendMessage
        add esp,20h
movzx ecx,ax
mov rect.left,ecx
shr eax,16
mov rect.top,eax
@9:     sub esp,30h
mov qword ptr [rsp+20h],0
lea r9d,rect
or r8,-1
mov edx,edi
mov rcx,hdc
call DrawText
        add esp,30h
pop rax
        pop rax
add edi,eax
sub esi,eax
jmp @5; .else
@7: inc edi
dec esi
@5: cmp esi,0
ja @6
mov edx,txtrange.chrg.cpMax
sub edx,txtrange.chrg.cpMin
sub esp,20h
mov rcx,pString
call RtlZeroMemory
        add esp,20h
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
cmp ecx,0
jnbe ScanMore
NoMoreHit: pop rbx
pop rdi
; Now that the comments are out of our way, Get rid of the separators
mov rcx,BufferSize
lea esi,buffer
jrcxz @10; .while ecx>0
@11: lodsb;mov al,byte ptr [esi]
cmp al,'.'
je @14
cmp al,"%"
je @14
cmp al,'0'
jb @12
cmp al,'9'
jbe @14
cmp al,"?";3Fh
jb @12
cmp al,"[";5B
jb @14
cmp al,"\";60h
jbe @12
cmp al,"{";7B
jb @14
cmp al,"~";7F
ja @14
@12: mov byte ptr [rsi-1],0
@14: loop @11
; Begin the search
lea esi,buffer
@10: mov rcx,BufferSize
test ecx,ecx
jz @0; .while ecx>0
@16: cmp byte ptr [rsi],0
jz @17
push rcx
sub esp,20h
mov ecx,esi
call lstrlen
        add esp,20h
push rax
mov edx,eax ; edx contains the length of the string
movzx eax,byte ptr [esi]
cmp al,"A";.if al>="A" && al<="Z"
jb @f
cmp al,"Z"
ja @f
add al,20h;"a"
@@: lea eax,[rdi+rax*4]; edi contains the pointer to the WORDINFO pointer array
cmp dword ptr [rax],0
jz @19
mov eax,[rax]
jmp @20
@21: cmp edx,[eax+WORDINFO.WordLen]
jnz @22
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
sub esp,20h
mov edx,esi
mov ecx,[rax+WORDINFO.pszWord]
call lstrcmpi
        add esp,20h
or eax,eax;.if eax==0
jnz @23
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
; hilite the word
mov ecx,esi
lea edx,buffer
sub ecx,edx
add rcx,FirstChar
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
cmp [RichEditVersion],3
jnz @24
sub esp,20h
mov r9d,ecx
lea r8d,rect
mov edx,EM_POSFROMCHAR
mov rcx,hWnd
call SendMessage
        add esp,20h
jmp @25;.else
@24:    sub esp,20h
xor r9d,r9d
mov r8d,ecx
mov edx,EM_POSFROMCHAR
mov rcx,hWnd
call SendMessage
        add esp,20h
movzx ecx,ax
mov rect.left,ecx
shr eax,16
mov rect.top,eax
@25: pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
mov edx,[eax+WORDINFO.pColor]
sub esp,20h
mov edx,dword ptr [edx]
mov rcx,hdc
call SetTextColor
        sub esp,10h
mov qword ptr [rsp+20h],0
lea r9d,rect
or r8d,-1
mov edx,esi
mov rcx,hdc
call DrawText
        add esp,30h
jmp @19;.endif
@23: pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
@22: mov eax,[eax+WORDINFO.NextLink]
@20: or eax,eax;.endw
jnz @21;.endif
@19: pop rax
pop rcx
add esi,eax
sub ecx,eax
jmp @15;.else
@17: inc esi
dec ecx
@15: jnz @16
@0:     sub esp,20h
mov rdx,hOldRgn
mov rcx,hdc
call SelectObject
mov rcx,hRgn
call DeleteObject
mov rdx,hOldFont
mov rcx,hdc
call SelectObject
mov rdx,hdc
mov rcx,hWnd
call ReleaseDC
mov rcx,hWnd
call ShowCaret
        add esp,20h
pop rax
pop rsi
pop rdi
leave
retn

wmCLOSE:mov r8,OldWndProc
mov edx,GWL_WNDPROC
call SetWindowLongPtr;hWnd
NewRichEditProc 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
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; 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
@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
xor r9d,r9d
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
xor r8d,r8d
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;.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 ecx,WM_COPY;invoke SendMessage,hwndRichEdit,WM_COPY,0,0
jmp @19
CUT:
mov ecx,WM_CUT;invoke SendMessage,hwndRichEdit,WM_CUT,0,0
jmp @19
PASTE:
mov ecx,WM_PASTE;invoke SendMessage,hwndRichEdit,WM_PASTE,0,0
jmp @19
DELETE1:
xor r9d,r9d
mov r8d,TRUE
mov edx,EM_REPLACESEL
jmp @21;invoke SendMessage,hwndRichEdit,EM_REPLACESEL,TRUE,0
SELECTALL:
mov chrg.cpMin,0
mov chrg.cpMax,-1
lea r9,chrg
mov edx,EM_EXSETSEL
jmp @20;invoke SendMessage,hwndRichEdit,EM_EXSETSEL,0,addr chrg
UNDO:   
mov ecx,EM_UNDO;invoke SendMessage,hwndRichEdit,EM_UNDO,0,0
jmp @19
REDO:   
mov edx,EM_REDO
@19: xor r9d,r9d
@20: xor r8d,r8d
@21: mov rcx,hwndRichEdit
call SendMessage;invoke SendMessage,hwndRichEdit,0,0
        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;invoke DialogBoxParam,hInstance,IDD_OPTIONDLG,hWnd,addr OptionProc,0
        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
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;invoke SendMessage,hwndRichEdit,EM_FINDTEXTEX,0,addr findtext
inc eax;.if eax!=-1
jz wmBYE
mov r9d,offset findtext.chrgText
xor r8d,r8d
mov edx,EM_EXSETSEL
mov rcx,hwndRichEdit
call SendMessage;invoke SendMessage,hwndRichEdit,EM_EXSETSEL,0,addr findtext.chrgText
jmp wmBYE
EXIT:   xor r9d,r9d
xor r8d,r8d
mov edx,WM_CLOSE
mov rcx,hWnd
call SendMessage
jmp wmBYE
wmCLOSE:call CheckModifyState;,hWnd
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 'Win64 Iczelion''s lesson #35: IczEdit version 3.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
WordFileName db "\wordfile.txt",0
ASMSection db "ASSEMBLY",0
C1Key db "C1",0
C2Key db "C2",0
C3Key db "C3",0
C4Key db "C4",0
C5Key db "C5",0
C6Key db "C6",0
C7Key db "C7",0
C8Key db "C8",0
C9Key db "C9",0
C10Key db "C10",0
ZeroString db 0
ASMColorArray dd 0FF0000h,0805F50h,0FFh,666F00h,44F0h,5F8754h,4 dup(0FF0000h)
CommentColor dd 808000h
hInstance dq IMAGE_BASE
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 <>
ASMSyntaxArray dd 256 dup(?)
hSearch dq ? ; handle to the search/replace dialog box
hAccel dq ?
hMainHeap dq ? ; heap handle
OldWndProc dq ?
RichEditVersion dq ?
Rect RECT <?>
end

qWord

I think after all that positive feed back it is time give some not that friendly feed back (:badgrin:), so here are some thoughts on the code...

IMAGE_BASE equ 400000hOK, the programmer choose the image base or it is fixed(!) - so far so good ...

mov esi,IMAGE_BASE
...
push rsi ;hInstance
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
but that is really interesting: there is a relationship between the module's base address and CW_USEDEFAULT!
I curios how useful it is for a WinAPI tutorial, to use trick code to transform one magic value into an other one rather than just using the corresponding equate.

STYLBTN equ BS_DEFPUSHBUTTON+WS_VISIBLE+WS_CHILD
dangerous habit


push 10029h ;hIconSm
push 10005h ;hCursor
push 10029h        ;hIcon

The author does know it better than Microsoft?


Quote
...
YES_BUT:;обработка нажатия кнопки. сначала стереть текст в заголовке
...
        mov HWNDBTN,rax;запомнить дескриптор кнопки
l5:        ;загрузить необходимое меню
...
        jrcxz wmBYE;пропускаем первое сообщение при обращении к меню
        test word ptr wParam+2,MF_POPUP;проверяем, что активизировано - пункт меню или заголовок выпадающего меню
        setne al
        movzx r8,al
;если 0, то в lword wParam идентификатор пункта меню
;если 1, то в lword wParam номер заголовка выпадающего меню
...
;заполнение структуры для вызова функции GetMenuItemInfo
...
Ah ... OK.


db 48h;mov ecx,offset ASMSyntaxArray
dd 202444C7h,ASMSyntaxArray;mov [rsp+20h],rcx

Is a there a special reason to encode instruction by hand?


Maybe I did overlooked it, but where is the discussion about the calling convention?

regards,
qWord

MREAL macros - when you need floating point arithmetic while assembling!

Mikl__

#104
Hi, qWord!
I am glad that you are interested in this topic
About
QuoteIMAGE_BASE    equ 400000h
see my discussion with sinsi on page #3
Quotepush 10029h ;hIconSm
push 10005h ;hCursor
push 10029h        ;hIcon
The author does know it better than Microsoft?
see page #1 tool "Win x64 Tutorial #2b: MessageBox"
about comments in russian - 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
And I'm sorry for my bad english