;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Name : Dialog2.asm
;Function: 玩话程序,看看你是否能点中"否"按钮
;Author : Purple Endurer
;Version : 0.1
;--------------------------------------------------------------------------
;Date Summary
;2005-07-02 Created
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.386
.model flat, stdcall
option casemap: none
include /masm32/ include/windows.inc
include /masm32/ include/user32.inc
include /masm32/ include/kernel32.inc
include /masm32/ include/shell32.inc
includelib /masm32/ lib/user32.lib
includelib /masm32/ lib/kernel32.lib
includelib /masm32/ lib/shell32.lib
DlgProc PROTO : DWORD,: DWORD,: DWORD,: DWORD
Static PROTO : DWORD, : DWORD, : DWORD, : DWORD, : DWORD, : DWORD, : DWORD
btn_NewWndProc PROTO : DWORD, : DWORD, : DWORD, : DWORD
m2m MACRO d1, d2
push d2
pop d1
ENDM
.const
IDC_btnYES equ 3000
IDC_btnNO equ 3001
IDC_btnAbout equ 3002
.data
szDlgName db "MyDialog",0
szAppName db "程序设计语言用户调查",0
szYes db "是", 0
szNo db "否", 0
szAgree db "您的回答真令我高兴,因为"
szAboutMsg db 13, 10, "☆ 我就是由【Purple Endurer】用纯32位汇编语言编写的!☆", 0
szAboutTitle db "汇编语言用户调查程序 1.0", 0
szStaticTxtName db "STATIC", 0
szWarning db "你必须接受调查!", 0
g_dwReplied dword 0
.data?
hInstance HINSTANCE ?
g_hWnd HWND ?
g_hbtnYes HWND ?
g_hbtnNo HWND ?
btnNo_OldWndProc dd ?
btnYes_OldWndProc dd ?
g_dwCurrentYesBtn dd ?
g_dwCurrentNoBtn dd ?
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, ADDR szDlgName, NULL, addr DlgProc, NULL
Invoke ExitProcess, eax
;==================================================================
DlgProc proc hWnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM
;------------------------------------------------------------------
.IF uMsg == WM_INITDIALOG
push hWnd
pop g_hWnd
;Get the handle of btnNo
invoke GetDlgItem, hWnd, IDC_btnNO
mov g_hbtnNo, eax
mov g_dwCurrentNoBtn, eax
;-----------------------------------------
; Subclass btnNo!
;-----------------------------------------
invoke SetWindowLong, eax,GWL_WNDPROC, addr btn_NewWndProc
mov btnNo_OldWndProc, eax
;Get the handle of btnYes
invoke GetDlgItem, hWnd, IDC_btnYES
mov g_hbtnYes, eax
mov g_dwCurrentYesBtn, eax
invoke SetFocus, eax
;-----------------------------------------
; Subclass btnYes!
;-----------------------------------------
invoke SetWindowLong,g_hbtnYes, GWL_WNDPROC, addr btn_NewWndProc
mov btnYes_OldWndProc, eax
.ELSEIF uMsg == WM_CLOSE
.if g_dwReplied==0
invoke MessageBox, hWnd, ADDR szWarning, ADDR szAppName,
MB_OK + MB_ICONWARNING
.else
invoke EndDialog, hWnd, NULL
.endif
.ELSEIF uMsg == WM_COMMAND
.if lParam
;pushad
mov edx,wParam
mov eax, edx
shr edx,16
.IF dx == BN_CLICKED
.if ax == IDC_btnAbout
invoke ShellAbout, hWnd, ADDR szAboutTitle, ADDR szAboutMsg, 0
.else
.IF g_dwReplied==0
invoke Static, ADDR szAgree, hWnd, 15, 90, 230, 85, 3
mov g_dwReplied, 1
.ENDIF
.endif
.ENDIF
;popad
.endif
.ELSE
mov eax, FALSE
ret
.ENDIF
mov eax, TRUE
ret
DlgProc endp
;======================================================================
Static proc lpText: DWORD, hParent: DWORD, dwLeft: DWORD, dwTop: DWORD,
dwWidth: DWORD, dwHeight : DWORD,ID: DWORD
;======================================================================
invoke CreateWindowEx, WS_EX_STATICEDGE or WS_EX_WINDOWEDGE,
ADDR szStaticTxtName, lpText,
WS_CHILD or WS_VISIBLE or SS_LEFT,
dwLeft, dwTop, dwWidth, dwHeight, hParent, ID,
hInstance,NULL
ret
Static endp
;===========================================================================
btn_NewWndProc PROC hBtn: DWORD, uMsg: DWORD, wParam: DWORD, lParam: DWORD
;===========================================================================
m2m eax, hBtn
.IF g_dwCurrentYesBtn != eax
.if uMsg==WM_MOUSEMOVE
m2m g_dwCurrentNoBtn, g_dwCurrentYesBtn
m2m g_dwCurrentYesBtn, hBtn
;--------------------------
;Must use SendMessage
;--------------------------
invoke SendMessage, g_dwCurrentYesBtn, WM_SETTEXT, NULL, ADDR szYes
invoke SendMessage, g_dwCurrentNoBtn, WM_SETTEXT, NULL, ADDR szNo
.elseif uMsg==WM_SETFOCUS
invoke PostMessage, g_dwCurrentYesBtn,WM_SETFOCUS, hBtn, NULL
.elseif uMsg==WM_KEYDOWN
invoke PostMessage, g_dwCurrentYesBtn, WM_KEYDOWN, wParam, lParam
.else
jmp @F
.endif
xor eax, eax
ret
.ENDIF
@@:
mov eax,g_hbtnNo
.IF g_dwCurrentYesBtn == eax
mov eax, btnNo_OldWndProc
.ELSE
mov eax, btnYes_OldWndProc
.ENDIF
invoke CallWindowProc, eax, hBtn, uMsg, wParam, lParam
ret
btn_NewWndProc endp
end start
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;rsrc.rc
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include "/masm32/include/resource.h"
#define IDC_btnYES 3000
#define IDC_btnNO 3001
#define IDC_btnAbout 3002
#define IDC_Question 3003
MyDialog DIALOG 10, 10, 215, 70
STYLE 0x0001 | DS_CENTER | WS_CAPTION | DS_SYSMODAL |
WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
| WS_POPUP | WS_SYSMENU | WS_EX_TOOLWINDOW
CAPTION "程序设计语言用户调查"
/*CLASS "DLGCLASS"*/
{
DEFPUSHBUTTON "是", IDC_btnYES, 131, 10, 52, 13
PUSHBUTTON "否", IDC_btnNO, 131, 30, 52, 13
PUSHBUTTON "[&A]关于…", IDC_btnAbout, 131, 50, 52, 13
LTEXT "问题:/r/r你喜欢用汇编语言写程序吗?",IDC_Question,10, 10, 110, 55
}