⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 masmed.asm

📁 MasmEd是一款专门针对Masm32做的汇编代码编辑器
💻 ASM
📖 第 1 页 / 共 4 页
字号:
.386
.model flat,stdcall
option casemap:none

include MasmEd.inc
include Tool\CboTool.asm
include Misc\Misc.asm
include Tool\TabTool.asm
include Misc\FileIO.asm
include Misc\Find.asm
;--------------------------------------------------------------------------------
include MPATH\SetReg.asm
include MPATH\mpath.asm
;--------------------------------------------------------------------------------
include Misc\Make.asm
include Opt\KeyWords.asm
include Opt\MenuOption.asm
include Opt\TabOptions.Asm
include Misc\Print.asm
include Misc\CodeComplete.asm
include About\About.asm
include Block\Block.asm
;include \RadASM\masm\inc\radbg.inc
.code

start:

	invoke GetModuleHandle,NULL
	mov		hInstance,eax
	invoke GetCommandLine
	mov		CommandLine,eax
	;Get command line filename
	invoke PathGetArgs,CommandLine
  @@:
	mov		dl,[eax]
	.if dl==VK_SPACE
		inc		eax
		jmp		@b
	.elseif dl=='"'
		invoke PathUnquoteSpaces,eax
	.endif
	mov		CommandLine,eax
	invoke InitCommonControls
	;prepare common control structure
	mov		icex.dwSize,sizeof INITCOMMONCONTROLSEX
	mov		icex.dwICC,ICC_DATE_CLASSES or ICC_USEREX_CLASSES or ICC_INTERNET_CLASSES or ICC_ANIMATE_CLASS or ICC_HOTKEY_CLASS or ICC_PAGESCROLLER_CLASS or ICC_COOL_CLASSES
	invoke InitCommonControlsEx,addr icex
	invoke LoadLibrary,offset szRichEdit
	mov		hRichEd,eax
	invoke GetModuleFileName,0,offset FileName,sizeof FileName
	invoke lstrlen,offset FileName
	mov		edx,offset FileName
	add		edx,eax
  @@:
	dec		edx
	xor eax,eax
	
	mov		al,[edx]
	.if al=='.' || al=='\'
		mov		byte ptr [edx],0
	.endif
	.if al!='\'
		jmp		@b
	.endif
	inc		edx
	invoke lstrcat,offset szSimEd,edx
	invoke SetCurrentDirectory,offset FileName
	invoke RegCreateKeyEx,HKEY_CURRENT_USER,addr szSimEd,0,addr szREG_SZ,0,KEY_WRITE or KEY_READ,0,addr hReg,addr lpdwDisp
	.if lpdwDisp==REG_OPENED_EXISTING_KEY
		mov		lpcbData,sizeof wpos
		invoke RegQueryValueEx,hReg,addr szWinPos,0,addr lpType,addr wpos,addr lpcbData
		.if wpos.wtfile<50
			mov		wpos.wtfile,175
		.endif
		mov		lpcbData,sizeof edopt
		invoke RegQueryValueEx,hReg,addr szEditOpt,0,addr lpType,addr edopt,addr lpcbData
		mov		lpcbData,sizeof lfnt
		invoke RegQueryValueEx,hReg,addr szCodeFont,0,addr lpType,addr lfnt,addr lpcbData
		mov		lpcbData,sizeof lfntlnr
		invoke RegQueryValueEx,hReg,addr szLnrFont,0,addr lpType,addr lfntlnr,addr lpcbData
		mov		lpcbData,sizeof col
		invoke RegQueryValueEx,hReg,addr szColor,0,addr lpType,addr col,addr lpcbData
		mov		lpcbData,sizeof CustColors
		invoke RegQueryValueEx,hReg,addr szCustColors,0,addr lpType,addr CustColors,addr lpcbData

		mov		lpcbData,sizeof nmeexp
		invoke RegQueryValueEx,hReg,addr szNmeExp,0,addr lpType,addr nmeexp,addr lpcbData
		mov		lpcbData,sizeof grdsize
		invoke RegQueryValueEx,hReg,addr szGrid,0,addr lpType,addr grdsize,addr lpcbData

		mov		lpcbData,16*4
		invoke RegQueryValueEx,hReg,addr szKeyWordColor,0,addr lpType,addr kwcol,addr lpcbData
		mov		lpcbData,sizeof ppos
		invoke RegQueryValueEx,hReg,addr szPrnPos,0,addr lpType,addr ppos,addr lpcbData
		mov		eax,ppos.margins.left
		mov		psd.rtMargin.left,eax
		mov		eax,ppos.margins.top
		mov		psd.rtMargin.top,eax
		mov		eax,ppos.margins.right
		mov		psd.rtMargin.right,eax
		mov		eax,ppos.margins.bottom
		mov		psd.rtMargin.bottom,eax
		mov		eax,ppos.pagesize.x
		mov		psd.ptPaperSize.x,eax
		mov		eax,ppos.pagesize.y
		mov		psd.ptPaperSize.y,eax
	.endif
	invoke OleInitialize,NULL
	invoke InstallRAEdit,hInstance
	invoke RAHexEdInstall,hInstance
	invoke ResEdInstall,hInstance
	invoke GridInstall,hInstance
	invoke InstallFileBrowser,hInstance
	invoke InstallRACodeComplete,hInstance
	invoke ParseApiFile
	invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
	push	eax
	invoke UnInstallRAEdit
	invoke RAHexEdUnInstall
	invoke ResEdUninstall
	invoke UnInstallFileBrowser
	.if hApiMem
		invoke GlobalFree,hApiMem
	.endif
	.if hRichEd
		invoke FreeLibrary,hRichEd
	.endif
	invoke RegSetValueEx,hReg,addr szWinPos,0,REG_BINARY,addr wpos,sizeof wpos
	invoke RegCloseKey,hReg
	invoke OleUninitialize
	pop		eax
	invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
	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,DLGWINDOWEXTRA
	push	hInst
	pop		wc.hInstance
	mov		wc.hbrBackground,COLOR_BTNFACE+1;NULL
	mov		wc.lpszMenuName,IDM_MENU
	mov		wc.lpszClassName,offset ClassName
	invoke LoadIcon,hInst,32106
	mov		hIcon,eax
	mov		wc.hIcon,eax
	mov		wc.hIconSm,eax
	invoke LoadCursor,NULL,IDC_ARROW
	mov		wc.hCursor,eax
	invoke RegisterClassEx,addr wc

	mov		wc.cbSize,sizeof WNDCLASSEX
	mov		wc.style,CS_HREDRAW or CS_VREDRAW
	mov		wc.lpfnWndProc,offset ResProc
	mov		wc.cbClsExtra,NULL
	mov		wc.cbWndExtra,NULL
	push	hInst
	pop		wc.hInstance
	mov		wc.hbrBackground,NULL
	mov		wc.lpszMenuName,NULL
	mov		wc.lpszClassName,offset szResClassName
	xor		eax,eax
	mov		wc.hIcon,eax
	mov		wc.hIconSm,eax
	invoke LoadCursor,NULL,IDC_ARROW
	mov		wc.hCursor,eax
	invoke RegisterClassEx,addr wc

	invoke CreateDialogParam,hInstance,IDD_DLG,NULL,offset WndProc,NULL
	mov		hWnd,eax
	.if wpos.fMax
		mov		eax,SW_MAXIMIZE
	.else
		mov		eax,SW_SHOWNORMAL
	.endif
	invoke ShowWindow,hWnd,eax
	test	wpos.fView,4
	.if !ZERO?
		invoke ShowWindow,hOut,SW_SHOWNA
	.endif
	invoke UpdateWindow,hWnd
	invoke LoadAccelerators,hInstance,IDR_ACCEL
	mov		hAccel,eax
	;Get command line filename
	mov		edx,CommandLine
	mov		al,[edx]
	.if al
		invoke lstrcpy,offset FileName,edx
		invoke TabToolSetText,0,offset FileName
		invoke LoadFile,hREd,offset FileName
	.endif
	.while TRUE
		invoke GetMessage,addr msg,NULL,0,0
	  .break .if !eax
		invoke IsDialogMessage,hFind,addr msg
		.if !eax
			invoke TranslateAccelerator,hWnd,hAccel,addr msg
			.if !eax
				invoke TranslateMessage,addr msg
				invoke DispatchMessage,addr msg
			.endif
		.endif
	.endw
	mov		eax,msg.wParam
	ret

