News:

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

Help with String

Started by sayain_code, October 23, 2009, 09:54:50 AM

Previous topic - Next topic

sayain_code

Simple question about strings. I seem to still be be thinking to high level for for masm32. What i want to do is show a display in the window to show the current x y pos of mouse.
I have created a
LTEXT        "X:",ID_Mousex,2,2,50,18,ES_LEFT | WS_BORDER In the rsrc.rc file it displays the current x pos in number format like 234; What i want  is to show the value as a string so i can make it look like this X:234.

.ELSEIF uMsg==WM_MOUSEMOVE
      
      mov eax,lParam
      and eax,0ffffh
      mov hitpoint.x,eax
      mov MouseClick,TRUE
      .IF MouseClick
      invoke SetDlgItemInt,hWin,ID_Mousex,hitpoint.x,TRUE
.ENDIF

How do i take to different strings and put them together into one?

hutch : I just fixed the spelling in your topic, a "sting" in ordinary parlance means something different.  :bg

MichaelW

This (console) code demonstrates one possible method that does the integer to string conversion and combines the two strings in a buffer, all with a single function call:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      buff db 20 dup(0)
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov eax, 234
    invoke wsprintf, ADDR buff, cfm$("X:%d\n\n"), eax
    print ADDR buff

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


Or were you asking how to do it the hard way?
eschew obfuscation

ecube

if u include the masmlib you can use dwota(dword to ascii) e.g number to strong



.data?
mynum dd ?
mybuffer byte 256 dup(?)

mov mynum,58585
invoke dwtoa,mynum,addr mybuffer

sayain_code

Ya i wanted to use convert to string with invoke dwtoa. But i wanted to also merge the 2 strings.
"or were you asking how to do it the hard way?"  what other way u talking about? Sorry for all the newbie questions.
Is the a way to put a var in a string.  Like this -
.data
displayMousex db "X:"+hitpoint.x,0

Is there a correct way to show this or do this? Or is that to high level?

MichaelW

This data definition:

displayMousex db "X:"+hitpoint.x,0

Will not work because the initial value must be a constant or an expression that evaluates to an integer constant, known at assembly time. When you define the variable you can reserve space for the converted integer value, something like this:

displayMousex db "X:",20 dup(0)

And then at run time use dwtoa, or whatever, to convert the value and store it in the reserved space, something like this:

invoke dwtoa, hitpoint.x, ADDR displayMousex + 2
eschew obfuscation