窗口框架
1 . pe.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
ICO_MAIN equ 1000
DLG_MAIN equ 1000
IDC_INFO equ 1001
IDM_MAIN equ 2000
IDM_OPEN equ 2001
IDM_EXIT equ 2002
IDM_1 equ 4000
IDM_2 equ 4001
IDM_3 equ 4002
IDM_4 equ 4003
.data
hInstance dd ?
hRichEdit dd ? ;富文本动态链接库句柄
hWinMain dd ?
hWinEdit dd ? ;文本控件名柄
.const
szDllEdit db "RichEd20.dll", 0
szClassEdit db "RichEdit20A", 0
szFont db "宋体", 0
szTestMsg db "test", 0
.code
;------------------------
;初始化窗口程序
;------------------------
_init proc
local @stcf:CHARFORMAT
invoke GetDlgItem,hWinMain, IDC_INFO
mov hWinEdit, eax
;为窗口设置图标
invoke LoadIcon, hInstance, ICO_MAIN
invoke SendMessage,hWinMain,WM_SETICON,ICON_BIG,eax
;设置编辑控件
invoke SendMessage, hWinMain, 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, hWinMain, EM_SETCHARFORMAT,0, addr @stcf
invoke SendMessage, hWinMain, EM_EXLIMITTEXT,0,-1
ret
_init endp
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam, lParam
mov eax, wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
push hWnd
pop hWinMain
call _init
.elseif eax == WM_COMMAND
mov eax, wParam
.if eax == IDM_EXIT
invoke EndDialog,hWnd,NULL
.elseif eax == IDM_OPEN
invoke MessageBox, hWnd, offset szTestMsg, NULL, MB_OK
.elseif eax == IDM_1
.elseif eax == IDM_2
.elseif eax == IDM_3
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke LoadLibrary,offset szDllEdit
mov hRichEdit, eax
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance, DLG_MAIN, NULL, offset _ProcDlgMain, NULL
invoke FreeLibrary,hRichEdit
invoke ExitProcess,NULL
end start
2. pe.rc
#include <resource.h>
#define ICO_MAIN 1000
#define DLG_MAIN 1000
#define IDC_INFO 1001
#define IDM_MAIN 2000
#define IDM_OPEN 2001
#define IDM_EXIT 2002
#define IDM_1 4000
#define IDM_2 4001
#define IDM_3 4002
#define IDM_4 4003
ICO_MAIN ICON "main.ico"
DLG_MAIN DIALOG 50,50,544,399
STYLE DS_MODALFRAME |WS_POPUP| WS_VISIBLE | WS_CAPTION |WS_SYSMENU
CAPTION "PE文件基本信息"
MENU IDM_MAIN
FONT 9, "宋体"
BEGIN
CONTROL "", IDC_INFO, "RichEdit20A", 196| ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_BORDER |WS_VSCROLL | WS_TABSTOP, 0, 0, 540, 396
END
IDM_MAIN menu discardable
BEGIN
POPUP "文件(&F)"
BEGIN
menuitem "打开文件(&O)...",IDM_OPEN
menuitem separator
menuitem "退出(&X)...",IDM_EXIT
END
POPUP "查看"
BEGIN
menuitem "源文件",IDM_1
menuitem "窗口透明度",IDM_2
menuitem separator
menuitem "大小",IDM_3
menuitem "宽度",IDM_4
END
END
3.
ml -c -coff pe.asm 生成pe.obj
rc -r pe.rc 生成rc.res
link -subsystem:windows pe.obj pe.RES 生成pe.exe