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

📄 wordpad.asm

📁 罗云彬32位汇编代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:

_SetCaption	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 设置菜单项、工具栏、状态栏的状态和信息
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_SetStatus	proc
		local	@stRange:CHARRANGE
		local	@dwLines,@dwLine,@dwLineStart
		local	@szBuffer[256]:byte

;********************************************************************
; 在状态栏显示行、列信息
;********************************************************************
		invoke	GetWindowTextLength,hWinEdit
		invoke	wsprintf,addr @szBuffer,addr szCharsFormat,eax
		invoke	SendMessage,hWinStatus,SB_SETTEXT,3,addr @szBuffer
		invoke	SendMessage,hWinEdit,EM_GETLINECOUNT,0,0
		invoke	wsprintf,addr @szBuffer,addr szLinesFormat,eax
		invoke	SendMessage,hWinStatus,SB_SETTEXT,2,addr @szBuffer
		invoke	SendMessage,hWinEdit,EM_EXGETSEL,0,addr @stRange
		invoke	SendMessage,hWinEdit,EM_EXLINEFROMCHAR,0,-1
		mov	@dwLine,eax
		invoke	SendMessage,hWinEdit,EM_LINEINDEX,eax,0
		mov	ecx,@stRange.cpMin
		sub	ecx,eax
		inc	ecx
		invoke	wsprintf,addr @szBuffer,addr szColFormat,ecx
		invoke	SendMessage,hWinStatus,SB_SETTEXT,1,addr @szBuffer
		inc	@dwLine
		invoke	wsprintf,addr @szBuffer,addr szLineFormat,@dwLine
		invoke	SendMessage,hWinStatus,SB_SETTEXT,0,addr @szBuffer
;********************************************************************
; 根据选择情况改变菜单项、工具栏按钮状态
;********************************************************************
		mov	eax,@stRange.cpMin
		.if	eax ==	@stRange.cpMax
			invoke	EnableMenuItem,hMenu,IDM_COPY,MF_GRAYED
			invoke	EnableMenuItem,hMenu,IDM_CUT,MF_GRAYED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_COPY,FALSE
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_CUT,FALSE
		.else
			invoke	EnableMenuItem,hMenu,IDM_COPY,MF_ENABLED
			invoke	EnableMenuItem,hMenu,IDM_CUT,MF_ENABLED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_COPY,TRUE
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_CUT,TRUE
		.endif
;********************************************************************
		invoke	IsClipboardFormatAvailable,CF_TEXT
		.if	eax
			invoke	EnableMenuItem,hMenu,IDM_PASTE,MF_ENABLED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_PASTE,TRUE
		.else
			invoke	EnableMenuItem,hMenu,IDM_PASTE,MF_GRAYED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_PASTE,FALSE
		.endif
;********************************************************************
		invoke	SendMessage,hWinEdit,EM_CANREDO,0,0
		.if	eax
			invoke	EnableMenuItem,hMenu,IDM_REDO,MF_ENABLED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_REDO,TRUE
		.else
			invoke	EnableMenuItem,hMenu,IDM_REDO,MF_GRAYED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_REDO,FALSE
		.endif
;********************************************************************
		invoke	SendMessage,hWinEdit,EM_CANUNDO,0,0
		.if	eax
			invoke	EnableMenuItem,hMenu,IDM_UNDO,MF_ENABLED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_UNDO,TRUE
		.else
			invoke	EnableMenuItem,hMenu,IDM_UNDO,MF_GRAYED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_UNDO,FALSE
		.endif
;********************************************************************
		invoke	GetWindowTextLength,hWinEdit
		.if	eax
			invoke	EnableMenuItem,hMenu,IDM_SELALL,MF_ENABLED
		.else
			invoke	EnableMenuItem,hMenu,IDM_SELALL,MF_GRAYED
		.endif
;********************************************************************
		invoke	SendMessage,hWinEdit,EM_GETMODIFY,0,0
		.if	eax
			invoke	EnableMenuItem,hMenu,IDM_SAVE,MF_ENABLED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_SAVE,TRUE
			invoke	SendMessage,hWinStatus,SB_SETTEXT,4,addr szHasModify
		.else
			invoke	EnableMenuItem,hMenu,IDM_SAVE,MF_GRAYED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_SAVE,FALSE
			invoke	SendMessage,hWinStatus,SB_SETTEXT,4,addr szNotModify
		.endif
