News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

add letter to end of a text field

Started by Trope, September 15, 2005, 04:45:26 AM

Previous topic - Next topic

Trope

I have a button, IDC_BUTTON1 and an edit control (textbox) named IDC_EDIT1.

When the IDC_BUTTON1 is pressed, how do I add a certain character to the textbox? For instance, when the button is pressed, add the character "1" to the end of whatever is already in the textfield.

Any help would be greatly appreciated!

THX!

lamer


LOCAL szBuffer[256]        :BYTE
;hwnd - your dialog handle
invoke GetDlgItemText,hwnd,IDC_EDIT1,addr szBuffer,sizeof szBuffer
invoke lstrlen,addr szBuffer
lea ecx,szBuffer
add ecx,eax
mov [ecx],byte ptr 31h    ;31h = "1"
invoke SetDlgItemText,hwnd,IDC_EDIT1,addr szBuffer

Trope

 :U kick ass. now that i see it... it looks easy. a few hours ago... impossible!


thanks man!

Trope

Ok now for more...

let's say i have buttons named IDC_BUTTON1, all the way through BUTTON9 (and BUTTON0 of course)...

if there an efficient way to do this rather than all those .IF statements?

Like in a function or something?

Here is what I have in mind...


SendNumber  pszNumber:DWORD

; then do your code

; but pszNumber would be the IDC_BUTTON1 , or IDC_BUTTON2, etc.

ENDP  SendNumber


Basically I have a keypad of numbers, like a phone, and when the user presses a number, I want the number displayed in the edit control.

would a function be more efficient, or use all those IF's?




hutch--

Giovanni,

How do you want to store the numbers ? Hard code them in the asm file or make them part of an external file that the APP loads ?
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jimg

Quotelet's say i have buttons named IDC_BUTTON1, all the way through BUTTON9 (and BUTTON0 of course)...
if there an efficient way to do this rather than all those .IF statements?
Assuming by efficiency, you want to minimize the amount of code, you could do something like this-
; assuming the 0 button is id 1001, 1=1002, ...  9=1010  i.e. they are any consecutive sequence
mov eax,wParam
.if ax>=1001 and ax<=1010      ; is it one of the number buttons?
    sub eax,1001-48  ; base - '0'   ; you now have the character to append in al
    ; add al to text as before           
.endif

I may be off by one on the subtraction, you'll have to try it.

P1

Quote from: Jimg on September 15, 2005, 01:51:48 PM
Assuming by efficiency, you want to minimize the amount of code, you could do something like this-
; assuming the 0 button is id 1001, 1=1002, ...  9=1010  i.e. they are any consecutive sequence
mov eax,wParam
.if ax>=1001 and ax<=1010      ; is it one of the number buttons?
    sub eax,1001-48  ; base - '0'   ; you now have the character to append in al
    ; add al to text as before           
.endif

I may be off by one on the subtraction, you'll have to try it.
Jimg has a good idea but you can strip out conversion time by changing the id to 01030h to 01039h, just move the al register part of the value to the append to the Edit box.

Regards,  P1  :8)