News:

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

Need chelp witch reding and writing in edit

Started by Gregrin, January 11, 2009, 01:44:36 AM

Previous topic - Next topic

Gregrin

Hello.
I'm writing a calculator in masm32. I read the iczelion guide and I made gui for my prog (it will be operating on binary values) and i wondering how to get numbers from edit and how to write in it.
In iczelion guide i find how to do this but only on strings. How can i content of edit write in for exaple in EAX ?? and how from EAX write it into edit ??

And how make impossible to write in edit other digits than 0 and 1 ??

EDIT: In iczelion examples (tutorial 6)was showed how to check what key was pressed. I was trying modyfy iczelion example to check what key was presed in edit box but it's still checking main windows :/ What I'm doing wrong ??

.386

.MODEL FLAT, STDCALL

OPTION CASEMAP:NONE

WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD

INCLUDE    \masm32\include\windows.inc
INCLUDE    \masm32\include\user32.inc
INCLUDE    \masm32\include\kernel32.inc
INCLUDE    \masm32\include\gdi32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDELIB \masm32\lib\gdi32.lib

.DATA
ButtonID    EQU 1
EditID      EQU 2
hwndEdit    HWND      ?
hwndButton  HWND      ?

MenuName        DB "FirstMenu",0
ButtonClassName DB "button",0
ButtonText      DB "Nasz pierwszy przycisk",0
EditClassName   DB "edit",0
TestString      DB "Och! Jestem w edytorze",0


ClassName DB "SimpleWinClass",0
AppName   DB "Tekst z klawiatury",0
MsgBoxCaption DB "Kurs Iczeliona. Rozdział nr 2",0
MsgBoxText    DB "Asembler Win32 jest Wspaniały!",0

char WPARAM 20h

.DATA?

hInstance   HINSTANCE ?
CommandLine LPSTR     ?

.CODE

start:
INVOKE GetModuleHandle, NULL
mov    hInstance, eax
INVOKE GetCommandLine
mov    CommandLine, eax
INVOKE WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
INVOKE ExitProcess, eax

WinMain PROC hInst:     HINSTANCE,\
             hPrevInst: HINSTANCE,\
             CmdLine:   LPSTR,\
             CmdShow:   DWORD

LOCAL wc:   WNDCLASSEX
LOCAL msg:  MSG
LOCAL hwnd: HWND

mov    wc.cbSize, SIZEOF WNDCLASSEX
mov    wc.style, CS_HREDRAW OR CS_VREDRAW
mov    wc.lpfnWndProc, OFFSET WndProc
mov    wc.cbClsExtra, NULL
mov    wc.cbWndExtra, NULL
push   hInst
pop    wc.hInstance
mov    wc.hbrBackground, COLOR_WINDOW+1
mov    wc.lpszMenuName, NULL
mov    wc.lpszClassName, OFFSET ClassName
INVOKE LoadIcon, NULL, IDI_APPLICATION
mov    wc.hIcon, eax
mov    wc.hIconSm, eax
INVOKE LoadCursor, NULL, IDC_ARROW
mov    wc.hCursor, eax
INVOKE RegisterClassEx, ADDR wc
INVOKE CreateWindowEx, NULL, ADDR ClassName, ADDR AppName,\
           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,\
           CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,\
           hInst, NULL
mov    hwnd, eax
INVOKE ShowWindow, hwnd, SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE
        INVOKE GetMessage, ADDR msg, NULL, 0, 0
        .BREAK .IF (!eax)
        INVOKE TranslateMessage, ADDR msg
        INVOKE DispatchMessage,  ADDR msg
.ENDW
mov eax, msg.wParam
ret
WinMain ENDP

WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL hdc: HDC
LOCAL ps:  PAINTSTRUCT

.IF uMsg==WM_DESTROY
INVOKE PostQuitMessage, NULL
    .ELSEIF uMsg==WM_CREATE
        INVOKE CreateWindowEx, WS_EX_CLIENTEDGE,\
                               ADDR EditClassName, NULL,\
                               WS_CHILD OR WS_VISIBLE OR\
                               WS_BORDER OR ES_LEFT OR\
                               ES_AUTOHSCROLL,\
                               50, 35, 200, 25, hWnd,\
                               EditID, hInstance, NULL
        mov    hwndEdit, eax
       ; INVOKE SetFocus, hwndEdit
        INVOKE CreateWindowEx, NULL,\
                               ADDR ButtonClassName, ADDR ButtonText,\
                               WS_CHILD OR WS_VISIBLE OR BS_DEFPUSHBUTTON,\
                               50, 70, 200, 25, hWnd, ButtonID,\
                               hInstance, NULL
        mov    hwndButton, eax
    .ELSEIF uMsg==WM_CHAR
        push   wParam
        pop    char
  .if (char > 20h)
  INVOKE MessageBox, NULL, ADDR MsgBoxText, ADDR MsgBoxCaption, MB_OK
  .endif
        INVOKE InvalidateRect, hWnd, NULL, TRUE
    .ELSEIF uMsg==WM_PAINT
        INVOKE BeginPaint, hWnd, ADDR ps
        mov    hdc, eax
        INVOKE TextOut, hdc, 0, 0, ADDR char, 1
        INVOKE EndPaint, hWnd, ADDR ps
    .ELSE
        INVOKE DefWindowProc, hWnd, uMsg, wParam, lParam
        ret
    .ENDIF

    xor eax, eax
    ret

WndProc ENDP


END start

thomas_remkus


Mark Jones

#2
Quote from: Gregrin on January 11, 2009, 01:44:36 AM
...how to get numbers from edit and how to write in it. In iczelion guide i find how to do this but only on strings. How can i content of edit write in for exaple in EAX ?? and how from EAX write it into edit ??

Hello Gregrin. As Thomas has mentioned, you can use GetWindowText to retrieve the contents of your edit box. Since the user can only write string data into the box, this is only what can be read from it. Therefore, the text typed into it is being read as string characters, not a numeric value. To convert these characters into numeric digits, the MASM32 library includes the function "atodw", or ASCII to DWORD. Feed this the string of characters, and it will produce a numeric DWORD result in EAX. i.e.:


.DATA
szMyString db "87654321",0
.CODE
invoke atodw,addr szMyString
; eax now contains the value 05397FB1h
; which is exactly 87654321 in decimal.


QuoteAnd how make impossible to write in edit other digits than 0 and 1 ??

Long story short, to do this you need to subclass the edit control. Please see the folder \masm32\examples\exampl01\filtinpt for an example.

Note, if you wish to allow the user to input "0101110011000101011" and convert this to binary, then ATODW will not work (it will read the string as a decimal number.)

To convert an ASCII binary string to a value, see the attachment in this thread. ("0101110011000101011" = 2E62Bh = 189995...)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08