;********************************************************************
		.if	szFindText
			invoke	EnableMenuItem,hMenu,IDM_FINDNEXT,MF_ENABLED
			invoke	EnableMenuItem,hMenu,IDM_FINDPREV,MF_ENABLED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_FINDNEXT,TRUE
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_FINDPREV,TRUE
		.else
			invoke	EnableMenuItem,hMenu,IDM_FINDNEXT,MF_GRAYED
			invoke	EnableMenuItem,hMenu,IDM_FINDPREV,MF_GRAYED
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_FINDNEXT,FALSE
			invoke	SendMessage,hWinToolbar,TB_ENABLEBUTTON,IDM_FINDPREV,FALSE
		.endif
;********************************************************************
		.if	dwOption & F_STATUSBAR
			invoke	CheckMenuItem,hMenu,IDM_STATUSBAR,MF_CHECKED
		.else
			invoke	CheckMenuItem,hMenu,IDM_STATUSBAR,MF_UNCHECKED
		.endif
;********************************************************************
		.if	dwOption & F_TOOLBAR
			invoke	CheckMenuItem,hMenu,IDM_TOOLBAR,MF_CHECKED
		.else
			invoke	CheckMenuItem,hMenu,IDM_TOOLBAR,MF_UNCHECKED
		.endif
		ret

_SetStatus	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 重新排列窗口位置
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ResizeWindow	proc
		local	@stRect:RECT
		local	@stRectTemp:RECT
		local	@dwWidth,@dwHeight

		invoke	GetClientRect,hWinMain,addr @stRect
		mov	eax,@stRect.right
		sub	eax,@stRect.left
		mov	@dwWidth,eax
		mov	eax,@stRect.bottom
		sub	eax,@stRect.top
		mov	@dwHeight,eax
;********************************************************************
; 计算及调整状态栏
;********************************************************************
		.if	dwOption & F_STATUSBAR
			invoke	ShowWindow,hWinStatus,SW_SHOW
			invoke	MoveWindow,hWinStatus,0,0,0,0,TRUE
			invoke	GetWindowRect,hWinStatus,addr @stRectTemp
			mov	eax,@stRectTemp.bottom
			sub	eax,@stRectTemp.top
			sub	@dwHeight,eax
		.else
			invoke	ShowWindow,hWinStatus,SW_HIDE
		.endif
;********************************************************************
; 计算及调整工具栏
;********************************************************************
		.if	dwOption & F_TOOLBAR
			invoke	ShowWindow,hWinToolbar,SW_SHOW
			invoke	GetWindowRect,hWinToolbar,addr @stRectTemp
			mov	eax,@stRectTemp.bottom
			sub	eax,@stRectTemp.top
			push	eax
			invoke	MoveWindow,hWinToolbar,0,0,@dwWidth,eax,TRUE
			pop	eax
			sub	@dwHeight,eax
			mov	@stRect.top,eax
		.else
			invoke	ShowWindow,hWinToolbar,SW_HIDE
		.endif
;********************************************************************
; 调整Richedit控件位置
;********************************************************************
		invoke	MoveWindow,hWinEdit,@stRect.left,@stRect.top,\
			@dwWidth,@dwHeight,TRUE
		ret

_ResizeWindow	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_Init		proc

;********************************************************************
; 注册“查找”对话框消息,初始化“查找”对话框的结构
;********************************************************************
		mov	stFind.lStructSize,sizeof stFind
		push	hWinMain
		pop	stFind.hwndOwner
		mov	stFind.Flags,FR_DOWN
		mov	stFind.lpstrFindWhat,offset szFindText
		mov	stFind.wFindWhatLen,sizeof szFindText
		invoke	RegisterWindowMessage,addr FINDMSGSTRING
		mov	idFindMessage,eax
