News:

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

MasmLib GetTextInput needs ES_AUTOHSCROLL

Started by jj2007, September 21, 2008, 09:10:12 PM

Previous topic - Next topic

jj2007

I wanted to give the MasmLib GetTextInput the ES_AUTOHSCROLL style, simply because the edit field is not wide enough to hold a long URL. So I tried my luck:

  invoke SetTimer, hWnd, 4321, 500, CbTimer
  invoke GetTextInput, hOwn, hInstance, 0, pApp, offset txHyMsg, esi


In the timer callback:

invoke FindWindowEx, 0, 0, 8002h, chr$("RichMasm")
.if eax
push esi
mov esi, eax
invoke FindWindowEx, eax, 0, chr$("Edit"), 0
mov hEdit, eax
sm eax, WM_SETTEXT, 0, chr$("This is a pretty looooooong URL, I wonder if it fits into the edit field")
workaround = 1
if workaround
invoke GetClientRect, hEdit, addr rc
mov ecx, rc.right
add ecx, 400
invoke SetWindowPos, hEdit, 0, 0, 0, ecx, rc.bottom, SWP_NOMOVE or SWP_NOZORDER
else
invoke GetWindowLong, hEdit, GWL_STYLE
or eax, ES_AUTOHSCROLL
invoke SetWindowLong, hEdit, GWL_STYLE, eax
endif
pop esi
; .else
; invoke MessageBox, 0, chr$("Not found, sorry!"), chr$("Title"), MB_OK
.endif


The problem: It simply ignores my attempts to change the style. I tried all combinations of GWL_STYLE, EXSTYLE etc but no success. And the source code is not available... what the heck is going wrong here?
P.S: workaround = 1 works like a charm, but the edit field is partly obscured by the OK and Cancel buttons. Too ugly.

hutch--

JJ,

Its in the m32lib directory as gettext.asm. Just tweak the source or better still copy it and chnge whtever you like, thats why the source is there.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Thanxalot, Hutch. I had done a search in that folder but apparently overlooked it :red

jj2007

#3
Quote from: hutch-- on September 21, 2008, 11:19:15 PM
JJ,

Its in the m32lib directory as gettext.asm. Just tweak the source or better still copy it and chnge whtever you like, thats why the source is there.

That was easy. In case somebody else is interested:

MyGetTextInput PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
GetTextProc PROTO :DWORD,:DWORD,:DWORD,:DWORD


MyGetTextInput proc hParent:DWORD,
Instance:DWORD, Icon:DWORD, caption:DWORD,
subcaption:DWORD, lpbuffer:DWORD

  Dialog  "0","MS Sans Serif", 8+3,\
          WS_OVERLAPPED or WS_SYSMENU or DS_CENTER,\
          4, 0, 0, 270, 50, 1024

  DlgEdit WS_TABSTOP or WS_BORDER or ES_AUTOHSCROLL, 10, 12, 200, 12, 101
  DlgButton "OK", WS_TABSTOP, 220, 5, 40, 12, IDOK
  DlgButton "Cancel", WS_TABSTOP, 220, 19+2, 40, 12, IDCANCEL
  DlgStatic "0", SS_CENTER, 10, 3, 200, 9, 100

  CallModalDialog Instance, hParent, GetTextProc, ADDR hParent

  ret

MyGetTextInput endp


I increased the font size (8+3) and added or ES_AUTOHSCROLL. No need to include GetTextProc from the original source, it works like shown above. However, if you want to have the editbox prefilled, then do include the GetTextProc and change as follows:
...
      invoke GetDlgItem,hWin,101
      mov hEdit, eax
      invoke SetWindowText, eax, [esi+20]    ; prefill editbox with lpbuffer contents
      invoke SetFocus,hEdit
...

I have used this to enhance the Ctrl K insert hyperlink feature in RichMasm: The editor checks if the clipboard contains a text starting with http; if yes, the editbox is prefilled with the URL.

jj2007

I have worked a bit on GetTextInput and managed to

- give it the ES_AUTOHSCROLL style, e.g. for pasting long URLs
- add a prefilling feature, i.e. it displays the buffer contents
- cut it down almost 100 bytes :wink

However, since the buffer must be explicitly cleared if you want it to be empty, see example below, I felt it was better to change the name to InputBox, so that it will not break existing code.

include \masm32\include\masm32rt.inc

InputBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
InputBoxProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data?
hInstance dd ?
hWnd dd ?
ProcSize dd ?

.code
AppName db "New InputBox:", 0

