我一直面临这个问题退出一段时间,我想在我点击关闭按钮时发布一个消息框,其中想要询问是/否如果用户想要关闭程序。我的自定义退出按钮就像一个魅力,但窗口的关闭按钮(X)不是这样。 当我点击Yes时它完全退出程序,但是当点击No时,它只是关闭窗口但程序仍在运行,每次都必须从任务管理器关闭它。
不得不提的是,只需单击(X)按钮,程序就会关闭主窗口并提示消息框(是/否)。 我只是想让它工作,所以当我点击否它会回到主程序。 这是代码:
.386P
.MODEL FLAT, stdcall
include c:\masm32\include\user32.inc
includelib c:\masm32\lib\user32.lib
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\masm32.lib
include MYedit.inc
atodw PROTO :DWORD
;------------------------------------------------------------
_DATA SEGMENT DWORD PUBLIC USE32 'DATA'
NEWHWND DD 0
MSG MSGSTRUCT <?>
WC WNDCLASS <?>
HINST DD 0
TITLENAME DB 'Calculator',0
CLASSNAME DB 'CLASS32',0
CPBUT DB 'Exit',0
CPBUT2 DB 'Calculate',0
CPEDT1 DB 'Decimal Number (Max 9 Digits):',0
CPEDT2 DB 'New Counting Base (1-36):',0
CPEDT3 DB 'Result:',0
CPEDT4 DB 0
CLSBUTN DB 'BUTTON',0
CLSEDIT DB 'EDIT',0
HWNDBTN DWORD 0
HWNDEDT1 DWORD 0
HWNDBTN2 DWORD 0
HWNDEDT2 DWORD 0
HWNDEDT3 DWORD 0
HWNDEDT4 DWORD 0
HWNDEDT5 DWORD 0
HWNDEDT6 DWORD 0
CAP DB 'Exit',0
MES DB 'Are you sure to exit the program ?',0
NStr DB 9 dup(0),0
CBasStr DB 3 DUP(0),0
CBas DB ?,0
TheResult BYTE 31 DUP (0),0
_DATA ENDS
;----------------------------------------
_TEXT SEGMENT DWORD PUBLIC USE32 'CODE'
START:
INVOKE GetModuleHandleA, 0
MOV [HINST], EAX
REG_CLASS:
MOV [WC.CLSSTYLE], STYLE
MOV [WC.CLWNDPROC], OFFSET WNDPROC
MOV [WC.CLSCBCLSEX],0
MOV [WC.CLSCBWNDEX],0
MOV EAX, [HINST]
MOV [WC.CLSHINST], EAX
INVOKE LoadIconA, 0, IDI_APPLICATION
MOV [WC.CLSHICON], EAX
INVOKE LoadCursorA, 0, IDC_ARROW
MOV [WC.CLSHCURSOR], EAX
MOV [WC.CLBKGROUND], 5
MOV DWORD PTR [WC.CLMENNAME], 0
MOV DWORD PTR [WC.CLNAME], OFFSET CLASSNAME
INVOKE RegisterClassA, ADDR WC
INVOKE CreateWindowExA, 0, OFFSET CLASSNAME, OFFSET TITLENAME, WS_OVERLAPPEDWINDOW-WS_SIZEBOX-WS_MAXIMIZEBOX-WS_CAPTION, 100, 100, 500, 160, 0, 0, [HINST], 0
CMP EAX, 0
JZ _ERR
MOV [NEWHWND], EAX
INVOKE ShowWindow, [NEWHWND], SW_SHOWNORMAL
;------------------------------------------------------------
INVOKE UpdateWindow, [NEWHWND]
MSG_LOOP:
INVOKE GetMessageA, OFFSET MSG, 0, 0, 0
CMP EAX, 0
JE END_LOOP
INVOKE TranslateMessage, OFFSET MSG
INVOKE DispatchMessageA, OFFSET MSG
JMP MSG_LOOP
END_LOOP:
INVOKE ExitProcess, [MSG.MSWPARAM]
_ERR:
JMP END_LOOP
; The Order of Parameters in The Stack
; [EBP+014Í] ; LPARAM
; [EBP+10H] ; WAPARAM
; [EBP+0CH] ; MES
; [EBP+8] ; HWND
WNDPROC PROC
PUSH EBP
MOV EBP,ESP
PUSH EBX
PUSH ESI
PUSH EDI
CMP DWORD PTR [EBP+0CH] ,WM_DESTROY
JE WMDESTROY
CMP DWORD PTR [EBP+0CH] ,WM_CREATE
JE WMCREATE
CMP DWORD PTR [EBP+0CH] ,WM_COMMAND
JE WMCOMMND
JMP DEFWNDPROC
WMCOMMND:
MOV EAX,HWNDBTN
CMP DWORD PTR [EBP+14H],EAX
JE WMDESTROY
MOV EAX,HWNDBTN2
CMP DWORD PTR [EBP+14H],EAX
JE BTNCOPY
MOV EAX, 0
JMP FINISH
;====================================
BTNCOPY:
INVOKE SendMessageA, HWNDEDT4, WM_GETTEXT, 10, OFFSET NStr
INVOKE SendMessageA, HWNDEDT5, WM_GETTEXT, 3, OFFSET CBasStr
CALL Calculate
INVOKE SendMessageA, HWNDEDT6, WM_SETTEXT, 0, OFFSET TheResult
MOV EAX, 0
JMP FINISH
WMCREATE:
;=============The Exit Button
INVOKE CreateWindowExA, 0, OFFSET CLSBUTN, OFFSET CPBUT, STYLBTN, 372, 50, 100, 20, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDBTN,EAX
;=============The Calculate Button
INVOKE CreateWindowExA, 0, OFFSET CLSBUTN, OFFSET CPBUT2, STYLBTN, 372, 10, 100, 20, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDBTN2,EAX
;=============================================
;1st =====================
INVOKE CreateWindowExA, WS_EX_RIGHT, OFFSET CLSEDIT, OFFSET CPEDT1, STYLEDT1, 10, 10, 210, 23, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDEDT1,EAX
;2nd =====================
INVOKE CreateWindowExA, WS_EX_RIGHT, OFFSET CLSEDIT, OFFSET CPEDT2, STYLEDT1, 10, 50, 210, 23, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDEDT2,EAX
;3rd =====================
INVOKE CreateWindowExA, WS_EX_RIGHT, OFFSET CLSEDIT, OFFSET CPEDT3, STYLEDT1, 10, 90, 210, 23, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDEDT3,EAX
;4th =====================
INVOKE CreateWindowExA, WS_EX_CLIENTEDGE, OFFSET CLSEDIT, OFFSET CPEDT4, STYLEDT2, 225, 10, 83, 20, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDEDT4,EAx
;5th =====================
INVOKE CreateWindowExA, WS_EX_CLIENTEDGE, OFFSET CLSEDIT, OFFSET CPEDT4, STYLEDT2, 225, 50, 27, 20, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDEDT5,EAX
;6th =====================
INVOKE CreateWindowExA, WS_EX_CLIENTEDGE, OFFSET CLSEDIT, OFFSET CPEDT4, STYLEDT2, 225, 90, 249, 20, DWORD PTR [EBP+08H], 0, [HINST],0
MOV HWNDEDT6,EAX
;=================================
INVOKE SetFocus, HWNDEDT4
MOV EAX, 0
JMP FINISH
DEFWNDPROC:
INVOKE DefWindowProcA, DWORD PTR [EBP+08H], DWORD PTR [EBP+0CH], DWORD PTR [EBP+10H], DWORD PTR [EBP+14H]
JMP FINISH
WMDESTROY:
INVOKE MessageBoxA, DWORD PTR [EBP+08H], OFFSET MES, OFFSET CAP, 4
.IF EAX==6
INVOKE PostQuitMessage, 0
MOV EAX,0
.ELSE
JMP FINISH
.ENDIF
FINISH:
POP EDI
POP ESI
POP EBX
POP EBP
RET 16
WNDPROC ENDP
我已经对情况进行了描述,但由于没有足够的声誉,因此无法添加。 我如何避免这种情况,如果需要myedit.inc或Calculate PROC,请告诉我以便为您发布。 提前致谢