在学罗老大的《win32汇编程序设计》,敲了个程序
rc文件:
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define ICO_MAIN 0x1000
#define DLG_MAIN 0x1000
#define IDM_MAIN 0x1000
#define IDM_OPEN 0x1101
#define IDM_SAVEAS 0x1102
#define IDM_PAGESETUP 0x1103
#define IDM_EXIT 0x1104
#define IDM_FIND 0x1201
#define IDM_REPLACE 0x1202
#define IDM_SELFONT 0x1203
#define IDM_SELCOLOR 0x1204
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN ICON "Main.ico"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN DIALOGEX 150, 180, 250, 130
MENU IDM_MAIN
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_CLIENTEDGE
CAPTION "通用对话框示例"
FONT 9, "宋体"
{
}
IDM_MAIN menu discardable
BEGIN
popup "文件(&F)"
BEGIN
menuitem "打开文件(&O)...", IDM_OPEN
menuitem "文件另存为(&C)...",IDM_SAVEAS
menuitem separator
menuitem "页面设置(&P)...",IDM_PAGESETUP
menuitem separator
menuitem "退出(&X)", IDM_EXIT
END
popup "查看(&V)"
BEGIN
menuitem "查找字符串(&S)...",IDM_FIND
menuitem "替换字符串(&R)...",IDM_REPLACE
menuitem separator
menuitem "选择字体(&F)...",IDM_SELFONT
menuitem "选择颜色(&B)...",IDM_SELCOLOR
END
END
-------------------------------------------------------------------
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 1000h
DLG_MAIN equ 1000h
IDM_MAIN equ 1000h
IDM_OPEN equ 1101h
IDM_SAVES equ 1102h
IDM_PAGESETUP equ 1103h
IDM_EXIT equ 1104h
IDM_FIND equ 1201h
IDM_REPLACE equ 1202h
IDM_SELFONT equ 1203h
IDM_SELCOLOR equ 1204h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;data
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
_ProcDlgMain proc uses ebx esi edi, hWnd, wMsg, wParam, lParam
local @szBuffer[128]:byte
mov eax, wMsg
.if eax == WM_CLOSE
invoke EndDialog, hWnd, NULL
.elseif eax == WM_INITDIALOG
.else
mov eax, FALSE
ret
.endif
mov eax, TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, DLG_MAIN, NULL,\
offset _ProcDlgMain, NULL
invoke ExitProcess, NULL
end start
很简单的程序,本来以为能显示一个对话框。。。结果。。结果,什么都没有
后来看了半天才发现是因为把资源定义成16进制的了。
书上在前面有说,windows将大于65535的数值当做字符串解释。。。把资源定义小点就行了。
结果我定义的数太大了。。。。让系统当成字符串了,在此贴出来,希望像能给像我一样的菜鸟一些警告,避免再犯同样的错误
还是太菜了,这么简单的问题都调试了一个小时。。。
希望大牛勿笑
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!