start:
invoke GetModuleHandle, 0 ; provides the instance handle
mov hInstance, eax
invoke GetDesktopWindow
mov hWnd, eax
mov ProcSize, offset ibL2-InputBox
call TestMe
exit

TestMe proc
LOCAL buffer[1024]:BYTE

mov byte ptr buffer, 0 ; you MUST clear the buffer if you want it empty
invoke InputBox, hWnd, hInstance, 0, addr AppName,
chr$("An empty box - type something, or press Cancel:"), addr buffer

invoke lstrcpy, addr buffer, chr$("http://www.masm32.com/board/index.php?action=unread")
invoke InputBox, hWnd, hInstance, 0, addr AppName,
chr$("Put a loooong URL here:"), addr buffer

invoke lstrcpy, addr buffer, str$(ProcSize)
invoke InputBox, hWnd, hInstance, 0, addr AppName,
chr$("The size of the InputBox in bytes:"), addr buffer

  ret
TestMe endp

InputBox proc hParent:DWORD,
Instance:DWORD, Icon:DWORD, caption:DWORD,
subcaption:DWORD, lpbuffer:DWORD

  Dialog "0", "MS Sans Serif", 10,\
          WS_OVERLAPPED or WS_SYSMENU or DS_CENTER,\
          4, 0, 0, 270, 50, 1024 ; 4 is # of controls

  DlgEdit WS_TABSTOP or WS_BORDER or ES_AUTOHSCROLL,\
10, 12, 200, 12, 101
  DlgButton "OK", WS_TABSTOP, 220, 5, 40, 12, IDOK
  DlgButton "Cancel", WS_TABSTOP, 220, 19+2, 40, 12, IDCANCEL
  DlgStatic "0", SS_CENTER, 10, 3, 200, 9, 100

  CallModalDialog Instance, hParent, InputBoxProc, addr hParent

  ret
InputBox endp
ibL1:

InputBoxProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL hEdit:DWORD
LOCAL ps:PAINTSTRUCT
LOCAL rct:RECT

    .if uMsg == WM_INITDIALOG
      invoke SetWindowLong, hWin, GWL_USERDATA, lParam

      push esi
      mov esi, lParam

    ; -------------------- set the window icon --------------------
mov eax, [esi+8] ; icon slot
.if eax==0
invoke LoadIcon, 0, IDI_ASTERISK ; no icon, set default
.endif
invoke SendMessage, hWin, WM_SETICON, 1, eax

    ; ----------------------- set the window caption -----------------------
mov eax, [esi+12] ; caption slot
.if eax==0
mov eax, chr$("Get Text") ; no caption, set default
.endif
invoke SetWindowText, hWin, eax ; set caption

    ; ----------------------- set the sub-caption -----------------------
      invoke GetDlgItem, hWin, 100
      invoke SetWindowText, eax, [esi+16] ; sub-caption, may be empty

    ; ----------------------- fill editbox and set focus -----------------------
invoke GetDlgItem, hWin, 101
push eax ; mov hEdit, eax
invoke SetWindowText, eax, [esi+20] ; prefill
pop eax
invoke SetFocus, eax ; eax=hEdit

      pop esi

    .elseif uMsg == WM_PAINT
invoke GetClientRect, hWin, ADDR rct
invoke BeginPaint, hWin, ADDR ps
mov ecx, eax ; shorter than mov hDC, eax
invoke DrawEdge, ecx, ADDR rct, EDGE_ETCHED, BF_RECT
invoke EndPaint, hWin, ADDR ps

    .elseif uMsg == WM_COMMAND
      .if wParam == IDOK
invoke GetDlgItem, hWin, 101
mov hEdit, eax
invoke GetWindowTextLength, hEdit ; test if zero length
test eax, eax
je @F
inc eax
push eax ; was mov tl, eax, inc tl (6 bytes, now 2)
invoke GetWindowLong, hWin, GWL_USERDATA ; get buffer address
pop ecx
invoke SendMessage, hEdit, WM_GETTEXT, ecx, [eax+20] ; write edit text to buffer
jmp gtpExit
      @@:
invoke SetFocus, hEdit

      .elseif wParam == IDCANCEL
invoke GetWindowLong, hWin, GWL_USERDATA ; get buffer address
mov eax, [eax+20]
mov BYTE PTR [eax], 0 ; set 1st byte in buffer to zero
jmp gtpExit

      .endif

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

    .endif

    xor eax, eax
    ret
InputBoxProc endp
ibL2:

end start