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,199
- STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
- CAPTION "PE文件基本信息 by xxx"
- MENU IDM_MAIN
- FONT 9,"宋体"
- BEGIN
- CONTROL "",IDC_INFO,"RichEdit20A",196 | ES_WANTRETURN | WS_CHILD | ES_READONLY
- | 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
编译资源文件pe.rc生成目标文件pe.res
rc -r pe.rc
- .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
- 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
-
- .data
- hInstance dd ?
- hRichEdit dd ?
- hWinMain dd ?
- hWinEdit dd ?
- szFileName db MAX_PATH dup(?)
-
- .const
- szDllEdit db 'RichEd20.dll',0
- szClassEdit db 'RichEdit20A',0
- szFont db '宋体',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,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
-
-
- ;-------------------
- ; 窗口程序
- ;-------------------
- _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 ;打开文件
- .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
调用DialogBoxParam弹出主窗口
只实现了退出功能
.if eax==WM_CLOSE
invoke EndDialog,hWnd,NULL
编译asm
cl -c -coff pe.asm
链接资源文件与目标文件
link -subsystem:windows pe.obj pe.res
执行pe.exe显示如下