All pastes #830507 Raw Edit

Anonymous

public text v1 · immutable
#830507 ·published 2007-12-24 00:37 UTC
rendered paste body
                .386
                .MODEL FLAT,STDCALL
                locals
                jumps

                UNICODE = 0             ; Not Unicode

                include \w32\w32.inc


                IDC_STATIC      equ    -1
                IDD_DIALOG1     equ   103
                IDD_DIALOG2     equ   104
                IDI_ICON        equ   105
                ICON_SMALL      equ     0

                ID_but0         equ  2000
                ID_but1         equ  2001
                ID_but2         equ  2002
                ID_but3         equ  2003
                ID_but4         equ  2004
                ID_but5         equ  2005
                ID_but6         equ  2006
                ID_but7         equ  2007
                ID_but8         equ  2008
                ID_but9         equ  2009
                ID_butMult      equ  2010
                ID_butDiv       equ  2011
                ID_butPlus      equ  2012
                ID_butMinus     equ  2013
                ID_butPoint     equ  2014
                ID_butNeg       equ  2015
                ID_butEqu       equ  2016
                ID_butCE        equ  2017
                ID_butAC        equ  2018
                ID_EDIT1        equ  2020


                IDM_NEW         equ  4000
                IDM_ABO         equ  4001
                IDM_EXIT        equ  4002

.DATA

;[--------==========================================================--------];

_hInst          dd ?                    ;the hInst
_hWnd           dd ?                    ;Window Handle
_hIcon		dd ?

fmat1           db "%lu", 0             ; Unsigned decimal long.
fmat2           db "%lX", 0             ; Hexadecimal long.

_msg            MSG             <?>     ;The message Structure
_pnt            PAINTSTRUCT     <?>
DlgRect         RECT            <>
DlgWidth        dd              ?
DlgHeight       dd              ?
DesktopRect     RECT            <>

                db 0
tbuff1          db 256 dup(0)
                db 0
tbuff2          db 256 dup(0)
nullbuff        db 0

inedit          dd 0

number1         dq 00.00                ; Number 1
number2         dq 00.00                ; Number 2
operator        db 0                    ; ( '+' '-' '*' '/' )

.CODE

;[--------==========================================================--------];

main:
        mov eax, offset notPt

    call GetModuleHandle, NULL          ; Get the handle to our app
    mov _hinst, eax

    call InitCommonControls

    call DialogBoxParamA, _hinst, IDD_DIALOG1, 0, offset DlgProc, 0

    call ExitProcess                    ; Exit the main process

;[--------==========================================================--------];

    PUBLIC DlgProc

DlgProc proc STDCALL, __hwnd:DWORD, wmsg:DWORD, _wparam:DWORD, _lparam:DWORD
    USES ebx, edi, esi
    mov eax, wmsg
    cmp ax, WM_DESTROY
     je _wmdestroy
    cmp ax, WM_CLOSE
     je _wmdestroy
    cmp ax, WM_COMMAND
     je _wmcommand
    cmp ax, WM_INITDIALOG
     je _initdlg
    cmp ax, WM_PAINT
     je _paint
    xor eax,eax
    ret

;---------------------------------------;
_wmdestroy:
    call EndDialog, __hWnd, 0           ; End the Dialog
    call ExitProcess                    ; Exit Process
    ret
;---------------------------------------;
_wmcommand:
    cmp _wparam, IDM_ABO
     jne nohlp
    call GetModuleHandle, NULL          ; Get the handle to our app
    call DialogBoxParamA, eax, IDD_DIALOG2, __hWnd, offset DlgProc2, 0
nohlp:
    cmp _wparam, IDM_EXIT
     jne noext
    jmp _wmdestroy
noext:
        cmp _wparam, ID_but0
         jb nnumbut
        cmp _wparam, ID_but9
         ja nnumbut
        call GetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1, 256
        mov ebx, _wparam
        sub ebx, ID_but0 - '0'          ; Make ascii
        mov byte ptr [offset tbuff1 + eax], bl
        mov byte ptr [offset tbuff1 + eax + 1], 0
        call SetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1
        xor eax, eax
        ret
nnumbut:cmp _wparam, ID_butCE
         jne notCE
        call SetDlgItemText, __hWnd, ID_EDIT1, offset nullbuff
        xor eax, eax
        ret
notCE:  cmp _wparam, ID_butPoint
         jne notPt
        call GetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1, 256
        mov byte ptr [offset tbuff1 + eax], '.'
        mov byte ptr [offset tbuff1 + eax + 1], 0
        call SetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1
        xor eax, eax
        ret
notPt:  cmp _wparam, ID_butNeg
         jne notNeg
        call GetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1, 256
        or eax, eax
         jz nothneg
        cmp byte ptr [offset tbuff1], '-'
         je neg111
        mov byte ptr [offset tbuff1 - 1], '-'
        call SetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1 - 1
nothneg:xor eax, eax
        ret
neg111: call SetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1 + 1
        xor eax, eax
        ret
notNeg:

