News:

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

Main Menu

Store User input thru a message box

Started by Magnum, December 11, 2012, 12:35:23 PM

Previous topic - Next topic

Magnum

I was looking for an example to take a string input into a message box and store it in a buffer.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

you probably just want a dialog with an edit control (possibly a combo box)
you can make one pretty easily in resource

dedndave

in the asm source, use DialogBoxParam and a DlgProc

;##################################################################

#define  IDW_DLG                100
#define  IDC_STATIC             101
#define  IDC_COMBO              102
#define  IDC_BUTTON             103

;##################################################################

IDW_DLG DIALOG 0,0,190,115
STYLE   WS_VISIBLE|WS_CLIPCHILDREN|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|DS_CENTER|DS_MODALFRAME
CAPTION " Dialog With Combo Box"
FONT    8,"MS Sans Serif"
BEGIN
  LTEXT      "",IDC_STATIC,10,10,168,34
  CONTROL    "",IDC_COMBO,"ComboBox",WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWN|WS_TABSTOP,10,30,168,40
  PUSHBUTTON "Ok",IDC_BUTTON,66,66,57,17
END

;##################################################################

Magnum

I found this in the examples. It looks like the minimum I will need.

I will study and see how I can integrate this into my fixer program.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

      .486                      ; create 32 bit code
      .model flat, stdcall      ; 32 bit memory model
      option casemap :none      ; case sensitive

      include \masm32\include\dialogs.inc
      include nested.inc

      dlgproc       PROTO :DWORD,:DWORD,:DWORD,:DWORD
      GetText       PROTO :DWORD,:DWORD,:DWORD
      GetTextProc   PROTO :DWORD,:DWORD,:DWORD,:DWORD

    .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:

      mov hInstance, FUNC(GetModuleHandle,NULL)
      mov hIcon,     FUNC(LoadIcon,hInstance,500)

      call main

      invoke ExitProcess,eax

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL lpArgs:DWORD

    invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT, 32
    mov lpArgs, eax

    push hIcon
    pop [eax]

    Dialog "Nested Dialogs","MS Sans Serif",10, \         ; caption,font,pointsize
            WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \     ; style
            4, \                                            ; control count
            50,50,150,80, \                                 ; x y co-ordinates
            1024                                            ; memory buffer size

    DlgButton "Test",WS_TABSTOP,112,4,30,10,IDOK
    DlgButton "Cancel",WS_TABSTOP,112,15,30,10,IDCANCEL
    DlgStatic 'Click on  "Test"  to run nested dialog',SS_CENTER,3,35,140,9,100
    DlgIcon   500,10,10,101

    CallModalDialog hInstance,0,dlgproc,ADDR lpArgs

    invoke GlobalFree, lpArgs

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    LOCAL buffer:DWORD

    .if uMsg == WM_INITDIALOG
      invoke SetWindowLong,hWin,GWL_USERDATA,lParam
      mov eax, lParam
      mov eax, [eax]
      invoke SendMessage,hWin,WM_SETICON,1,[eax]

    .elseif uMsg == WM_COMMAND
      .if wParam == IDOK
        invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT, 32
        mov buffer, eax
        invoke GetWindowLong,hWin,GWL_USERDATA
        mov ecx, [eax]
        invoke GetText,hWin,[ecx],buffer
        mov ecx, buffer
        cmp BYTE PTR [ecx], 0
        je @F
        invoke MessageBox,hWin,buffer,SADD("You typed ..."),MB_OK
        jmp nxt
      @@:
        invoke MessageBox,hWin,SADD("You did not enter any text"),
                               SADD("No text to display"),MB_OK
      nxt:
        invoke GlobalFree,buffer

      .elseif wParam == IDCANCEL
        jmp quit_dialog
      .endif

    .elseif uMsg == WM_CLOSE
      quit_dialog:
      invoke EndDialog,hWin,0

    .endif

    xor eax, eax
    ret

dlgproc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

