[Original] Joke program 1 to see if you can click the "no" button

Source: Internet
Author: User
; <<
; Name: dialog2.asm
; Function: Play the phone program to see if you can click the "no" button
; Author: Purple endurer
; Version: 0.1
;--------------------------------------------------------------------------
; Date Summary
; 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
Static proto: DWORD,: DWORD
Btn_newwndproc proto: DWORD,: DWORD

M2M macro D1, D2
Push D2
Pop d1
Endm

. Const
Idc_btnyes equ 3000
Idc_btnno equ 3001
Idc_btnabout equ3002

. Data
Szdlgname DB "mydialog", 0
Szappname DB "user survey of programming language", 0

Szyes DB "yes", 0
Szno DB "no", 0
Szagree DB "your answer really makes me happy, because"
Szaboutmsg dB 13, 10, "☆i was written in pure 32-bit assembly language by Purple endurer! ☆", 0
Szabouttitle DB "assembly language user survey program 1.0", 0
Szstatictxtname DB "static", 0
Szwarning DB "you must accept the investigation! ", 0

G_dwreplied DWORD 0

. Data?
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 create‑wex, ws_ex_staticedge or ws_ex_1_wedge,
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 "user survey of programming language"
/* Class "dlgclass "*/

{
Defpushbutton "is", idc_btnyes, 131, 10, 52, 13
Pushbutton "no", idc_btnno, 131, 30, 52, 13
Pushbutton "[& A] About... ", Idc_btnabout, 131, 50, 52, 13
Ltext "Question:/R/r do you like to write programs in assembly language? ", Idc_question, 10, 10,110, 55
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.