;============================================================================;
        cmp word ptr [offset _wparam], ID_EDIT1
         jne noted
        cmp word ptr [offset _wparam + 2], EN_UPDATE
         jne noted
        cmp inedit, 1
         je noted
        mov inedit, 1
        call GetDlgItemText, __hWnd, ID_EDIT1, offset tbuff1, 256
        mov esi, offset tbuff1
        mov edi, offset tbuff2
        cmp byte ptr [esi], '-'
         jne nolead1
        inc esi
        mov byte ptr [edi], '-'
        inc edi
nolead1:
        mov ecx, 0                      ; '.' count
        mov edx, 0                      ; started number yet? (0's)
loip1:  mov al, byte ptr [esi]
        inc esi
        or ecx, ecx
         jnz nyes1                      ; No more '.'s
        cmp al, '.'
         jne nyes1
        mov edx, 1
        mov ecx, 1
        jmp yess1
nyes1:
        cmp al, 0
         je yess1
        cmp al, '0'
         jb nooo1
         jne no0s
        cmp edx, 1
         jne nooo1                      ; Trim off start 0's
no0s:   cmp al, '9'
         ja nooo1
        mov edx, 1
yess1:  mov byte ptr [edi], al
        inc edi
nooo1:  cmp al, 0
         jne loip1
        call SetDlgItemText, __hWnd, ID_EDIT1, offset tbuff2

        call SendDlgItemMessage, __hWnd, ID_EDIT1, WM_KEYDOWN, VK_END, NULL
        mov inedit, 0
        xor eax, eax
        ret
noted:

    xor eax, eax
    ret


;---------------------------------------; Center dialog, put icon
_initdlg:
    call LoadIcon, _hinst, IDI_ICON     ; Load the Icon
    mov _hIcon, eax                     ; Store Icon handle

    call SendMessage, __hWnd, WM_SETICON, ICON_SMALL, eax       ; Set icon

    call GetWindowRect, __hWnd, offset DlgRect                  ; Get DlgRect

    call GetDesktopWindow
    call GetWindowRect, eax, offset DesktopRect     ; Get Desktop rect

    mov eax, DlgRect.rc_bottom
    sub eax, DlgRect.rc_top
    mov DlgHeight, eax                  ; Dialog box height
    mov eax, DlgRect.rc_right
    sub eax, DlgRect.rc_left
    mov DlgWidth, eax                   ; Dialog box width
    mov ebx, DesktopRect.rc_bottom
    sub ebx, DlgHeight
    shr ebx, 1                          ; ebx = Start y
    mov ecx, DesktopRect.rc_right
    sub ecx, DlgWidth
    shr ecx, 1                          ; ecx = Start x

    call MoveWindow, __hWnd, ecx, ebx, DlgWidth, DlgHeight, 0   ; Centre

    ret
;---------------------------------------;
_paint:
    call BeginPaint, __hWnd, offset _pnt

;    push _hIcon                         ; Icon Handle
;    push 204                            ; Start Y
;    push 10                             ; Start X
;    push eax                            ; The hDc (returned by BeginPaint)
;    call DrawIcon                       ; Draw it
	
    call EndPaint, __hwnd, offset _pnt
    ret
DlgProc endp

;----------------------------------------------------------------------------;

    PUBLIC DlgProc2

DlgProc2 proc STDCALL, __hwnd:DWORD, wmsg:DWORD, _wparam:DWORD, _lparam:DWORD
    USES ebx, edi, esi
    mov eax, wmsg
    cmp ax, WM_DESTROY
     je _wmdestroy2
    cmp ax, WM_CLOSE
     je _wmdestroy2
    cmp ax, WM_COMMAND
     je _wmcommand2
    cmp ax, WM_INITDIALOG
     je _initdlg2
    cmp ax, WM_PAINT
     je _paint2
    xor eax,eax
    ret
;---------------------------------------;
_wmdestroy2:
    call EndDialog, __hWnd, 0           ; End the Dialog
    ret
_paint2:
    call BeginPaint, __hWnd, offset _pnt
    call EndPaint, __hwnd, offset _pnt
    ret
_initdlg2:
    call GetWindowRect, __hWnd, offset DlgRect                  ; Get DlgRect

    call GetDesktopWindow
    call GetWindowRect, eax, offset DesktopRect     ; Get Desktop rect

    mov eax, DlgRect.rc_bottom
    sub eax, DlgRect.rc_top
    mov DlgHeight, eax                  ; Dialog box height
    mov eax, DlgRect.rc_right
    sub eax, DlgRect.rc_left
    mov DlgWidth, eax                   ; Dialog box width
    mov ebx, DesktopRect.rc_bottom
    sub ebx, DlgHeight
    shr ebx, 1                          ; ebx = Start y
    mov ecx, DesktopRect.rc_right
    sub ecx, DlgWidth
    shr ecx, 1                          ; ecx = Start x

    call MoveWindow, __hWnd, ecx, ebx, DlgWidth, DlgHeight, 0   ; Centre
    ret
_wmcommand2:
    cmp _wparam, IDOK
     jne nook
    jmp _wmdestroy2
nook:
    ret
DlgProc2 endp

;[--------==========================================================--------];

jprintf proc p1:dword, p2:dword, p3:dword
    push p3
    push p2
    push p1
    call _wsprintfA
    add esp, 12
    ret
jprintf endp


;---------------------------------------;
ends
    end main