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

📄 jsb.asm

📁 用汇编写的记事本程序,功能非常全,认真解剖会对理解Windows的消息机制非常有益。
💻 ASM
📖 第 1 页 / 共 3 页
字号:

FindDlgProc endp

DoToolBar proc hInst:DWORD,hToolBar:HWND ;工具栏函数
	LOCAL	tbab:TBADDBITMAP

	;Set toolbar struct size
	invoke SendMessage,hToolBar,TB_BUTTONSTRUCTSIZE,sizeof TBBUTTON,0
	;Set toolbar bitmap
	push	hInst
	pop		tbab.hInst
	mov		tbab.nID,IDB_TBRBMP
	invoke SendMessage,hToolBar,TB_ADDBITMAP,15,addr tbab
	;Set toolbar buttons
	invoke SendMessage,hToolBar,TB_ADDBUTTONS,ntbrbtns,addr tbrbtns
	mov		eax,hToolBar
	ret

DoToolBar endp

SetFormat proc hWin:DWORD
        LOCAL	chrg1:CHARRANGE
       	LOCAL	pf:PARAFORMAT2
	LOCAL	cf:CHARFORMAT
	LOCAL	tp:DWORD
	LOCAL	buffer[16]:BYTE
	LOCAL	pt:POINT
	LOCAL	hDC:HDC

	;Save modify state
	invoke SendMessage,hWin,EM_GETMODIFY,0,0
	push	eax
	;Save selection
	invoke SendMessage,hWin,EM_EXGETSEL,0,addr chrg1 ;设置范围
	invoke SendMessage,hWin,EM_HIDESELECTION,TRUE,0
	;设置字体
	mov		cf.cbSize,sizeof cf
	mov		cf.dwMask,CFM_CHARSET or CFM_FACE or CFM_SIZE or CFM_COLOR or CFM_BOLD \
	                or CFM_ITALIC or CFM_UNDERLINE or CFM_STRIKEOUT
	push ebx
	mov eax,lfnt.lfWeight
	.if eax==700
		mov cf.dwEffects,CFE_BOLD
		mov al,lfnt.lfUnderline
		mov bl,lfnt.lfStrikeOut
		.if al 
		   mov cf.dwEffects,CFE_BOLD or CFE_UNDERLINE
			.if bl
				mov cf.dwEffects,CFE_BOLD or CFE_UNDERLINE or CFE_STRIKEOUT
			.endif
		.else
			.if bl
				mov cf.dwEffects,CFE_BOLD or CFE_STRIKEOUT
			.endif	
		.endif
	.endif
	mov al,lfnt.lfItalic
	.if al
	  mov cf.dwEffects,CFE_ITALIC
	  mov al,lfnt.lfUnderline
	  mov bl,lfnt.lfStrikeOut
		.if al
		        mov cf.dwEffects,CFE_ITALIC or CFE_UNDERLINE
			
			.if bl
				mov cf.dwEffects,CFE_ITALIC or CFE_UNDERLINE or CFE_STRIKEOUT
			.endif
		.else
			
			.if bl
				mov cf.dwEffects,CFE_ITALIC or CFE_STRIKEOUT
			.endif	
		.endif
	.endif
	mov eax,lfnt.lfWeight
	mov bl,lfnt.lfItalic
	.if eax==700 && bl
		mov cf.dwEffects,CFE_BOLD or CFE_ITALIC
		mov al,lfnt.lfUnderline
		mov bl,lfnt.lfStrikeOut
		.if al
		        mov cf.dwEffects,CFE_ITALIC or CFE_UNDERLINE or CFE_BOLD
			.if bl
				mov cf.dwEffects,CFE_ITALIC or CFE_UNDERLINE or CFE_STRIKEOUT or CFE_BOLD
			.endif
		.else
			.if bl
				mov cf.dwEffects,CFE_ITALIC  or CFE_STRIKEOUT or CFE_BOLD
			.endif
			
		.endif
	.endif
	mov eax,lfnt.lfWeight
	mov bl,lfnt.lfItalic
	.if eax<700 && bl==0
		mov cf.dwEffects,0
		mov al,lfnt.lfUnderline
		mov bl,lfnt.lfStrikeOut
		.if al
		        mov cf.dwEffects,CFE_UNDERLINE
			.if bl
				mov cf.dwEffects,CFE_UNDERLINE or CFE_STRIKEOUT 
			.endif
		.else
			.if bl
				mov cf.dwEffects, CFE_STRIKEOUT 
			.endif
			
		.endif
	.endif
		
	pop ebx
	mov		al,lfnt.lfCharSet
	mov		cf.bCharSet,al
	mov		al,lfnt.lfPitchAndFamily
	mov		cf.bPitchAndFamily,al
	invoke lstrcpyn,addr cf.szFaceName,addr lfnt.lfFaceName,LF_FACESIZE
	mov		eax,lfnt.lfHeight
	neg		eax
	mov		ecx,15
	mul		ecx
	mov		cf.yHeight,eax
	mov		eax,rgb
	mov		cf.crTextColor,eax
	
	invoke SendMessage,hWin,EM_SETCHARFORMAT,SCF_SELECTION,addr cf
	;Get tab width
	invoke GetDC,hWin
	mov		hDC,eax
	invoke SelectObject,hDC,hFont
	push	eax
	mov		eax,'WWWW'
	mov		dword ptr buffer,eax
	invoke GetTextExtentPoint32,hDC,addr buffer,4,addr pt
	pop		eax
	invoke SelectObject,hDC,eax
	invoke ReleaseDC,hWin,hDC
	mov		eax,pt.x
	mov		ecx,TabSize
	mul		ecx
	mov		ecx,15
	mul		ecx
	shr		eax,2
	mov		tp,eax
	;Set tab stops
	mov		pf.cbSize,sizeof pf
	mov		pf.dwMask,PFM_TABSTOPS
	mov		pf.cTabCount,MAX_TAB_STOPS
	xor		eax,eax
	xor		edx,edx
	mov		ecx,MAX_TAB_STOPS
  @@:
	add		eax,tp
	mov		dword ptr pf.rgxTabs[edx],eax
	add		edx,4
	loop	@b
	invoke SendMessage,hWin,EM_SETPARAFORMAT,0,addr pf
	;Restore modify state
	pop		eax
	invoke SendMessage,hWin,EM_SETMODIFY,eax,0
	;Restore selection
	invoke SendMessage,hWin,EM_EXSETSEL,0,addr chrg1
	invoke SendMessage,hWin,EM_HIDESELECTION,FALSE,0
	ret