;********************************************************************
; 建立工具栏
;********************************************************************
		invoke	CreateToolbarEx,hWinMain,\
			WS_VISIBLE or WS_CHILD or TBSTYLE_FLAT,\
			1,0,HINST_COMMCTRL,IDB_STD_SMALL_COLOR,offset stToolbar,\
			NUM_BUTTONS,0,0,0,0,sizeof TBBUTTON
		mov	hWinToolbar,eax
;********************************************************************
; 建立状态栏
;********************************************************************
		invoke	CreateStatusWindow,WS_CHILD OR WS_VISIBLE OR \
			SBS_SIZEGRIP,NULL,hWinMain,2
		mov	hWinStatus,eax
		invoke	SendMessage,hWinStatus,SB_SETPARTS,6,offset dwStatusWidth
;********************************************************************
; 建立输出文本窗口
;********************************************************************
		invoke	CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassEdit,NULL,\
			WS_CHILD OR WS_VISIBLE OR WS_VSCROLL OR	WS_HSCROLL \
			OR ES_MULTILINE or ES_NOHIDESEL,\
			0,0,0,0,\
			hWinMain,0,hInstance,NULL
		mov	hWinEdit,eax
		or	dwOption,F_STATUSBAR or F_TOOLBAR
		invoke	_SetCaption
		invoke	_SetStatus
		invoke	_SetFont,addr szFontFace,9 * 20,0
		invoke	SendMessage,hWinEdit,EM_SETEVENTMASK,0,ENM_CHANGE or ENM_SELCHANGE
		invoke	SendMessage,hWinEdit,EM_EXLIMITTEXT,0,-1
		ret

_Init		endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_Quit		proc

		invoke	_CheckModify
		.if	eax
			invoke	DestroyWindow,hWinMain
			invoke	PostQuitMessage,NULL
			.if	hFile
				invoke	CloseHandle,hFile
			.endif
		.endif
		ret

_Quit		endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain	proc	uses ebx edi esi hWnd,uMsg,wParam,lParam
		local	@stRange:CHARRANGE

		mov	eax,uMsg
		.if	eax ==	WM_SIZE
			invoke	_ResizeWindow
		.elseif	eax ==	WM_NOTIFY
			mov	eax,lParam
			mov	eax,[eax + NMHDR.hwndFrom]
			.if	eax == hWinEdit
				invoke	_SetStatus
			.endif
;********************************************************************
; 处理菜单、加速键及工具栏消息
;********************************************************************
		.elseif	eax ==	WM_COMMAND
			mov	eax,wParam
			movzx	eax,ax
			.if	eax ==	IDM_OPEN
				invoke	_CheckModify
				.if	eax
					call	_OpenFile
				.endif
			.elseif	eax ==	IDM_NEW
				invoke	_CheckModify
				.if	eax
					.if	hFile
						invoke	CloseHandle,hFile
						mov	hFile,0
					.endif
					mov	szFileName,0
					invoke	SetWindowText,hWinEdit,NULL
					invoke	_SetCaption
					invoke	_SetStatus
				.endif
			.elseif	eax ==	IDM_SAVE
				call	_SaveFile
			.elseif	eax ==	IDM_SAVEAS
				call	_SaveAs
			.elseif	eax ==	IDM_PAGESETUP
				call	_PageSetup
			.elseif	eax ==	IDM_EXIT
				invoke	_Quit
			.elseif	eax ==	IDM_UNDO
				invoke	SendMessage,hWinEdit,EM_UNDO,0,0
			.elseif	eax ==	IDM_REDO
				invoke	SendMessage,hWinEdit,EM_REDO,0,0
			.elseif	eax ==	IDM_SELALL
				mov	@stRange.cpMin,0
				mov	@stRange.cpMax,-1
				invoke	SendMessage,hWinEdit,EM_EXSETSEL,0,addr @stRange
			.elseif	eax ==	IDM_COPY
				invoke	SendMessage,hWinEdit,WM_COPY,0,0
			.elseif	eax ==	IDM_CUT
				invoke	SendMessage,hWinEdit,WM_CUT,0,0
			.elseif	eax ==	IDM_PASTE
				invoke	SendMessage,hWinEdit,WM_PASTE,0,0
			.elseif	eax ==	IDM_FIND
				and	stFind.Flags,not FR_DIALOGTERM
				invoke	FindText,addr stFind
				.if	eax
					mov	hFindDialog,eax
				.endif
			.elseif	eax ==	IDM_FINDPREV
				and	stFind.Flags,not FR_DOWN
				invoke	_FindText
			.elseif	eax ==	IDM_FINDNEXT
				or	stFind.Flags,FR_DOWN
				invoke	_FindText
			.elseif	eax ==	IDM_FONT
				invoke	_ChooseFont
			.elseif	eax ==	IDM_BKCOLOR
				invoke	_ChooseColor
			.elseif	eax ==	IDM_TOOLBAR
				xor	dwOption,F_TOOLBAR
				invoke	_ResizeWindow
			.elseif	eax ==	IDM_STATUSBAR
				xor	dwOption,F_STATUSBAR
				invoke	_ResizeWindow
			.endif