WinMain endp

RAEditProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

	mov		eax,uMsg
	.if eax==WM_CHAR
		mov		eax,wParam
		.if eax==VK_TAB
			invoke IsWindowVisible,hCCLB
			.if eax
				invoke SendMessage,hREd,REM_LOCKUNDOID,TRUE,0
				invoke SendMessage,hREd,EM_EXSETSEL,0,addr ccchrg
				invoke SendMessage,hCCLB,CCM_GETCURSEL,0,0
				invoke SendMessage,hCCLB,CCM_GETITEM,eax,0
				push	eax
				invoke SendMessage,hREd,EM_REPLACESEL,TRUE,eax
				pop		eax
				push	eax
				invoke lstrlen,eax
				pop		edx
				.if byte ptr [edx+eax+1]
					mov		word ptr LineTxt,','
					invoke SendMessage,hREd,EM_REPLACESEL,TRUE,offset LineTxt
				.endif
				invoke SendMessage,hREd,REM_LOCKUNDOID,FALSE,0
				invoke ShowWindow,hCCLB,SW_HIDE
				xor		eax,eax
				jmp		Ex
			.endif
		.elseif eax==VK_ESCAPE
			invoke ShowWindow,hCCLB,SW_HIDE
			xor		eax,eax
			jmp		Ex
		.endif
	.elseif eax==WM_KEYDOWN
		mov		edx,wParam
		mov		eax,lParam
		shr		eax,16
		and		eax,3FFh
		.if edx==28h && (eax==150h || eax==50h)
			;Down
			invoke IsWindowVisible,hCCLB
			.if eax
				invoke SetFocus,hCCLB
				xor		eax,eax
				jmp		Ex
			.endif
		.endif
	.endif
	invoke CallWindowProc,lpOldRAEditProc,hWin,uMsg,wParam,lParam
  Ex:
	ret

