菜鸟问题,Win32对话框中使用菜单后无法显示窗口
00401125 E8 0E000000 call <jmp.&user32.DialogBoxParamA> ; \DialogBoxParamA0040112A 6A 00 push 0 ;下断点处
0040112C E8 25000000 call <jmp.&kernel32.ExitProcess> ; \ExitProcess
00401131 C3 retn
;DialogBoxParam调用后马上返回,不知道怎么回事(也就是说对话框还没有创建就结束了),如果在对话框资源定义中去掉MENU IDM_MAIN
就可以显示,但是没有菜单啊,平时其他的对话框程序我就是用这种方法来创建菜单的,现在这个程序不知道怎么
回事,我用了2个小时去调试也找不到错误原因。
源码: 直接可以编译连接
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include comdlg32.inc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DLL导入库
includelib user32.lib
includelib kernel32.lib
includelib comdlg32.lib
include comctl32.inc
includelib comctl32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>资源文件等值定义
IDD_DLG_MAIN equ 0001h
IDM_MAIN equ 2000h
IDC_STATUS equ 0002h
IDC_EDT1 equ 0003h
IDM_OPEN equ 1101h
IDM_SAVEAS 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
IDM_MENUHELP equ 1300h
.data
hInstance dword ?
hWinMain dword ?
hWinStatus dword ?
hWinEdit dword ?
dwStatusWidth dword 60,140,172,-1
szFormat1 byte "%02d:%02d:%02d",0 ;时间格式化输出
szFormat2 byte "字节数: %d",0
szStr1 byte "插入",0
szStr2 byte "改写",0
dwMenuHelp dword 0,IDM_MENUHELP,0,0
.code
;**********************************************************************
;对话框窗口过程
;**********************************************************************
ProcDlgMain proc uses ebx esi edi hWnd,uMsg,wParam,lParam
LOCAL @szBuffer[256]:byte
LOCAL @stPos:POINT
LOCAL @stST:SYSTEMTIME
mov eax,uMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
mov eax,hWnd
mov hWinMain,eax
invoke GetDlgItem,hWnd,IDC_STATUS
mov hWinStatus,eax
invoke GetDlgItem,hWnd,IDC_EDT1
mov hWinEdit,eax
invoke SendMessage,hWinStatus,SB_SETPARTS,4,offset dwStatusWidth
invoke SendMessage,hWinStatus,SB_SETTEXT,2,offset szStr1
; invoke ShowWindow,hWinMain,SW_SHOW
; call _Resize
invoke SetTimer,hWnd,1,300,NULL
.elseif eax == WM_TIMER
invoke GetLocalTime,addr @stST
movzx eax,@stST.wHour
movzx ebx,@stST.wMinute
movzx ecx,@stST.wSecond
invoke wsprintf,addr @szBuffer,addr szFormat1,eax,ebx,ecx
invoke SendMessage,hWinStatus,SB_SETTEXT,0,addr @szBuffer
; .elseif eax == WM_SIZE
; call _Resize
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
ProcDlgMain endp
;以注释
;**************************************************************************
;自动调整子窗口控件大小
;**************************************************************************
;_Resize proc
; LOCAL @stRect:RECT,@stRect1:RECT
;
; invoke MoveWindow,hWinStatus,0,0,0,0,TRUE
; invoke GetWindowRect,hWinStatus,addr @stRect
; invoke GetClientRect,hWinMain,addr @stRect1
; mov ecx,@stRect1.right
; sub ecx,@stRect1.left
; mov eax,@stRect1.bottom
; sub eax,@stRect1.top
; sub eax,@stRect.bottom
; add eax,@stRect.top
; invoke MoveWindow,hWinEdit,0,0,ecx,eax,TRUE
; ret
;
;_Resize endp
;**************************************************************************
;程序入口处
;**************************************************************************
WinMain proc
invoke InitCommonControls ;加载通用控件库comctl32.dll
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG_MAIN,NULL,offset ProcDlgMain,NULL
invoke ExitProcess,NULL
ret
WinMain endp
end WinMain
:资源文件定义>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <resource.h>
#define IDD_DLG_MAIN 0x0001
#define IDM_MAIN 0x2000
#define IDC_STATUS 0x0002
#define IDC_EDT1 0x0003
#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
#define IDM_MENUHELP 0x1300
IDD_DLG_MAIN DIALOGEX 10,10,300,200
CAPTION "AC_使用状态栏"
FONT 9,"宋体"
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
MENU IDM_MAIN
BEGIN
CONTROL
"",IDC_STATUS,"msctls_statusbar32",WS_CHILDWINDOW|WS_VISIBLE|CCS_BOTTOM,9,114,228,12
; CONTROL "",IDC_EDT1,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|ES_AUTOHSCROLL|ES_MULTILINE|ES_WANTRETURN,10,10,100,200,WS_EX_CLIENTEDGE
END
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