;********************************************************************
		.elseif	eax ==	idFindMessage
			.if	stFind.Flags & FR_DIALOGTERM
				mov	hFindDialog,0
			.else
				invoke	_FindText
			.endif
;********************************************************************
		.elseif	eax ==	WM_ACTIVATE
			mov	eax,wParam
			.if	(ax ==	WA_CLICKACTIVE ) || (ax == WA_ACTIVE)
				invoke	SetFocus,hWinEdit
			.endif
;********************************************************************
		.elseif	eax ==	WM_CREATE
			push	hWnd
			pop	hWinMain
			invoke	_Init
;********************************************************************
		.elseif	eax ==	WM_CLOSE
			call	_Quit
;********************************************************************
		.else
			invoke	DefWindowProc,hWnd,uMsg,wParam,lParam
			ret
		.endif
;********************************************************************
		xor	eax,eax
		ret

_ProcWinMain	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain	proc
		local	@stWndClass:WNDCLASSEX
		local	@stMsg:MSG
		local	@hAccelerator,@hRichEdit

		invoke	LoadLibrary,offset szDllEdit
		mov	@hRichEdit,eax
		invoke	GetModuleHandle,NULL
		mov	hInstance,eax
		invoke	LoadMenu,hInstance,IDM_MAIN
		mov	hMenu,eax
		invoke	LoadAccelerators,hInstance,IDA_MAIN
		mov	@hAccelerator,eax
;********************************************************************
; 注册窗口类
;********************************************************************
		invoke	RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
		invoke	LoadIcon,hInstance,ICO_MAIN
		mov	@stWndClass.hIcon,eax
		mov	@stWndClass.hIconSm,eax
		invoke	LoadCursor,0,IDC_ARROW
		mov	@stWndClass.hCursor,eax
		push	hInstance
		pop	@stWndClass.hInstance
		mov	@stWndClass.cbSize,sizeof WNDCLASSEX
		mov	@stWndClass.style,CS_HREDRAW or CS_VREDRAW
		mov	@stWndClass.lpfnWndProc,offset _ProcWinMain
		mov	@stWndClass.hbrBackground,COLOR_BTNFACE+1
		mov	@stWndClass.lpszClassName,offset szClassName
		invoke	RegisterClassEx,addr @stWndClass
;********************************************************************
; 建立并显示窗口
;********************************************************************
		invoke	CreateWindowEx,NULL,\
			offset szClassName,offset szCaptionMain,\
			WS_OVERLAPPEDWINDOW,\
			CW_USEDEFAULT,CW_USEDEFAULT,700,500,\
			NULL,hMenu,hInstance,NULL
		mov	hWinMain,eax
		invoke	ShowWindow,hWinMain,SW_SHOWNORMAL
		invoke	UpdateWindow,hWinMain
;********************************************************************
; 消息循环
;********************************************************************
		.while	TRUE
			invoke	GetMessage,addr @stMsg,NULL,0,0
			.break	.if eax	== 0
			invoke	TranslateAccelerator,hWinMain,@hAccelerator,addr @stMsg
			.if	eax == 0
				invoke	TranslateMessage,addr @stMsg
				invoke	DispatchMessage,addr @stMsg
			.endif
		.endw
		invoke	FreeLibrary,@hRichEdit
		ret

_WinMain	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
		call	_WinMain
		invoke	ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		end	start

⌨️ 快捷键说明

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