RAEditProc endp

CreateRAEdit proc

	push	hREd
	.if edopt.hilitecmnt
		mov		eax,WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or STYLE_NOBACKBUFFER or STYLE_DRAGDROP or STYLE_SCROLLTIP or STYLE_HILITECOMMENT
	.else
		mov		eax,WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or STYLE_NOBACKBUFFER or STYLE_DRAGDROP or STYLE_SCROLLTIP
	.endif
	invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szRAEditClass,NULL,eax,0,0,0,0,hWnd,IDC_RAE,hInstance,0
	mov		hREd,eax
	invoke SendMessage,hREd,REM_SUBCLASS,0,addr RAEditProc
	mov		lpOldRAEditProc,eax
	invoke SetFormat,hREd
	;Set colors
	invoke SendMessage,hREd,REM_SETCOLOR,0,addr col
	invoke SendMessage,hWnd,WM_SIZE,0,0
	pop		eax
	invoke ShowWindow,eax,SW_HIDE
	ret

CreateRAEdit endp

CreateRAHexEd proc
	LOCAL	hefnt:HEFONT

	invoke ShowWindow,hREd,SW_HIDE
	invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szRAHexEdClassName,NULL,WS_CHILD or WS_VISIBLE,0,0,0,0,hWnd,IDC_HEX,hInstance,0
	mov		hREd,eax
	mov		eax,hFont
	mov		hefnt.hFont,eax
	mov		eax,hLnrFont
	mov		hefnt.hLnrFont,eax
	;Set fonts
	invoke SendMessage,hREd,HEM_SETFONT,0,addr hefnt
	;Set colors
;	invoke SendMessage,hREd,REM_SETCOLOR,0,addr col
	invoke SendMessage,hWnd,WM_SIZE,0,0
	ret

CreateRAHexEd endp

CreateNew proc

	invoke lstrcpy,offset FileName,offset szNewFile
	invoke CreateRAEdit
	invoke TabToolAdd,hREd,offset FileName
	invoke SetWinCaption,offset FileName
	invoke RefreshCombo,hREd
	invoke SetFocus,hREd
	ret

