📄 tooltemplate.asm
字号:
title ToolTemplate
.586
.model flat, stdcall
option casemap:none ; Case sensitive
include \MASM32V1\PROGRAMS\AsmEdit\include\Windows.inc
include \MASM32V1\PROGRAMS\AsmEdit\include\user32.inc
include \MASM32V1\PROGRAMS\AsmEdit\include\kernel32.inc
include \MASM32V1\PROGRAMS\AsmEdit\include\gdi32.inc
include \MASM32V1\PROGRAMS\AsmEdit\include\comctl32.inc
include \MASM32V1\PROGRAMS\AsmEdit\include\comdlg32.inc
include \MASM32V1\PROGRAMS\AsmEdit\include\DSPMACRO.asm
includelib \MASM32V1\PROGRAMS\AsmEdit\lib\user32.lib
includelib \MASM32V1\PROGRAMS\AsmEdit\lib\kernel32.lib
includelib \MASM32V1\PROGRAMS\AsmEdit\lib\gdi32.lib
includelib \MASM32V1\PROGRAMS\AsmEdit\lib\comctl32.lib
includelib \MASM32V1\PROGRAMS\AsmEdit\lib\comdlg32.lib
;===================================================
; PROTO, MACRO, and Data section
;===================================================
WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD
RichEditProc PROTO :DWORD, :DWORD, :DWORD, :DWORD
;Insert between
;++++ Proto & Macros ++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MOVmd MACRO Var1, Var2
push Var2
pop Var1
ENDM
.const
;Insert between
;++++ Constants +++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IDM_SELALL equ 2009
.data
RichEdit db 'RichEdit20A',0
RichEdDLL db 'RICHED20.DLL',0
FontNameCN db 'Courier New',0
PopupMenu db 'PopupMenu',0
FontHeight dd -12
FontW dd 400
StatClass db 'msctls_statusbar32',0
szPart1 db 'Part 1',0
szPart3 db 'Part 3',0
ClassName db 'ToolTemplate',0
AppName db 'ToolTemplate',0
MenuName db 'MainMenu',0
szNull db 0
;Insert between
;++++ .data +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
szError1 db 'The RICHED20.DLL was not found!',0
.data?
hInst dd ?
CommandLine dd ?
MainExit dd ?
hWnd dd ?
hREdDll dd ?
hREdit dd ?
hSMenu dd ?
lpRichEdit dd ?
hFont dd ?
FontName db 64 dup(?)
hWndStat dd ?
sbParts dd 4 dup(?)
MenuCnt dd ?
;Insert between
;++++ .data? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [Structures] ----------
.code
;===================================================
; Program initialization section
;===================================================
start:
INVOKE GetModuleHandle, NULL
mov hInst, eax
INVOKE GetCommandLine
mov CommandLine, eax
call InitCommonControls
INVOKE LoadLibrary, addr RichEdDLL ; Load the Riched20.dll
mov hREdDll, eax
.if !eax
INVOKE MessageBox, NULL, addr szError1, addr AppName, MB_OK or MB_ICONERROR
jmp NoGo
.endif
INVOKE WinMain, hInst ,NULL, CommandLine, SW_SHOWDEFAULT
mov MainExit, eax
INVOKE FreeLibrary, hREdDll
NoGo:
INVOKE ExitProcess, MainExit
;===================================================
; WinMain procedure
;===================================================
WinMain proc uses ebx hinst:DWORD, hPrevInst, CmdLine, CmdShow
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszMenuName, offset MenuName
mov wc.lpszClassName, offset ClassName
INVOKE LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
INVOKE LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
INVOKE RegisterClassEx, addr wc
;Insert between if any
;++++ Float/Dock Class ++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [Center the window] ----------
INVOKE GetSystemMetrics, SM_CXSCREEN
sub eax, 350
shr eax, 1
push eax
INVOKE GetSystemMetrics, SM_CYSCREEN
sub eax, 300
shr eax, 1
pop ebx
;---------- [Create the Main Window] ----------
INVOKE CreateWindowEx, WS_EX_CLIENTEDGE, addr ClassName,\
addr AppName, WS_OVERLAPPEDWINDOW,\
ebx, eax, 350, 300, NULL, NULL, hInst, NULL
mov hWnd, eax
INVOKE ShowWindow, hWnd, SW_SHOWNORMAL
INVOKE UpdateWindow, hWnd
;---------- [Message loop] ----------
.while TRUE
INVOKE GetMessage, addr msg, NULL, 0, 0
.break .if (!eax)
INVOKE TranslateMessage, addr msg
INVOKE DispatchMessage, addr msg
.endw
mov eax, msg.wParam
ret
WinMain endp
;===================================================
; WinProc procedure
;===================================================
WndProc proc uses ebx hwnd:DWORD, wMsg, wParam, lParam
LOCAL rect:RECT
LOCAL lf:LOGFONT
LOCAL charF:CHARFORMAT2
;Insert between
;++++ Locals ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LOCAL szBuff[64]:BYTE
;---------- [Create the Control(s) and one time stuff] ----------
.if wMsg == WM_CREATE
;---------- [Create the status bar window] ----------
INVOKE CreateWindowEx, 0, addr StatClass, 0,\
WS_CHILD or WS_BORDER or WS_VISIBLE or SBS_SIZEGRIP,\
0, 0, 0, 0, hwnd, 0, hInst, 0
.if !eax
;Do message
jmp Ret0
.endif
mov hWndStat, eax
;Insert between
;++++ Toolbar code ++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [Create the Edit Window] ----------
INVOKE CreateWindowEx, NULL, addr RichEdit, NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_MULTILINE or\
ES_NOHIDESEL or ES_SAVESEL or ES_SELECTIONBAR or\
WS_HSCROLL or ES_AUTOHSCROLL or\
WS_VSCROLL or ES_AUTOVSCROLL,\
0, 0, 0, 0, hwnd, 4444, hInst, NULL
.if !eax
;Do message
jmp Ret0
.endif
mov hREdit, eax
INVOKE SendMessage, hREdit, EM_EXLIMITTEXT, 0, 4000000
INVOKE SetFocus, hREdit
;---------- [Control window subclassed] ----------
INVOKE SetWindowLong, hREdit, GWL_WNDPROC, RichEditProc
mov lpRichEdit, eax
INVOKE LoadMenu, hInst, addr PopupMenu
INVOKE GetSubMenu, eax, 0
mov hSMenu, eax
;---------- [Get the character format] ----------
mov charF.cbSize, sizeof charF
INVOKE SendMessage, hREdit, EM_GETCHARFORMAT, TRUE, addr charF
mov eax, FontW
mov charF.wWeight, ax
INVOKE lstrcpy, addr FontName, addr FontNameCN
INVOKE RtlZeroMemory, addr lf, sizeof lf
INVOKE lstrcpy, addr lf.lfFaceName, addr FontName
push FontHeight
pop lf.lfHeight
xor eax, eax
mov ax, charF.wWeight
mov lf.lfWeight, eax
mov al, charF.bCharSet
mov lf.lfCharSet, al
mov al, charF.bPitchAndFamily
mov lf.lfPitchAndFamily, al
INVOKE CreateFontIndirect, ADDR lf
mov hFont, eax
INVOKE SendMessage, hREdit, WM_SETFONT, hFont, TRUE
INVOKE GetMenu, hwnd ; Get the handle to the main menu
INVOKE GetSubMenu, eax, 0 ; Get handle to 1st sub menu
INVOKE GetMenuItemCount, eax ; Get count of items in the sub menu
mov MenuCnt, eax ; Menu count for ProcessMRUFiles
;Insert between if any
;++++ Set Dropdown ++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between
;++++ Set variables +++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [Move and Size the Control(s)] ----------
.elseif wMsg == WM_SIZE
;Insert between
;++++ Sizing code +++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between
;++++ Notify code +++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between if any
;++++ Activate Docking Toolbar ++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between if any
;++++ Customize Toolbar code ++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between if any
;++++ Toolbar Dropdown Notify code ++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jmp DefWin
;---------- [System and user commands] ----------
.elseif wMsg == WM_COMMAND
mov eax, wParam
cwde ; Only low word contains command
.if eax == IDM_NEW
INVOKE SendMessage, hREdit, WM_SETTEXT, 0, offset szNull
INVOKE SendMessage, hREdit, EM_SETMODIFY, FALSE, 0
INVOKE SetFocus, hREdit
.elseif eax == IDM_OPEN
.elseif eax == IDM_SAVE
.elseif eax == IDM_EXIT
INVOKE SendMessage, hwnd, WM_CLOSE, 0 ,0
.elseif eax == IDM_CUT
INVOKE SendMessage, hREdit, WM_CUT, 0 ,0
.elseif eax == IDM_COPY
INVOKE SendMessage, hREdit, WM_COPY, 0 ,0
.elseif eax == IDM_PASTE
INVOKE SendMessage, hREdit, WM_PASTE, 0 ,0
.elseif eax == IDM_DELETE
INVOKE SendMessage, hREdit, WM_CLEAR, 0 ,0
.elseif eax == IDM_SELALL
INVOKE SendMessage, hREdit, EM_SETSEL, 0, -1
.elseif eax == IDM_FIND
.elseif eax == IDM_FINDNEXT
.elseif eax == IDM_FINDPREV
.elseif eax == IDM_REPLACE
.endif
.elseif wMsg == WM_CLOSE
INVOKE DestroyWindow, hwnd
.elseif wMsg == WM_DESTROY
;Insert between
;++++ Destroy Imagelist +++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INVOKE PostQuitMessage, NULL
.else
DefWin:
INVOKE DefWindowProc, hwnd, wMsg, wParam, lParam
ret
.endif
Ret0:
xor eax, eax
ret
WndProc endp
;===================================================
; SubClass the Edit control procedure
;===================================================
RichEditProc PROC hwnd:DWORD, wmsg, wparam, lparam
LOCAL rect:RECT
.if wmsg == WM_RBUTTONDOWN
jmp PopUp
.endif
jmp ThatsAll
PopUp:
INVOKE GetWindowRect, hWnd, addr rect
mov ecx, lparam ; x/y pos of window
mov ebx, ecx
and ebx, 0000ffffh ; ebx = LOWORD(lparam) = x pos
shr ecx, 16 ; ecx = HIWORD(lparam) = y pos
add ebx, rect.left
add ecx, rect.top
add ebx, 10
add ecx, 70
INVOKE TrackPopupMenu, hSMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON,\
ebx, ecx, 0, hWnd, addr rect
jmp ThatsAll
ThatsAll:
INVOKE CallWindowProc, lpRichEdit, hwnd, wmsg, wparam, lparam
ret
RichEditProc ENDP
;Insert between
;++++ ChgBmpColor PROC ++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between if any
;++++ Create Docking Toolbar PROC +++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between if any
;++++ FloatWndProc PROC +++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;Insert between if any
;++++ SetSize PROC ++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -