win32汇编富文本控件的基本使用

rich.asm,

		.386
		.model flat, stdcall
		option casemap :none

include		windows.inc
include		user32.inc
includelib	user32.lib
include		kernel32.inc
includelib	kernel32.lib
include		comdlg32.inc
includelib	comdlg32.lib

ICO_MAIN	equ	1000

		.data?
hInstance	dd	?
hWinMain	dd	?
hWinEdit	dd	?

		.data

		.const
szClassName	db	'Wordpad',0
szCaptionMain	db	'富文本控件示例',0
szDllEdit	db	'RichEd20.dll',0
szClassEdit	db	'RichEdit20A',0
szFont		db	'宋体',0

		.code

_Init		proc
		local	@stCf:CHARFORMAT

		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

		invoke	SendMessage,hWinEdit,EM_SETTEXTMODE,TM_PLAINTEXT,0
		invoke	RtlZeroMemory,addr @stCf,sizeof @stCf
		mov	@stCf.cbSize,sizeof @stCf
		mov	@stCf.yHeight,9 * 20
		mov	@stCf.dwMask,CFM_FACE or CFM_SIZE or CFM_BOLD
		invoke	lstrcpy,addr @stCf.szFaceName,addr szFont
		invoke	SendMessage,hWinEdit,EM_SETCHARFORMAT,0,addr @stCf
		invoke	SendMessage,hWinEdit,EM_EXLIMITTEXT,0,-1
		ret

_Init		endp

_Quit		proc

		invoke	DestroyWindow,hWinMain
		invoke	PostQuitMessage,NULL
		ret

_Quit		endp

_ProcWinMain	proc	uses ebx edi esi hWnd,uMsg,wParam,lParam
		local	@stRect:RECT

		mov	eax,uMsg
		.if	eax ==	WM_SIZE
			invoke	GetClientRect,hWinMain,addr @stRect
			invoke	MoveWindow,hWinEdit,0,0,@stRect.right,@stRect.bottom,TRUE

		.elseif	eax ==	WM_COMMAND

		.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	@hRichEdit

		invoke	LoadLibrary,offset szDllEdit
		mov	@hRichEdit,eax
		invoke	GetModuleHandle,NULL
		mov	hInstance,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,NULL,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
			
			.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

rich.rc,


#include		<resource.h>

#define	ICO_MAIN		1000

ICO_MAIN	ICON		"Main.ico"

在程序一开始运行的时候LoadLibrary,载入RichEd20.dll;
然后创建主窗口;
在处理主窗口WM_CREATE消息时,调用_Init过程,在_Init过程中创建富文本控件;
富文本控件创建了之后发一个消息给富文本控件,设置格式,
    SendMessage,hWinEdit,EM_SETCHARFORMAT,0,addr @stCf
@stCf是CHARFORMAT结构体类型;
CHARFORMAT结构含有丰富的编辑控制字符格式的信息;

现在没有处理菜单和控件消息,处理 WM_COMMAND 消息的分支先空着;

处理主窗口WM_SIZE消息时通过MoveWindow函数改变富文本控件的大小;

处理主窗口WM_ACTIVATE消息时,就是主窗口激活时,设置焦点给富文本控件;

程序结束时释放前面载入的dll;

只是在主窗口加载富文本控件,没有其他;

程序还有一些问题,有时间继续;

 

 

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值