SetFormat endp
_ChooseColor proc
	
	LOCAL @stCC:CHOOSECOLOR
	invoke RtlZeroMemory,addr @stCC,sizeof @stCC
	mov @stCC.lStructSize,sizeof @stCC
	push hWnd
	pop @stCC.hwndOwner
	push dwBackColor
	pop @stCC.rgbResult
	mov @stCC.Flags,CC_RGBINIT or CC_FULLOPEN
	mov @stCC.lpCustColors,offset dwCustColors
	invoke ChooseColor,addr @stCC
	.if eax
		push @stCC.rgbResult
		pop dwBackColor
		invoke SendMessage,hREd,EM_SETBKGNDCOLOR,0,dwBackColor
	.endif
	
	ret

_ChooseColor endp
_PAGESET proc
	
	LOCAL @stPS:PAGESETUPDLG
	invoke RtlZeroMemory,addr @stPS,sizeof @stPS
	mov @stPS.lStructSize,sizeof @stPS
	mov @stPS.flags,PSD_DISABLEMARGINS or PSD_DISABLEORIENTATION or PSD_DISABLEPAGEPAINTING
	push hWnd
	pop @stPS.hwndOwner
	invoke PageSetupDlg,addr @stPS
	
	ret

_PAGESET endp
_ChooseFont proc

	
	LOCAL @stCF:CHOOSEFONT
	invoke RtlZeroMemory,addr @stCF,sizeof @stCF
	mov @stCF.lStructSize,sizeof @stCF
	push hWnd
	pop @stCF.hwndOwner
	mov @stCF.lpLogFont,offset lfnt
	push dwFontColor
	pop @stCF.rgbColors
	mov @stCF.Flags,CF_SCREENFONTS or CF_INITTOLOGFONTSTRUCT or CF_EFFECTS
	invoke ChooseFont,addr @stCF
	.if eax
				invoke DeleteObject,hFont
				invoke CreateFontIndirect,addr lfnt
				mov     hFont,eax
				mov		eax,@stCF.rgbColors
				mov		rgb,eax
				invoke SetFormat,hREd
			.endif
			invoke SetFocus,hREd
	ret