GetText proc hParent:DWORD,lpIcon:DWORD,buffer:DWORD

    Dialog "Enter Text","MS Sans Serif",10, \               ; caption,font,pointsize
            WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \     ; style
            4, \                                            ; control count
            0,0,200,45, \                                   ; x y co-ordinates
            1024                                            ; memory buffer size

    DlgEdit     WS_TABSTOP or WS_BORDER,28,12,125,10,100
    DlgButton   "OK",WS_TABSTOP,160,4,30,10,IDOK
    DlgButton   "Cancel",WS_TABSTOP,160,15,30,10,IDCANCEL
    DlgIcon     500,5,5,101

  ; --------------------------------------------------------
  ; the use of "ADDR hParent" is to pass the address of the
  ; stack parameters in this proc to the proc being called.
  ; --------------------------------------------------------
    CallModalDialog hInstance,hParent,GetTextProc,ADDR hParent

    ret

GetText endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

GetTextProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    LOCAL buffer:DWORD
    LOCAL hEdit :DWORD
    LOCAL tl    :DWORD

    .if uMsg == WM_INITDIALOG
    ; -----------------------------------------
    ; write the parameters passed in "lParam"
    ; to the dialog's GWL_USERDATA address.
    ; -----------------------------------------
      invoke SetWindowLong,hWin,GWL_USERDATA,lParam
      mov eax, lParam
      mov eax, [eax+4]
      invoke SendMessage,hWin,WM_SETICON,1,eax

    .elseif uMsg == WM_COMMAND
      .if wParam == IDOK
        invoke GetDlgItem,hWin,100
        mov hEdit, eax
        invoke GetWindowTextLength,hEdit
        cmp eax, 0
        je @F
        mov tl, eax
        inc tl
        invoke GetWindowLong,hWin,GWL_USERDATA      ; get buffer address
        mov ecx, [eax+8]                            ; put it in ECX
        invoke SendMessage,hEdit,WM_GETTEXT,tl,ecx  ; write edit text to buffer
        jmp Exit_Find_Text

      @@:
        invoke SetFocus,hEdit

      .elseif wParam == IDCANCEL
        jmp Exit_Find_Text
      .endif

    .elseif uMsg == WM_CLOSE
      Exit_Find_Text:
      invoke EndDialog,hWin,0

    .endif

    xor eax, eax
    ret

GetTextProc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

that's the idea
Bill Cravener has a lot of nice dialog-from-resource type examples
he always writes easy to follow code   :t

the reason i mentioned DialogBoxParam is that is one of the ways to create a "modal" dialog - like a MessageBox

Vortex


jj2007

Pure assembler ;)

include \masm32\MasmBasic\MasmBasic.inc             ; download
  Init
DlgDefine "Dialogs are easy:", 0, 0, 150, -2, , 14        ; xy centered, width in pixels, two rows, , font size
  DlgControl dcEdit,        "Magnum", WS_BORDER or WS_TABSTOP, 1, -2        ; x, row 2
  DlgControl dcStatic,        "Type your name:", SS_LEFT, 1, -1, 70.0                     ; 70 means 70% - the buttons need space
  DlgControl dcButton,        "OK", BS_DEFPUSHBUTTON or WS_TABSTOP, 71.0, -1, 12.0, , IDOK             ; x=71%, y, width=12%, height, ID
  DlgControl dcButton,        "Quit", BS_PUSHBUTTON or WS_TABSTOP, 84.0, -1, 16.0, , IDCANCEL
  DlgShow
  .if eax==IDOK
        wMsgBox 0, Dlg$(0), "Write your name to test.txt?", MB_YESNO
        .if eax==IDYES
                FileWrite "test.txt", Utf8$(Dlg$(0))        ; convert Unicode to Ansi and write to a text file
        .endif
  .endif
  Exit
end start

Magnum

This is a screen of what your code made.

It does give me the screen co-ordinates while showing where my cursor is.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

Yes indeed. If you need client coordinates, either move your window to (0,0) or translate the coordinates. You meant the code in the other thread, by the way ;-)