masm32构造基本窗口程序

RC文资源文件

  1. #include <resource.h>
  2.  
  3. #define ICO_MAIN 1000
  4. #define DLG_MAIN 1000
  5. #define IDC_INFO 1001
  6. #define IDM_MAIN 2000
  7. #define IDM_OPEN 2001
  8. #define IDM_EXIT 2002
  9.  
  10. #define IDM_1 4000
  11. #define IDM_2 4001
  12. #define IDM_3 4002
  13. #define IDM_4 4003
  14.  
  15.  
  16. ICO_MAIN ICON "main.ico"
  17.  
  18. DLG_MAIN DIALOG 50,50,544,199
  19. STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
  20. CAPTION "PE文件基本信息 by xxx"
  21. MENU IDM_MAIN
  22. FONT 9,"宋体"
  23. BEGIN
  24. CONTROL "",IDC_INFO,"RichEdit20A",196 | ES_WANTRETURN | WS_CHILD | ES_READONLY
  25. | WS_VISIBLE |WS_BORDER | WS_VSCROLL | WS_TABSTOP,0,0,540,396
  26. END
  27.  
  28. IDM_MAIN menu discardable
  29. BEGIN
  30. POPUP "文件(&F)"
  31. BEGIN
  32. menuitem "打开文件(&O)...",IDM_OPEN
  33. menuitem separator
  34. menuitem "退出(&x)",IDM_EXIT
  35. END
  36.  
  37. POPUP "查看"
  38. BEGIN
  39. menuitem "源文件",IDM_1
  40. menuitem "窗口透明度",IDM_2
  41. menuitem separator
  42. menuitem "大小",IDM_3
  43. menuitem "宽度",IDM_4
  44. END
  45.  
  46. END

编译资源文件pe.rc生成目标文件pe.res

rc -r pe.rc
  1. .386
  2. .model flat,stdcall
  3. option casemap:none
  4.  
  5. include windows.inc
  6. include user32.inc
  7. includelib user32.lib
  8. include kernel32.inc
  9. includelib kernel32.lib
  10. include comdlg32.inc
  11. includelib comdlg32.lib
  12.  
  13.  
  14. ICO_MAIN equ 1000
  15. DLG_MAIN equ 1000
  16. IDC_INFO equ 1001
  17. IDM_MAIN equ 2000
  18. IDM_OPEN equ 2001
  19. IDM_EXIT equ 2002
  20. IDM_1 equ 4000
  21. IDM_2 equ 4001
  22. IDM_3 equ 4002
  23.  
  24. .data
  25. hInstance dd ?
  26. hRichEdit dd ?
  27. hWinMain dd ?
  28. hWinEdit dd ?
  29. szFileName db MAX_PATH dup(?)
  30.  
  31. .const
  32. szDllEdit db 'RichEd20.dll',0
  33. szClassEdit db 'RichEdit20A',0
  34. szFont db '宋体',0
  35.  
  36.  
  37. .code
  38.  
  39. ;----------------
  40. ;初始化窗口程序
  41. ;----------------
  42. _init proc
  43. local @stCf:CHARFORMAT
  44.  
  45. invoke GetDlgItem,hWinMain,IDC_INFO
  46. mov hWinEdit,eax
  47. invoke LoadIcon,hInstance,ICO_MAIN
  48. invoke SendMessage,hWinMain,WM_SETICON,ICON_BIG,eax ;为窗口设置图标
  49. invoke SendMessage,hWinEdit,EM_SETTEXTMODE,TM_PLAINTEXT,0 ;设置编辑控件
  50. invoke RtlZeroMemory,addr @stCf,sizeof @stCf
  51. mov @stCf.cbSize,sizeof @stCf
  52. mov @stCf.yHeight,9*20
  53. mov @stCf.dwMask,CFM_FACE or CFM_SIZE or CFM_BOLD
  54. invoke lstrcpy,addr @stCf.szFaceName,addr szFont
  55. invoke SendMessage,hWinEdit,EM_SETCHARFORMAT,0,addr @stCf
  56. invoke SendMessage,hWinEdit,EM_EXLIMITTEXT,0,-1
  57. ret
  58. _init endp
  59.  
  60.  
  61. ;-------------------
  62. ; 窗口程序
  63. ;-------------------
  64. _ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
  65. mov eax,wMsg
  66. .if eax==WM_CLOSE
  67. invoke EndDialog,hWnd,NULL
  68. .elseif eax==WM_INITDIALOG ;初始化
  69. push hWnd
  70. pop hWinMain
  71. call _init
  72. .elseif eax==WM_COMMAND ;菜单
  73. mov eax,wParam
  74. .if eax==IDM_EXIT ;退出
  75. invoke EndDialog,hWnd,NULL
  76. .elseif eax==IDM_OPEN ;打开文件
  77. .elseif eax==IDM_1
  78. .elseif eax==IDM_2
  79. .elseif eax==IDM_3
  80. .endif
  81. .else
  82. mov eax,FALSE
  83. ret
  84. .endif
  85. mov eax,TRUE
  86. ret
  87. _ProcDlgMain endp
  88.  
  89. start:
  90. invoke LoadLibrary,offset szDllEdit
  91. mov hRichEdit,eax
  92. invoke GetModuleHandle,NULL
  93. mov hInstance,eax
  94. invoke DialogBoxParam,hInstance,\
  95. DLG_MAIN,NULL,offset _ProcDlgMain,NULL
  96. invoke FreeLibrary,hRichEdit
  97. invoke ExitProcess,NULL
  98. 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显示如下

发表评论

邮箱地址不会被公开。 必填项已用*标注