_ChooseFont endp
_SetFormat proc hWin:DWORD,_Bsign:BOOL
        LOCAL	chrg1:CHARRANGE
       	LOCAL	pf:PARAFORMAT2
	LOCAL	cf:CHARFORMAT
	LOCAL	tp:DWORD
	LOCAL	buffer[16]:BYTE
	LOCAL	pt:POINT
	LOCAL	hDC:HDC

	;Save modify state
	invoke SendMessage,hWin,EM_GETMODIFY,0,0
	push	eax
	;Save selection
	invoke SendMessage,hWin,EM_EXGETSEL,0,addr chrg1 ;设置范围
	invoke SendMessage,hWin,EM_HIDESELECTION,TRUE,0
	;设置字体
	mov		cf.cbSize,sizeof cf
	mov		cf.dwMask,CFM_OFFSET or CFM_PROTECTED
	
	.if _Bsign
		
		mov cf.yOffset,60
	.else
		mov cf.yOffset,-60	
		
	.endif
	mov		al,lfnt.lfCharSet
	mov		cf.bCharSet,al
	mov		al,lfnt.lfPitchAndFamily
	mov		cf.bPitchAndFamily,al
	invoke lstrcpyn,addr cf.szFaceName,addr lfnt.lfFaceName,LF_FACESIZE
	mov		eax,lfnt.lfHeight
	neg		eax
	mov		ecx,15
	mul		ecx
	
	mov		cf.yHeight,eax
	mov		eax,rgb
	mov		cf.crTextColor,eax
	
	invoke SendMessage,hWin,EM_SETCHARFORMAT,SCF_SELECTION,addr cf
	;Get tab width
	invoke GetDC,hWin
	mov		hDC,eax
	invoke SelectObject,hDC,hFont
	push	eax
	mov		eax,'WWWW'
	mov		dword ptr buffer,eax
	invoke GetTextExtentPoint32,hDC,addr buffer,4,addr pt
	pop		eax
	invoke SelectObject,hDC,eax
	invoke ReleaseDC,hWin,hDC
	mov		eax,pt.x
	mov		ecx,TabSize
	mul		ecx
	mov		ecx,15
	mul		ecx
	shr		eax,2
	mov		tp,eax
	;Set tab stops
	mov		pf.cbSize,sizeof pf
	mov		pf.dwMask,PFM_TABSTOPS
	mov		pf.cTabCount,MAX_TAB_STOPS
	xor		eax,eax
	xor		edx,edx
	mov		ecx,MAX_TAB_STOPS
  @@:
	add		eax,tp
	mov		dword ptr pf.rgxTabs[edx],eax
	add		edx,4
	loop	@b
	invoke SendMessage,hWin,EM_SETPARAFORMAT,0,addr pf
	;Restore modify state
	pop		eax
	invoke SendMessage,hWin,EM_SETMODIFY,eax,0
	;Restore selection
	invoke SendMessage,hWin,EM_EXSETSEL,0,addr chrg1
	invoke SendMessage,hWin,EM_HIDESELECTION,FALSE,0
	ret

_SetFormat endp

_SetStatus proc

	
	LOCAL @stRange:CHARRANGE
	LOCAL @dwLines,@dwLine,@dwLineStart
	LOCAL @szBuffer[256]:byte
	LOCAL @szBuf[128]:byte
	invoke GetWindowTextLength,hREd
	invoke wsprintf,addr @szBuffer,addr szFormat4,eax
	invoke SendMessage,hWinStatus,SB_SETTEXT,3,addr @szBuffer
	invoke SendMessage,hREd,EM_GETLINECOUNT,0,0
	invoke wsprintf,addr @szBuffer,addr szFormat3,eax
	invoke SendMessage,hWinStatus,SB_SETTEXT,2,addr @szBuffer
	
	invoke SendMessage,hREd,EM_EXGETSEL,0,addr @stRange
