.486P

LOCALS

JUMPS

.MODEL FLAT, STDCALL			 



UNICODE = 0				; Used in w32.inc

INCLUDE W32.inc				; Windows definitions, messages, errors, structures,

					; API functions declarations, and so on.  Very useful.

					; Thanks to Barry Kauler and Sven Schreiber.				; by Net Walker!



;**********************************************************

;******		    RESOURCE IDENTIFIERS             ******

;/********************************************************\

DLG_0100	equ	100

;ID_GB1		equ	200

;ID_GB2		equ	201

ID_NAME		equ	202

ID_SERIAL	equ	203

IDI_ICON1  	equ     300

;\********************************************************/



.DATA



;**************************************

;***     SOME GENERAL HANDLERS      ***

;/************************************\



hInst		DD	0

hMain		DD	0

hNAME		DD	0

hSERIAL		DD	0



;**************************************

;***           STRINGS              ***

;/************************************\

szClassName	DB	"BIGMOM",0



;**************************************

;***           STRUCTURES           ***

;/************************************\



wc		WNDCLASSEX		<0>

msg		MSG			<0>	



;**************************************

;***            OTHERS              ***

;/************************************\



InputName	db	40 dup (0)

Serial1		db	82 dup (0)

Serial2		db	82 dup (0)

MoreLetters	db	"Ups, Minimum is two characters",0

ZeroString	db	0,0



.CODE



;**********************************************************

;******		      INITIALIZATION                 ******

;/********************************************************\



start:



; First of all, get the ModuleHandle - needed for most functions



	call 	GetModuleHandle, NULL

	mov	hInst, eax



; initialize the WndClass structure 

; Actually, we get the window class from a DIALOG (with CLASS directive) in the resource



	mov	wc.wc_cbSize, WNDCLASSEX_

	mov	wc.wc_style, CS_HREDRAW + CS_VREDRAW 

	mov	wc.wc_lpfnWndProc, offset WinMain

	mov	wc.wc_cbClsExtra, 0

	mov	wc.wc_cbWndExtra, DLGWINDOWEXTRA	; this is needed to use a dialogbox as

							; a window class

	mov	eax, hInst

	mov	wc.wc_hInstance, eax



; load main icon from resource



	call 	LoadIcon, hInst, IDI_ICON1

	mov	wc.wc_hIcon, eax

	mov	wc.wc_hIconSm, eax



; load a default cursor



  	call 	LoadCursor,NULL, IDC_ARROW

	mov	wc.wc_hCursor, eax

	

	mov	wc.wc_hbrBackground, COLOR_BACKGROUND

	mov	wc.wc_lpszMenuName, NULL

	mov	wc.wc_lpszClassName, OFFSET szClassName



  	call 	RegisterClassEx, OFFSET wc



; create window, or better, the dialogbox that will work as the main window



	call	CreateDialogParam, hInst, offset szClassName, 0, NULL, 0

	mov	hMain, eax



; get child control handles



	call 	GetDlgItem, hMain, ID_NAME

	mov	dword ptr [hNAME], eax



	call 	GetDlgItem, hMain, ID_SERIAL

	mov	dword ptr [hSERIAL], eax





	call	SetFocus, [hNAME]

	

	

;**********************************************************

;******		       MESSAGE LOOP                  ******

;/********************************************************\



msg_loop:

    	call 	GetMessage, OFFSET msg, 0,0,0

	cmp	ax, 0

        je      end_loop

	call	IsDialogMessage, hMain, offset msg	; put this if you want to let the 

	cmp	eax, TRUE				; system handle TAB, ENTER, etc

	jz	msg_loop



    	call 	TranslateMessage, OFFSET msg

    	call 	DispatchMessage, OFFSET msg

	jmp	msg_loop



end_loop:

    call 	ExitProcess, msg.ms_wParam

; we never get at this point



;**********************************************************

;******		         WINMAIN                     ******

;/********************************************************\



WinMain PROC USES ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD

	

	cmp	wmsg, WM_DESTROY

	jz	wmdestroy

	cmp	wmsg, WM_COMMAND

	jz	wmcommand

	call 	DefWindowProc, hwnd,wmsg,wparam,lparam

	jmp 	finish

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

wmcommand: 

@@1:	cmp	wparam, IDOK

	jnz	@@2

	call	MakeSerial

@@2:	

	jmp	finish    

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

wmdestroy:

        call    PostQuitMessage, 0

        mov     eax, 0

        jmp     finish

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



finish:

	ret

	

WinMain ENDP



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

MakeSerial	PROC





;We convert the entered name to uppercase,

;and write it back to the edit control



	call	GetWindowText, [hNAME], offset InputName, 30

	mov	esi, offset InputName

	call	strlen				;And get length of string to ebx, must be => 2 chars

	cmp	eax, 2

	jge	ms_0

	call	SetWindowText, [hSERIAL], offset MoreLetters



	call	SetWindowText, [hNAME], offset ZeroString  ;If below 2 chars, clear name edt and show error

	call	SetFocus, [hNAME]

	ret	

	

ms_0:	

	mov	eax,  offset offset InputName

	call	strupc

	call	SetWindowText, [hNAME], offset InputName



	cld	

	mov	esi, offset InputName		;Now we convert every entered char to

	mov	edi, offset Serial1		;its equvalient integer value

ms_1:	lodsb

	or	al, al

	jz	ms_2

	xor	ah, ah

	call	print_dec_16b

	jmp	ms_1



ms_2:	stosb					;terminate string with a zero



	mov	esi, offset Serial1

	call	strlen				;And get length of string to ebx

	mov	ebx, eax



	mov	esi, offset Serial1

	mov	edi, offset Serial2

	dec	ebx

	

	mov	al, [esi+ebx]			;Last char to first char

	stosb

	mov	al, [esi]			;First char to second char

	stosb



ms_3:	

	dec	ebx

	mov	al, [esi+ebx]			;Now we copy backward from Length-2 down to 1

	stosb

	cmp	ebx, 1

	jne	ms_3

	xor	al, al

	stosb



	call	SetWindowText, [hSERIAL], offset Serial2

	ret



MakeSerial	ENDP

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

strupc	proc



	mov	edi, eax

	mov	esi, edi

upcl0:	lodsb

	or	al, al

	jz	upcl3

	cmp	al, 'a'

	jl	upcl2

	cmp	al, 'z'

	jg	upcl2

	sub	al, 'a'-'A'

upcl2:	stosb

	jmp	upcl0

upcl3:	stosb

	ret



strupc	endp

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

print_dec_16b	proc



	mov	bx,ax

	xor	eax,eax

	mov	ax,bx

	mov	ebx,10

	xor	ecx,ecx

p6dl1:	xor	edx,edx

	div	ebx

	push	edx

	inc	ecx

	or	eax,eax

	jne	p6dl1

p6dl2:	pop	edx

	add	dl,'0'

	mov	al,dl

	stosb

	dec	ecx

	jnz	p6dl2

;	xor	al,al

;	stosb

	ret

	

print_dec_16b	endp	

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

strlen proc



	xor	ecx, ecx

	dec	ecx

strln0:	lodsb

	inc	ecx

	or	al,al

	jnz	strln0

	mov	eax, ecx

	ret



strlen	endp

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



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

ends

end start