Please bare with my knowledge I am new to assembly language.
I have a code here that add the value of the two textbox
and display the result on the third one when I hit the button.
I tried to construct argument using the GetWindowText
command but it didn't display anything sometimes it crashes, I look into the web with the same program I am working, but I only found this one From stackoverflow the difference is he use the GetDlgItemText
as I read on the Microsoft Website it retrieves the title or text associated with a control in a dialog box, but I am not using a dialog box so maybe I will just stick to the GetWindowText
function.
Here is the code I made, but to be honest I dunno what is going on here I just made it up because I have no idea how to construct an argument for GetWindowText
function.
Some of the code you are seeing there is a recycled code from the program that I work a few days ago which is a simple addition operation, which is when I input two values in a console it add the number and display the result. Now, I am trying to do it again but with the use of textbox and button but I can't get it right.
The Deceleration:
.data?
EditIn1ID db 10 dup(?)
EditIn2ID db 10 dup(?)
EditOutID db 10 dup(?)
hButton HWND ?
hEditIn1 HWND ?
hEditIn2 HWND ?
hEditOut HWND ?
The Textbox and the Button function
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg == WM_DESTROY
invoke PostQuitMessage, 0
.elseif uMsg == WM_CREATE
invoke CreateWindowEx, NULL, addr ButtonClassName, addr ButtonAdd, WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON, 225, 10, 120, 30, hWnd, ButtonID, hInstance, NULL
mov hButton, eax
invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr EditClassName, NULL, WS_CHILD or WS_VISIBLE, 10, 10, 120, 30, hWnd, EditIn1ID, hInstance, NULL
mov DWORD PTR [hEditIn1], eax
invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr EditClassName, NULL, WS_CHILD or WS_VISIBLE, 10, 50, 120, 30, hWnd, EditIn2ID, hInstance, NULL
mov DWORD PTR [hEditIn2], eax
invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr EditClassName, NULL, WS_CHILD or WS_VISIBLE, 10, 110, 120, 30, hWnd, EditOutID, hInstance, NULL
mov DWORD PTR [hEditOut], eax
.elseif uMsg == WM_COMMAND
mov eax, wParam
.if eax == ButtonID
shr eax, 16
.if ax == BN_CLICKED
invoke GetWindowText,EditIn1ID, eax, 10
invoke atodw, addr EditIn1ID
mov ebx, eax
invoke GetWindowText,EditIn2ID, ebx, 10
invoke atodw, addr EditIn2ID
add ebx, eax
invoke dwtoa, ebx, addr res
invoke SetWindowText,EditOutID, addr res
.endif
.endif
Here's What I think of this line of code:
invoke GetWindowText,EditIn1ID, eax, 10
in invoke GetWindowText
this line of code calls the function GetWindowText which copies the input value.
EditIn1ID
This code is the unique ID for my textbox just so that the button has this specific value.
eax
is for calculation operation, maybe it will be use in addition operation.
Some also use esi and edi but I never encounter this code I dunno if they are slightly the same with eax and ebx, I googled the meaning of it but I am skeptical if I can use it here in my code so, I refrain from using it.
Pls. advice me, thanks.