最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

assembly - Why are the EndDialog and ExitProcess instructions in this sample MASM32 code for x86 not being executed? - Stack Ove

programmeradmin0浏览0评论

In the sample program, I used DialogBoxParam to create a dialog box (dialog box #1) with a 2 menu options (Help1 & Exit1) and 2 corresponding buttons (Help1 & Exit1).

The Help1 option executed via either the menu or the button opens a 2nd dialog box with similar options (Help2 & Exit2). The Help2 option opens a message box with the message "Help is UNDER CONSTRUCTION".

So far, so good. However, when I attempt to execute any of the Exit options, nothing happens. I use the EndDialog function to exit dialog box #2 expecting it to close dialog box #2 and continue in dialog box #1 but it just hangs. If I run the program and just try to exit dialog box #1 without opening dialog box #2, like the exit routine for dialog box #2, the dialog box #1 exit routine just hangs.

I expected the EndDialog function to close dialog box #1 and the ExitProcess function to terminate the program. I am obviously missing something and could use some help.

Source code
include \masm32\include\masm32rt.inc
include \masm32\include\debug.inc
includelib \masm32\lib\debug.lib
includelib \masm32\lib\comctl32.lib

DlgProc1 proto hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
DlgProc2 proto hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
ExitProcess PROTO, dwExitCode:DWORD

.const
MyMenu1 equ 1000
IDM_Help1 equ 1001
IDM_Exit1 equ 1002
BTN_Help1 equ 1003
BTN_Exit1 equ 1004

MyMenu2 equ 2000
IDM_Help2 equ 2001
IDM_Exit2 equ 2002
BTN_Help2 equ 2003
BTN_Exit2 equ 2004

.data
AppName db "Spawn Dialog Box Example",0
DlgName1 db "MyDialog1",0
DlgName2 db "MyDialog2",0
ErrorMsg db "Error loading RichEdit DLL.",0
Help_String db "Help is UNDER CONSTRUCTION",0
MsgBoxTitle db "Help",0
NoRichEdit db "RichEdit control not available.",0
RichEditClass db "RichEdit20A",0
RichEditDLL db "RICHED32.DLL",0

.data?
DlgCtrlID1 dd ?
DlgCtrlID2 dd ?
ExitCodeDlg1 dd ?
ExitCodeDlg2 dd ?
hInstance HWND ?
hDlg1 HWND ?
hDlg2 HWND ?
hRichEditDLL dd ?

.code
start:
INVOKE GetModuleHandle, NULL
mov hInstance, eax

invoke LoadLibrary,addr RichEditDLL
.IF eax!=0
    mov hRichEditDLL,eax
    INVOKE DialogBoxParam,hInstance,addr DlgName1,NULL,addr DlgProc1,0
    mov ExitCodeDlg1,eax

    invoke FreeLibrary,hRichEditDLL
.ELSE
    
    invoke MessageBox, NULL, addr ErrorMsg, addr AppName, MB_OK
.ENDIF

INVOKE ExitProcess, ExitCodeDlg1

DlgProc1 proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,hWnd
mov hDlg1,eax

.IF uMsg==WM_INITDIALOG

.ELSEIF uMsg==WM_CLOSE
    invoke SendMessage,hDlg1,WM_COMMAND,IDM_Exit1,0

.ELSEIF uMsg==WM_COMMAND
    mov eax,wParam
    .IF lParam==0
        .IF ax==IDM_Help1
            INVOKE DialogBoxParam,hInstance,addr DlgName2,hDlg1,addr DlgProc2,0
            mov ExitCodeDlg2,eax
    ;   .ENDIF  ; ***** This .ENDIF was in WRONG PLACE *****
        .ELSEIF ax==IDM_Exit1
            INVOKE EndDialog,hDlg1,1
        .ENDIF  ; ***** This is CORRECT PLACE for this .ENDIF *****
    .ELSE
       mov edx,wParam
       shr edx,16
        .IF dx==BN_CLICKED
         .IF ax==BTN_Help1
           invoke SendMessage,hDlg1,WM_COMMAND,IDM_Help1,0
         .ELSEIF ax==BTN_Exit1
           invoke SendMessage,hDlg1,WM_COMMAND,IDM_Exit1,0
         .ENDIF
        .ENDIF
    .ENDIF
.ELSE
    mov eax,FALSE
    RET
.ENDIF
mov eax,TRUE
RET
DlgProc1 ENDP

DlgProc2 proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax,hWnd
mov hDlg2, eax

.IF uMsg==WM_INITDIALOG

.ELSEIF uMsg==WM_CLOSE
    invoke SendMessage,hDlg2,WM_COMMAND,IDM_Exit2, 0

.ELSEIF uMsg==WM_COMMAND
    mov eax,wParam
    .IF lParam==0
        .IF ax==IDM_Help2
          invoke MessageBox,NULL,ADDR Help_String,ADDR MsgBoxTitle,MB_OK
    ;   .ENDIF  ; ***** This .ENDIF was in WRONG PLACE *****
        .ELSEIF ax==IDM_Exit2
            INVOKE EndDialog,hDlg2,1
        .ENDIF  ; ***** This is CORRECT PLACE for this .ENDIF *****
    .ELSE
       mov edx,wParam
       shr edx,16
        .IF dx==BN_CLICKED
         .IF ax==BTN_Help2
           invoke SendMessage,hDlg2,WM_COMMAND,IDM_Help2,0
         .ELSEIF ax==BTN_Exit2
           invoke SendMessage,hDlg2,WM_COMMAND,IDM_Exit2,0
         .ENDIF
        .ENDIF
    .ENDIF
.ELSE
    mov eax,FALSE
    RET
.ENDIF
mov eax,TRUE
RET
DlgProc2 ENDP

END start
Resource control files:
;This resource Script was generated by WinAsm Studio.    
#include "resource.h"
#include "richedit.h"
#include "commctrl.h"

#define MyMenu1 1000
#define IDM_Help1 1001
#define IDM_Exit1 1002
#define BTN_Help1 1003
#define BTN_Exit1 1004

MyMenu1 MENUEX DISCARDABLE
BEGIN
    POPUP "&Help"
    BEGIN
        MENUITEM "&Help",IDM_Help1
    END
    POPUP "&Exit"
    BEGIN
        MENUITEM "&Exit",IDM_Exit1
    END
END

MYDIALOG1 DIALOGEX 10,10,800,400
CAPTION "Dialog Box #1"
FONT 8,"MS Shell Dlg"
MENU MyMenu1
STYLE 0x90FB08D8    ;was 0x90FB08D8
EXSTYLE 0x00000200
BEGIN
    CONTROL "Help1",BTN_Help1,"Button",NOT 0x00010000 | 0x10400000,660,350,50,20,0x00000000
    CONTROL "EXIT1",BTN_Exit1,"Button",NOT 0x00010000 | 0x10400000,720,350,50,20,0x00000000
END

#define MyMenu2 2000
#define IDM_Help2 2001
#define IDM_Exit2 2002
#define BTN_Help2 2003
#define BTN_Exit2 2004

MyMenu2 MENUEX DISCARDABLE
BEGIN
    POPUP "&Help"
    BEGIN
        MENUITEM "&Help",IDM_Help2
    END
    POPUP "&Exit"
    BEGIN
        MENUITEM "&Exit",IDM_Exit2
    END

END

MYDIALOG2 DIALOGEX 10,10,800,400
CAPTION "Dialog Box #2"
FONT 8,"MS Shell Dlg"
MENU MyMenu2
STYLE 0x90FB08D8    ;was 0x90FB08D8
EXSTYLE 0x00000200
BEGIN
    CONTROL "Help2",BTN_Help2,"Button",NOT 0x00010000 | 0x10400000,660,350,50,20,0x00000000
    CONTROL "EXIT2",BTN_Exit2,"Button",NOT 0x00010000 | 0x10400000,720,350,50,20,0x00000000
END
发布评论

评论列表(0)

  1. 暂无评论