News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

help please: masm32 input dialog box

Started by Mads379, September 16, 2018, 10:08:47 PM

Previous topic - Next topic

Mads379

how can i change the display into dialog input box instead of cmd.



TITLE my program ()

INCLUDE irvine32.inc
INCLUDE Macros.inc

.data
str1 BYTE "Enter two integers: ", 0
str4 BYTE "The highest integer: ", 0dh, 0ah, 0
str6 BYTE "The smallest integer: ",0dh, 0ah, 0

arrInt DWORD 2 dup(?)
arrLen = LENGTHOF arrInt

.code
main PROC
call getIntUser
call Crlf
call printInt
call Crlf
exit
main ENDP

getIntUser PROC
mov ecx, arrLen
mov edx, OFFSET str1
mov esi, OFFSET arrInt
L1:
   call WriteString
   call ReadInt
   mov [esi], eax
   add esi, TYPE arrInt
   loop L1
   ret
getIntUser ENDP

printInt PROC
mov ecx, arrLen
mov esi, OFFSET arrInt

mov eax, [esi]
add esi, TYPE arrInt
mov ebx, [esi]
.IF eax > ebx
mov edx, OFFSET str4
call WriteString
call WriteDec
call Crlf
mov edx, OFFSET str6
call WriteString
mov eax, ebx
call WriteDec

.ELSE
xchg eax, ebx
mov edx, OFFSET str4
call WriteString
call WriteDec
call Crlf
mov edx, OFFSET str6
call WriteString
mov eax, ebx
call WriteDec
.ENDIF

ret
printInt ENDP

END main

[code]

aw27

It will not be easy what you want from a console application. Try a windows application.

Vortex

Hi Mads379,

Attached is an example for you. You can check test.bat to see how it works.

jj2007

Interesting, but maybe you should announce that the example creates a key in the registry...

    invoke  InputBox,DWORD PTR [esi+4],\    ; address of the text
                     DWORD PTR [esi+8],\    ; address of the title of the input box
                     edx,\                  ; address of the buffer receiving the input text
                     edi,\                  ; x-coordinate of the input box
                     eax,\                  ; y-coordinate of the input box
                     ADDR StrLength         ; pointer to the number of characters received to the input box

    mov     result,eax

    invoke  RegOpenKeyEx,HKEY_CURRENT_USER,ADDR subKey,0,\
            KEY_ALL_ACCESS,ADDR key1

    invoke  RegSetValueEx,key1,ADDR valName,0,\
            REG_SZ,ADDR buffer,StrLength

aw27

Quote from: jj2007 on November 15, 2018, 12:39:48 PM
Interesting, but maybe you should announce that the example creates a key in the registry...

I know it is not important, for you it is all the same, but the example does not create a key it creates a value or sets it if exists.

jj2007

Quote from: AW on November 15, 2018, 07:10:49 PMI know it is not important, for you it is all the same

You are right, José. Btw will you ever be able to post something without an insult?

aw27

#6
Quote from: jj2007 on November 15, 2018, 07:26:14 PM
You are right, José. Btw will you ever be able to post something without an insult?

Dear victimized narcissist,
I believe it is all in your head.  :icon_rolleyes:

Vortex

Hi Jochen,

Quote from: jj2007 on November 15, 2018, 12:39:48 PM
Interesting, but maybe you should announce that the example creates a key in the registry...

Why should I announce that my example creates a key in the registry when I attach the source code? Is it improper to add a key in the section HKEY_CURRENT_USER?

I am not a big fan of the registry but setting a DOS variable to the output of a command is not a very comfortable task. Here is an alternative version not using the registry :

FOR /F %%A in ('InputBox.exe "Type yes to continue, no to exit" "Hello" 100 100') do SET string=%%A

BusyBox, the tiny UNIX\Linux shell is easier to use for the same purpose :

https://frippery.org/busybox/

string=$(InputBox.exe "What is your name?" "Hello" 100 100)

echo Your name is $string

jj2007

Quote from: Vortex on November 19, 2018, 04:09:03 AM
Hi Jochen,

Quote from: jj2007 on November 15, 2018, 12:39:48 PM
Interesting, but maybe you should announce that the example creates a key in the registry...

Why should I announce that my example creates a key in the registry when I attach the source code? Is it improper to add a key in the section HKEY_CURRENT_USER?

Hi Erol,

Please don't be offended, it was not meant to. Your code is fine, but it came without any explanation - and as an assembly coder, I have that reflex "hey, he is fumbling my registry, why that?". My machine is getting slower and slower, and I am getting more and more sensitive to programs that add more stuff to my registry. Yours is a tiny bit indeed, not worth mentioning except for the good cause, i.e. you should explain to us n00bs in a few words what you did there ;-)
:icon14:

Vortex

Hi Jochen,

You are right, some explanation is required. The previous version of InputBox.exe copied the keyboard input to the registry. The command is simple :

InputBox.exe "Type yes to continue, no to exit" "Hello" 100 100

InputBox PROTO pText:DWORD,\      ; address of the text to be displayed in the static control
               pCaption:DWORD,\   ; address of the title of the input box
               pBuffer:DWORD,\    ; address of the buffer receiving the input text
               xpos:DWORD,\       ; x-coordinate of the input box
               ypos:DWORD,\       ; y-coordinate of the input box
               pStringLen:DWORD   ; pointer to the number of characters received to the input box


A separate tool was required to read the string stored in the registry :

FOR /F "delims=" %%A in ('ReadInputBox.exe') do SET choice=%%A

The output of ReadInputBox.exe is assigned to the variable choice.

A better solution is to write the string received by the input box to the console ( v1.02 ) :

FOR /F %%A in ('InputBox.exe "Type yes to continue, no to exit" "Hello" 100 100') do SET string=%%A

No need of ReadInputBox. The FOR loop sets the variable string to the output of InputBox.exe.


hutch--

JJ,

It may be worth looking for a registry cleaner that tests and ditched unused registry entries. Some better quality AV scanners will also clean out some junk from your registry database.