Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

windows - assembly masm how do you subtract 2 textboxes

I have 2 text boxes with numbers in them. how do I subtract them and put the result in a third text box.

I tried this

.data

gettext1            DB 100 DUP(?)
gettext2           DB 100 DUP(?)
gettext3            DB 100 DUP(?)

.code

LOCAL pmem1  :DWORD

        invoke GetDlgItemText,hWin,MeasuredlengthXtextbox,esi,100

    invoke GetDlgItemText,hWin,MeasuredlengthYtextbox,edi,100

    sub esi,edi 

    mov pmem1,esi   

    invoke lstrcpy,addr gettext1,pmem1

    invoke SetDlgItemText,hWin,ResultlengthXtextbox,addr gettext3

when I try this code it shows up nothing in the textbox

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First, the third parameter to GetDlgItemText is a pointer to a buffer to hold the string. A register will not work. You need to load esi and edi with the addresses of buffers, say gettext1 and gettext2.

Second, you cannot add strings. The number 1 you see on the screen is not really a number, but an ASCII version of the number.

You need to get the text, convert to a number, subtract, then convert back to a string to use with SetDlgItemText.

To make your life easier, just use GetDlgItemInt which will convert the number string to a number and return in eax, then use SetDlgItemInt


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...