Visual Basic style input boxes

Started by Vortex, August 27, 2008, 09:29:41 PM

Previous topic - Next topic

Vortex

Here is my attempt to create Visual Basic style input boxes. As the name suggests, the input box is used to receive keyboard input from the user.
The function InputBox created with GeneSys takes the parameters below :

InputBox PROC IB_hModule:DWORD,IB_hWnd:DWORD,IB_struct:DWORD

QuoteIB_hModule   -> handle  to the calling module
IB_hWnd      -> handle  to the parent window   
IB_struct      -> pointer to the INPUTBOX structure

The INPUTBOX structure is filled with the parameters required to display the input box. The last two parameters of this structure, IB_TextLen and IB_hEdit can take
arbitrary values as they are used internally by the InputBox function. The function when it returns writes the size of the input string to IB_TextLen

Here is a quick demo :

include Demo.inc

INPUTBOX STRUCT

    IB_SCText   dd ?    ; text to be displayed in the static control
    IB_Caption  dd ?    ; caption of the input box
    IB_Buffer   dd ?    ; Buffer receiving the input text
    IB_xpos     dw ?    ; x coordinate in dialog box units
    IB_ypos     dw ?    ; y coordinate in dialog box units
    IB_TextLen  dd ?    ; used internally - returns the length of the text received by InputBox
    IB_hEdit    dd ?    ; used internally - temporary storage for the handle to edit control

INPUTBOX ENDS

.data
caption     db 'GeneSys Input Box',0
msg         db 'Please enter your name',0
msg2        db 'Sorry, you did not type your name',13,10
            db 'Please try again',0
caption2    db 'Your name is',0

ib          INPUTBOX <OFFSET msg,OFFSET caption,OFFSET buffer,300,250,0,0>
                                                        ; set the properties of the input box

.data?

buffer      db 100 dup(?)
hModule     dd ?

.code

start:

    invoke  GetModuleHandle,0
    mov     hModule,eax
@@:
    invoke  InputBox,hModule,0,ADDR ib
    cmp     IBTextLen(ib),0                             ; IBTextLen - macro returning the length
    jnz     @f                                          ; of the input text
    mov     IBSCText(ib),OFFSET msg2                    ; IBSCText  - macro setting the static text
    jmp     @b                                          ; in the input box
@@:
    invoke  MessageBox,0,ADDR buffer,ADDR caption2,MB_OK
    invoke  ExitProcess,0

END start

[attachment deleted by admin]

Vortex

The batch file Build.bat was pointing an incorrect build environment. It's fixed now. New upload at the top.

Vortex

Simplified InputBox function eliminating the INPUTBOX structure :

InputBox    PROTO   IB_SCText:DWORD,\   ; text to be displayed in the input box
                    IB_Caption:DWORD,\  ; title of the input box
                    IB_Buffer:DWORD,\   ; buffer to receive the input text
                    IB_xpos:DWORD,\     ; x coordinate in dialog box units
                    IB_ypos:DWORD       ; y coordinate in dialog box units



QuoteReturn values   :
                    If the function succeeds, the return value is the length of the input text
                    If the function fails, the return value is -1

The revised demo code :

include     Demo.inc

IB_XPOS     equ 300
IB_YPOS     equ 250

.data
caption     db 'GeneSys Input Box',0
caption2    db 'Your name is',0
msg         db 'Please enter your name',0
msg2        db 'Sorry, you did not type your name',13,10
            db 'Please try again',0
message     dd  OFFSET msg

.data?

buffer      db 100 dup(?)

.code

start:

    invoke  InputBox,message,ADDR caption,ADDR buffer,IB_XPOS,IB_YPOS
    test    eax,eax
    jnz     @f
    mov     message,OFFSET msg2
    jmp     start
@@:
    invoke  MessageBox,0,ADDR buffer,ADDR caption2,MB_OK
    invoke  ExitProcess,0

END start

[attachment deleted by admin]

PBrennick

The GeneSys Project is available from:
The Repository or My crappy website

Vortex

Hi Paul,

Thanks for your kind words.

Vortex

Added an extra parameter to receive the number of characters typed in the input box :

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

; Return values :

;             If the user clicks the OK button, the return value is 1
;             If the user clicks the cancel button, the return value is 0
;             The number of characters received to the input box


Demo.asm :

include      Demo.inc

IB_XPOS      equ 300
IB_YPOS      equ 250

.data
caption      db 'GeneSys Input Box',0
caption2     db 'Your name is',0
msg          db 'Please enter your name',0
msg2         db 'Sorry, you did not type your name',13,10
             db 'Please try again',0
message      dd OFFSET msg

.data?

buffer       db 100 dup(?)
StrLen       dd ?

.code

start:

      invoke InputBox,message,ADDR caption,ADDR buffer,IB_XPOS,IB_YPOS,ADDR StrLen
      test   eax,eax
      jz     finish
      mov    eax,StrLen
      test   eax,eax
      jnz    @f
      mov    message,OFFSET msg2
      jmp    start
@@:
      invoke MessageBox,0,ADDR buffer,ADDR caption2,MB_OK

finish:

      invoke ExitProcess,0

END start

[attachment deleted by admin]