;	invoke wsprintf,addr @szBuf,addr szFormat5,@stRange.cpMin,@stRange.cpMax
;	invoke MessageBox,hWnd,addr szFormat5,addr AppName,MB_OK
	
	mov @dwLine,eax
	invoke SendMessage,hREd,EM_LINEINDEX,eax,0
	mov ecx,@stRange.cpMin
	sub ecx,eax
	inc ecx
	invoke wsprintf,addr @szBuffer,addr szFormat2,ecx
	invoke SendMessage,hWinStatus,SB_SETTEXT,1,addr @szBuffer	;列
	inc @dwLine
	invoke wsprintf,addr @szBuffer,addr szFormat1,@dwLine
	invoke SendMessage,hWinStatus,SB_SETTEXT,0,addr @szBuffer	;行
	
	mov eax,@stRange.cpMin
	.if eax==@stRange.cpMax
		invoke EnableMenuItem,hMenu,IDM_EDIT_COPY,MF_GRAYED
		invoke EnableMenuItem,hMenu,IDM_EDIT_CUT,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_COPY,FALSE
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_CUT,FALSE
	.else
		invoke EnableMenuItem,hMenu,IDM_EDIT_COPY,MF_ENABLED
		invoke EnableMenuItem,hMenu,IDM_EDIT_CUT,MF_ENABLED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_COPY,TRUE
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_CUT,TRUE	
	.endif
	invoke SendMessage,hREd,EM_CANPASTE,0,0				;判断粘贴
	.if eax
		invoke EnableMenuItem,hMenu,IDM_EDIT_PASTE,MF_ENABLED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_PASTE,TRUE
	.else
		invoke EnableMenuItem,hMenu,IDM_EDIT_PASTE,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_PASTE,FALSE	
	.endif
	invoke SendMessage,hREd,EM_CANREDO,0,0				;重做
	.if eax
		invoke EnableMenuItem,hMenu,IDM_EDIT_REDO,MF_ENABLED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_REDO,TRUE
	.else
		invoke EnableMenuItem,hMenu,IDM_EDIT_REDO,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_REDO,FALSE
	.endif
	invoke SendMessage,hREd,EM_CANUNDO,0,0				;撤消
	.if eax
		invoke EnableMenuItem,hMenu,IDM_EDIT_UNDO,MF_ENABLED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_UNDO,TRUE
	.else
		invoke EnableMenuItem,hMenu,IDM_EDIT_UNDO,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_UNDO,FALSE
	.endif
	invoke GetWindowTextLength,hREd
	.if eax
		invoke EnableMenuItem,hMenu,IDM_EDIT_SELECTALL,MF_ENABLED	;全选
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_SELECTALL,TRUE
		invoke EnableMenuItem,hMenu,IDM_FILE_PRINT,MF_ENABLED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_FILE_PRINT,TRUE
	.else
		invoke EnableMenuItem,hMenu,IDM_EDIT_SELECTALL,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_EDIT_SELECTALL,FALSE
		invoke EnableMenuItem,hMenu,IDM_FILE_PRINT,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_FILE_PRINT,FALSE	
	.endif
	invoke SendMessage,hREd,EM_GETMODIFY,0,0			;修改
	.if eax
		invoke EnableMenuItem,hMenu,IDM_FILE_SAVE,MF_ENABLED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_FILE_SAVE,TRUE
	.else
		invoke EnableMenuItem,hMenu,IDM_FILE_SAVE,MF_GRAYED
		invoke SendMessage,hTbr,TB_ENABLEBUTTON,IDM_FILE_SAVE,FALSE
	.endif
	.if szFindText
		invoke EnableMenuItem,hMenu,IDM_EDIT_FINDNEXT,MF_ENABLED
		invoke EnableMenuItem,hMenu,IDM_EDIT_FINDPREV,MF_ENABLED
	.else
		invoke EnableMenuItem,hMenu,IDM_EDIT_FINDNEXT,MF_GRAYED
		invoke EnableMenuItem,hMenu,IDM_EDIT_FINDPREV,MF_GRAYED	
		
	.endif
	
	ret

_SetStatus endp
GotoDlgProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM,lParam:LPARAM
	LOCAL LineNo:DWORD
	LOCAL chrg:CHARRANGE
	mov eax,uMsg
	.if eax==WM_INITDIALOG
		push hWin
		pop hFind
	.elseif eax==WM_COMMAND
		mov eax,wParam
		shr eax,16
		.if ax==BN_CLICKED

⌨️ 快捷键说明

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