CreateNew endp

CreateNewRes proc
	LOCAL	hMem:DWORD

	invoke lstrcpy,offset FileName,offset szNewFile
	invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,4096
	mov		hMem,eax
	invoke GlobalLock,hMem
	invoke SendMessage,hProject,PRO_OPEN,offset FileName,hMem
	invoke ShowWindow,hREd,SW_HIDE
	mov		eax,hRes
	mov		hREd,eax
	invoke TabToolAdd,hREd,offset FileName
	invoke SetWinCaption,offset FileName
	invoke ShowWindow,hREd,SW_SHOW
	invoke SendMessage,hWnd,WM_SIZE,0,0
	invoke RefreshCombo,hREd
	invoke SetFocus,hREd
	ret

CreateNewRes endp

UpdateAll proc uses ebx,nFunction:DWORD
	LOCAL	nInx:DWORD
	LOCAL	tci:TCITEM
	LOCAL	hefnt:HEFONT

	invoke SendMessage,hTab,TCM_GETITEMCOUNT,0,0
	mov		nInx,eax
	mov		tci.imask,TCIF_PARAM
	.while nInx
		dec		nInx
		invoke SendMessage,hTab,TCM_GETITEM,nInx,addr tci
		.if eax
			mov		ebx,tci.lParam
			mov		eax,nFunction
			.if eax==WM_SETFONT
				invoke GetWindowLong,[ebx].TABMEM.hwnd,GWL_ID
				.if eax==IDC_RAE
					invoke GetWindowLong,[ebx].TABMEM.hwnd,GWL_STYLE
					.if edopt.hilitecmnt
						or		eax,STYLE_HILITECOMMENT
					.else
						and		eax,-1 xor STYLE_HILITECOMMENT
					.endif
					invoke SetWindowLong,[ebx].TABMEM.hwnd,GWL_STYLE,eax
					invoke SendMessage,[ebx].TABMEM.hwnd,REM_SETCOLOR,0,addr col
					invoke SetFormat,[ebx].TABMEM.hwnd
				.elseif eax==IDC_HEX
					mov		eax,hFont
					mov		hefnt.hFont,eax
					mov		eax,hLnrFont
					mov		hefnt.hLnrFont,eax
					invoke SendMessage,[ebx].TABMEM.hwnd,HEM_SETFONT,0,addr hefnt
				.endif
			.elseif eax==WM_PAINT
				invoke GetWindowLong,[ebx].TABMEM.hwnd,GWL_ID
				.if eax==IDC_RAE
					invoke SendMessage,[ebx].TABMEM.hwnd,REM_REPAINT,0,0
				.elseif eax==IDC_HEX
					invoke SendMessage,[ebx].TABMEM.hwnd,HEM_REPAINT,0,0
				.endif
			.elseif eax==WM_CLOSE
				invoke SendMessage,[ebx].TABMEM.hwnd,EM_GETMODIFY,0,0
				.if eax
					invoke TabToolGetInx,[ebx].TABMEM.hwnd
					invoke SendMessage,hTab,TCM_SETCURSEL,eax,0
					invoke TabToolActivate
					invoke WantToSave,hREd,offset FileName
					or		eax,eax
					jne		Ex
				.endif
			.elseif eax==CLOSE_ALL
				mov		eax,[ebx].TABMEM.hwnd
				.if eax!=hRes
					invoke DestroyWindow,[ebx].TABMEM.hwnd
				.endif
				invoke SendMessage,hTab,TCM_DELETEITEM,nInx,0
				invoke GetProcessHeap
				invoke HeapFree,eax,NULL,ebx
			.elseif eax==WM_DESTROY
;				.if [ebx].TABMEM.hchange
;					invoke FindCloseChangeNotification,[ebx].TABMEM.hchange
;				.endif
;				invoke CloseHandle,[ebx].TABMEM.hthread
				invoke SendMessage,hTab,TCM_DELETEITEM,nInx,0
				invoke DestroyWindow,[ebx].TABMEM.hwnd
				invoke GetProcessHeap
				invoke HeapFree,eax,NULL,ebx
			.elseif eax==IS_OPEN
				invoke lstrcmpi,offset FileName,addr [ebx].TABMEM.filename
				.if !eax
					invoke SendMessage,hTab,TCM_SETCURSEL,nInx,0
					invoke TabToolActivate
					mov		eax,TRUE
					jmp		Ex
				.endif
			.elseif eax==IS_RESOURCE
				mov		eax,[ebx].TABMEM.hwnd
				.if eax==hRes
					invoke SendMessage,hTab,TCM_SETCURSEL,nInx,0
					invoke TabToolActivate
					mov		eax,TRUE
					jmp		Ex
				.endif
			.elseif eax==IS_RESOURCE_OPEN
				mov		eax,[ebx].TABMEM.hwnd
				.if eax==hRes
					mov		eax,TRUE
					jmp		Ex
				.endif
			.elseif eax==SAVE_ALL
				invoke SendMessage,[ebx].TABMEM.hwnd,EM_GETMODIFY,0,0
				.if eax
					invoke SaveEdit,[ebx].TABMEM.hwnd,addr [ebx].TABMEM.filename
				.endif
			.elseif eax==IS_CHANGED
				.if [ebx].TABMEM.nchange
					invoke ReleaseCapture
					mov		[ebx].TABMEM.nchange,0
					invoke lstrcpy,addr LineTxt,addr szChanged
					invoke lstrcat,addr LineTxt,addr [ebx].TABMEM.filename
					invoke lstrcat,addr LineTxt,addr szReopen
					invoke MessageBox,hWnd,addr LineTxt,addr szAppName,MB_YESNO or MB_ICONQUESTION
					.if eax==6
						invoke GetWindowLong,[ebx].TABMEM.hwnd,GWL_ID
						.if eax==IDC_RAE
							invoke LoadFile,[ebx].TABMEM.hwnd,addr [ebx].TABMEM.filename
						.elseif eax==IDC_HEX
							invoke LoadHexFile,[ebx].TABMEM.hwnd,addr [ebx].TABMEM.filename
						.elseif eax==IDC_RES
							invoke LoadRCFile,addr [ebx].TABMEM.filename
						.endif
					.endif
				.endif
			.elseif eax==CLEAR_CHANGED
				.if [ebx].TABMEM.nchange
					mov		[ebx].TABMEM.nchange,0
				.endif
			.endif
		.endif
		xor		eax,eax
	.endw
  Ex:
	ret

UpdateAll endp

MyTimerProc proc uses ebx,hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
	LOCAL	chrg:CHARRANGE

	.if fTimer
		dec		fTimer
		.if ZERO?
			invoke UpdateAll,IS_RESOURCE_OPEN
			xor		eax,1
			mov		edx,IDM_FILE_NEW_RES
			call	EnableDisable
			invoke GetWindowLong,hREd,GWL_ID
			.if eax==IDC_RES
				xor		eax,eax
				invoke SendMessage,hResEd,DEM_CANUNDO,0,0
				mov		edx,IDM_EDIT_UNDO
				call	EnableDisable
				invoke SendMessage,hResEd,DEM_ISSELECTION,0,0
				mov		edx,IDM_EDIT_CUT
				call	EnableDisable
				mov		edx,IDM_EDIT_COPY
				call	EnableDisable
				mov		edx,IDM_EDIT_DELETE
				call	EnableDisable
				.if eax!=2
					xor		eax,eax
				.endif
				mov		edx,IDM_FORMAT_ALIGN
				call	EnableDisable
				mov		edx,IDM_FORMAT_SIZE
				call	EnableDisable
				invoke SendMessage,hResEd,DEM_CANPASTE,0,0
				mov		edx,IDM_EDIT_PASTE
				call	EnableDisable
				xor		eax,eax
				mov		edx,IDM_FILE_PRINT
				call	EnableDisable
				mov		edx,IDM_EDIT_REDO
				call	EnableDisable
				mov		edx,IDM_EDIT_SELECTALL
				call	EnableDisable
				mov		edx,IDM_EDIT_FIND
				call	EnableDisable
				mov		edx,IDM_EDIT_FINDNEXT
				call	EnableDisable
				mov		edx,IDM_EDIT_FINDPREV

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -