;werds 
.386 
.model flat,stdcall 
option casemap:none 

      include \masm32\include\windows.inc
      include \MASM32\include\masm32.inc
      include \MASM32\include\gdi32.inc
      include \MASM32\include\user32.inc
      include \MASM32\include\kernel32.inc
      include \MASM32\include\Comctl32.inc
      include \MASM32\include\comdlg32.inc
      include \MASM32\include\shell32.inc
      include \masm32\include\shlwapi.inc
      include \MASM32\include\oleaut32.inc

      includelib \MASM32\LIB\masm32.lib

      includelib \MASM32\LIB\gdi32.lib
      includelib \MASM32\LIB\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \MASM32\LIB\Comctl32.lib
      includelib \MASM32\LIB\comdlg32.lib
      includelib \MASM32\LIB\shell32.lib
      includelib \masm32\lib\shlwapi.lib
      includelib \MASM32\LIB\oleaut32.lib
      
      
WinMain 	        PROTO :DWORD,:DWORD,:DWORD,:SDWORD 
wrpButtonBox       PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

wrptxtEditBox	    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
wrpListbox	        PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
wrpResizeListbox   PROTO
wrpGetData	        PROTO
wrpSaveData	    PROTO
wrpPaintbackground PROTO :DWORD
;xtrabits
wrpPaintbackground2    PROTO :DWORD
;xtrabits end
wrpReverseline	    PROTO :DWORD,:DWORD

wrpdCwrdvalidation PROTO :DWORD
wrpsValidation     PROTO :DWORD
wrpsinitValidation     PROTO :DWORD
wrpMakelino            PROTO
wrdpmainwindow          PROTO
wrdpResizeParameters    PROTO
wrdpParameterwindow     PROTO

    wrdmText MACRO Name, Text:VARARG
	   LOCAL lbl
	jmp lbl
	    Name db Text,0
      lbl:
    ENDM
    wrdmRGB macro red,green,blue
	xor    eax,eax
	mov  ah,blue
	shl	eax,8
	mov  ah,green
	mov  al,red
      ; mov eax, myRGB	;  ADD THIS LINE IN AND MESS WITH CONDITIONS BELOW TO CHANGE SCREEN COLOUR 
		  ; NOTE YOU NEED TO ADD A REPAINT FOR SCREEN SOMEWHERE ALSO   
    ENDM    
.const 

IDM_OPEN   equ 1002 
IDM_SAVE   equ 1003
IDM_SAVEAS equ 1004
IDM_MERGE  equ 1005
IDM_EXIT equ 1010 
MAXSIZE  equ 260


.data 

align 4
WS_TOTAL_COUNT dd 110 dup(0)
testeval  db 120 dup(?)
align 4
resbuf db 120 dup(0)
align 4
WERDPARAM_LIMIT   dd 18
smallspace db "  ",0

align 4
initbuf db 120 dup(0)

wrdshowbytype db "v",0
werdpoem0 db " mary had an ugly little pig   ",0
werdpoem1 db " the pig was nere forsaken     ",0
werdpoem2 db " 4 when she came home at night ",0
werdpoem3 db " the pig and she made bacon    ",0
;----------------------------
;component dll
  componentparm       dd 7
  componentreturn     dd 3
  componentmessage    dd "1",0
  componentDllLib     dd 0
  componentmessret    dd 0
  componentmesserror  dd 0
  
    wrdqGetfilesize   QWORD 0		       ; number of bytes actually read or write 
    MEMSIZE	           DWORD 64000 
    SizeReadWrite      DWORD 64 
    wrdlineterminator  dd 200ah
	allfileterminator  dd 0a09h
    Wwd 	      dd 600
    Wht 	      dd 400
    Wtx 	      dd 12
    Wty 	      dd 12
	; test for limiting size of dd item = 9 digits 
	
    wrdListReverse    dd 0    
    wlOutputbuffer     db 4096 dup (0)
    wlWorkBuffer       db 4096 dup (0)
    wlWorkword	       db 32 dup (0)   
    wlValuemessbuffer  db 16 dup (0) 
  
    wrdOpenfilename   OPENFILENAME <> 
    FilterString       db "All Files",0,"*.*",0 
		               db "Text Files",0,"*.txt",0,0 
    wlCFilebuffer      db MAXSIZE dup(0) 
   
    wrdClassName      db "Templateallass",0 
    wrdProgramId      db "Werd Lab",0 
    wrdEditallass     db "edit",0 
    wrdMenuName       db "Main Menu 1",0 
    wrdfilesizemess    db "file size :- ",0  
    wrdfilesizemess2   db " bites ",0
	wrdvbuffer         db 90 dup (0)
	aval               db 12 dup(0)
align 4
  
 wrdvwinid          dd 0
 wrdwindownumber   dd 0

    wrdstartposn    dd 0 
    wrdSCREENSIZE STRUCT
     ;wlcbPercent     dd  80
     ;wlrcOriginal    RECT <>
      wlrcWork	      RECT <>
    wrdSCREENSIZE ENDS	 
    wrdScr   wrdSCREENSIZE <> 
    wrdlbox  RECT <> 
    wrdebox  RECT <> 	
    wrdItemBuffer    db 128 dup (?)
    	  
    testlargest      dd 999999999
    wrwerdlitany      db "list of werds",0
	wrdtruecomp	     db "true werdations",0
    werd  db "werd",0
	badwerd  db "curses",0
     
.data? 
hInstance	   HINSTANCE ? 
CommandLine	   LPSTR ?
hwnd		   HWND ?
hwrpButtonBox HWND ?
hButtonS0      HWND ?
hButtonS1      HWND ?
hButtonS2      HWND ?
hButtonS3      HWND ?
              
hButtonD0      HWND ?
hButtonD1      HWND ?
hButtonD2      HWND ?
hButtonD3      HWND ?

hEditpar0	   HWND ?
hEditpar1	   HWND ?
hEditpar2	   HWND ?
hEditpar3	   HWND ?
hEditpar4	   HWND ?
hEditpar5	   HWND ?
hEditpar6	   HWND ?
hEditpar7	   HWND ?
hEditpar8	   HWND ?
hEditpar9	   HWND ?
hnEdita1	   HWND ?

hList0		   HWND ?	
hList1		   HWND ?	
	   
hFile		   HANDLE ?				  
hMemory 	   HANDLE ?   ;handle to the memory block allocated to the input file
hEditSortSequence	HANDLE ?
hcomponentLib HANDLE ?   ;handle to component dll library


wrdvpMemoryblock    DWORD ?    ; pointer to wrdocated file memory block
wrdvLinecount	    DWORD ? 			   
wrdvBytecount	    DWORD ?

.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:SDWORD 
    LOCAL wc:WNDCLASSEX 
    LOCAL msg:MSG 
   
    LOCAL sWid :DWORD
    LOCAL sHgt :DWORD 


	
    mov   wc.cbSize,SIZEOF WNDCLASSEX 
    mov   wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
    mov   wc.lpfnWndProc, OFFSET WndProc 
    mov   wc.cbClsExtra,NULL 
    mov   wc.cbWndExtra,NULL 
    push  hInst 
    pop   wc.hInstance 
    mov   wc.hbrBackground,COLOR_BTNFACE+1
    mov   wc.lpszMenuName, OFFSET wrdMenuName 
    mov   wc.lpszClassName,OFFSET wrdClassName 
    invoke LoadIcon,hInst,50 
    mov   wc.hIcon,eax 
    mov   wc.hIconSm,eax 
    invoke LoadCursor,NULL,IDC_ARROW 
    mov   wc.hCursor,eax 
    invoke RegisterClassEx, addr wc 
    invoke SystemParametersInfo,SPI_GETWORKAREA,0,ADDR wrdScr.wlrcWork,0
 
    add wrdScr.wlrcWork.left, 20
    add wrdScr.wlrcWork.top,  20
    sub wrdScr.wlrcWork.right,  50
    sub wrdScr.wlrcWork.bottom,	50
    invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW or WS_EX_CONTROLPARENT ,
		 ADDR wrdClassName,
		 ADDR wrdProgramId,
		 WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,
		 wrdScr.wlrcWork.left,wrdScr.wlrcWork.top,\
		 wrdScr.wlrcWork.right,wrdScr.wlrcWork.bottom, 
		 0,0,hInst,0	
	      ;  approx 21,21,900,650,
    mov   hwnd,eax 
    invoke LoadMenu,hInst,600  ; menu ID
    invoke SetMenu,hwnd,eax  
; couple of text edit boxes	
    mov wrdebox.left,20
	mov wrdebox.top,5
	mov wrdebox.right,80
	mov wrdebox.bottom,21
	invoke wrdpmainwindow	
     
    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 


   .if uMsg==WM_COMMAND 
	   mov eax,wParam 
	
       .if (wParam == 400)    

           invoke wrpsinitValidation,wParam 
                     
       .endif  	
	
       .if (wParam == 401) || (wParam == 402)    

           invoke wrpsValidation,wParam 
                     
       .endif  
       
       .if (wParam == 411) || (wParam == 412) 

          invoke wrpMakelino
      
       .endif
	.if lParam==0 
;----------------------------------------- 
; generated using qedit
;----------------------------------------- 
 .if wParam == 1000 ; "Open"
		 invoke wrpGetData
		 invoke SetFocus,hEditpar1 
        

      .elseif wParam == 1002 ; "Save"
		 invoke wrpSaveData
		 invoke SetFocus,hEditpar1 
		 
      .elseif wParam == 1004 ; "Save As"
		 invoke wrpSaveData
		 invoke SetFocus,hEditpar1 
        

      .elseif wParam == 1006 ; "Merge File"
        ; create this to append file or make new file if it doesnt exist...
        

      .elseif wParam == 1099 ; "Exit"
		 invoke SendMessage,hWnd,WM_SYSCOMMAND,SC_CLOSE,NULL	
		 
       .elseif wParam == 1100 ; "Go to param edit screen"
; xtrabits 	   
          mov wrdwindownumber,1
		  invoke SendMessage,InvalidateRect,hwnd,NULL,TRUE
      .elseif wParam == 1102 ; "Return to main screen"
          mov wrdwindownumber,0
		  invoke SendMessage,InvalidateRect,hwnd,NULL,TRUE
; xtrabits end
      .elseif wParam == 1104 ; "Find Text""
      .elseif wParam == 1106 ; "Find Next"
      .elseif wParam == 1108 ; "Select All"
      .elseif wParam == 2100 ; "Component"
            ; -------------------
            ; Direct call the DLL
            ; -------------------
            jmp @F
              libName  db "componentdll.dll",0
              FuncName db "componentProc",0
            @@:
            invoke LoadLibrary,ADDR libName
            mov hcomponentLib, eax
            invoke GetProcAddress,hcomponentLib,ADDR FuncName
            mov componentDllLib, eax
            xor ecx,ecx
            mov ecx,componentreturn
            push ecx
            xor eax,eax
            mov eax,componentparm
            push eax
            call componentDllLib
            mov componentmesserror,eax
            mov componentmessret,ecx 
            invoke dwtoa,componentmesserror,ADDR [componentreturn]
            invoke MessageBox,hWnd,ADDR componentreturn,ADDR FuncName,MB_OK
            invoke FreeLibrary,hcomponentLib
			
      .elseif wParam == 9100 ; "Restart"

        

      .elseif wParam == 9102 ; "Extra Instance"

        

      .elseif wParam == 9104 ; "System Info"

        

      .elseif wParam == 9106 ; "Memory usage"

        

      .elseif wParam == 9108 ; "Handles and processes"

      .elseif wParam == 9900 ; "About"

      .endif	  
;--------------------------------------------	  
	  
	.endif ;end Lparam
	  
  .elseif uMsg==WM_CREATE 
;============================================== 
;	 Initialize the members of OPENFILENAME structure 
;============================================== 
; xtrabits 
	mov wrdwindownumber,0
; xtrabits end	
	mov wrdOpenfilename.lStructSize,SIZEOF wrdOpenfilename 
	push hWnd 
	pop  wrdOpenfilename.hWndOwner 
	push hInstance 
	pop  wrdOpenfilename.hInstance 
	mov  wrdOpenfilename.lpstrFilter, OFFSET FilterString 
	mov  wrdOpenfilename.lpstrFile, OFFSET wlCFilebuffer 
	mov  wrdOpenfilename.nMaxFile,MAXSIZE 
	invoke SendMessage,hList0,LB_INITSTORAGE,10000,100000  
		

  .elseif uMsg==WM_SIZE 
	mov eax,lParam 
	mov edx,eax 
	shr edx,16 ; bottom
	and eax,0ffffh ; right
	mov wrdScr.wlrcWork.right, eax
	mov wrdScr.wlrcWork.bottom, edx
	sub wrdScr.wlrcWork.right,  50
	sub wrdScr.wlrcWork.bottom,  50 
		
	;invoke wrpResizeListbox                          removed this and added the following
; xtrabits 	
	  .if wrdwindownumber == 0
	       
 	      invoke wrpResizeListbox
     .else 
	      invoke wrpPaintbackground2,hwnd
          invoke wrdpParameterwindow
     .endif    
     invoke SendMessage,InvalidateRect,hwnd,NULL,TRUE
; xtrabits end	 
 
  .elseif uMsg==WM_PAINT
	;invoke wrpPaintbackground,hWnd                 removed this and added the following
	
; xtrabits 
      invoke SendMessage,InvalidateRect,hwnd,NULL,TRUE
      .if wrdwindownumber == 0
	     invoke wrpPaintbackground,hwnd
     .else 
	      invoke wrpPaintbackground2,hwnd
     .endif   
; xtrabits end	
 
    .elseif uMsg==WM_CLOSE
	invoke PostQuitMessage,NULL	   
    .elseif uMsg==WM_DESTROY 
	invoke PostQuitMessage,NULL
  .else
       invoke DefWindowProc,hWnd,uMsg,wParam,lParam
  .endif 
    ret
WndProc endp 
wrpButtonBox proc buta:DWORD,butb:DWORD,butwd:DWORD,butht:DWORD,hParent:DWORD,ID:DWORD

    wrdmText butBox,"button"
    
    invoke CreateWindowEx,0,ADDR butBox,0,
                BS_PUSHBUTTON or WS_CHILD or WS_VISIBLE or BS_ICON,
                buta,butb,butwd,butht,hParent,ID,hInstance,NULL
				
    mov   hwrpButtonBox,eax
 
   .if ID > 410
       
       invoke LoadIcon,hInstance,53
   .else
       invoke LoadIcon,hInstance,52
   .endif

    invoke SendMessage,hwrpButtonBox,BM_SETIMAGE,1,eax
	mov eax,hwrpButtonBox
	

    ret

wrpButtonBox endp

wrptxtEditBox proc eBa:DWORD,eBb:DWORD,eBwd:DWORD,eBht:DWORD,hParent:DWORD,ID:DWORD
 


    ; text edit set up .. the one above is for numerics only .. uses same title 
    wrdmText eBox,"edit"
    invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR eBox,0,
		 ES_LEFT or WS_CHILD or  \
		 WS_VISIBLE or WS_BORDER or WS_TABSTOP ,		      
		 eBa,eBb,eBwd,eBht,hParent,ID,hInstance,NULL
    
   
    ret

wrptxtEditBox endp
wrpListbox proc a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,hParent:DWORD,ID:DWORD

    wrdmText lstBox,"Listbox"

    invoke CreateWindowEx,WS_EX_CLIENTEDGE or WS_EX_ACCEPTFILES,
		 ADDR lstBox,0,
		 WS_VSCROLL or WS_VISIBLE or WS_HSCROLL or \
		 WS_BORDER or WS_CHILD or \
		 LBS_DISABLENOSCROLL,
		 a,b,wd,ht,
		 hParent,ID,hInstance,NULL
    
    ret

wrpListbox endp
wrpResizeListbox proc 
    mov wrdlbox.left, 20 
    mov eax, wrdScr.wlrcWork.top 
    shl eax, 3
    mov ecx, eax
    ;shr ecx, 1
    ;add eax, ecx  
   ; shr ecx, 1
    sub eax, 30
    mov wrdlbox.top, eax 
    mov eax, wrdScr.wlrcWork.right
    shr eax, 1
    sub eax, 10 
   .if eax < 85
       mov eax, 85
   .endif	
    mov wrdlbox.right, eax
    mov eax, wrdScr.wlrcWork.bottom
	sub eax, 82
   ; sub eax, 150
    mov wrdlbox.bottom, eax	   
    	
    invoke MoveWindow,hList0,wrdlbox.left,wrdlbox.top,wrdlbox.right,wrdlbox.bottom,TRUE 
	mov eax, wrdlbox.right
	pusha
	invoke SendMessage,hList0,LB_SETHORIZONTALEXTENT,1200,0  
	popa
	add  eax, 20
	add wrdlbox.left, eax
	invoke MoveWindow,hList1,wrdlbox.left,wrdlbox.top,wrdlbox.right,wrdlbox.bottom,TRUE 
    invoke MoveWindow,hButtonS1,wrdlbox.left,83,40,15,TRUE 
	invoke MoveWindow,hButtonD1,wrdlbox.left,105,40,20,TRUE
    invoke MoveWindow,hEditSortSequence,wrdlbox.left,55,70,25,TRUE

    ret

wrpResizeListbox endp

wrpGetData proc 
    mov  wrdOpenfilename.Flags, OFN_FILEMUSTEXIST or\
		OFN_PATHMUSTEXIST or OFN_LONGNAMES or\ 
		OFN_EXPLORER or OFN_HIDEREADONLY 
    invoke GetOpenFileName, ADDR wrdOpenfilename 
   .if eax==TRUE 
       invoke CreateFile,ADDR wlCFilebuffer,\ 
		    GENERIC_READ or GENERIC_WRITE ,\
		    FILE_SHARE_READ or FILE_SHARE_WRITE,\ 
		    0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0
       mov hFile,eax 
       xor eax, eax
       mov eax, offset wrdqGetfilesize
       invoke GetFileSizeEx,hFile,eax
			 
       mov eax, DWORD PTR [wrdqGetfilesize]
       mov MEMSIZE, eax 
				   
       invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
       mov  hMemory,eax 
       invoke GlobalLock,hMemory 
       mov  wrdvpMemoryblock,eax 
       invoke ReadFile,hFile,wrdvpMemoryblock,MEMSIZE,ADDR SizeReadWrite,NULL
; stringing messages example 

; output the file size to the list	
       mov wlOutputbuffer[0], 0 
       invoke szCatStr,ADDR wlOutputbuffer,ADDR wrdfilesizemess
       invoke dw2a,SizeReadWrite,ADDR wlValuemessbuffer
       invoke szCatStr,ADDR wlOutputbuffer,ADDR wlValuemessbuffer
       invoke szCatStr,ADDR wlOutputbuffer,ADDR wrdfilesizemess2 
; by setting the horizontal extent in pixels you can allow hscroll to go as far right as pixel limit 
; other wise it defaults to lb width and you cant necessarily see all of a long line !	     
       invoke SendMessage,hList1,LB_SETHORIZONTALEXTENT,1200,0	     
       invoke SendMessage,hList1,LB_ADDSTRING,0,ADDR wlOutputbuffer 
; avoid zero length reads .. these can occur if there are  memory errors	
       cmp SizeReadWrite, 0
       je wrpGetDataerror
       invoke  GetDlgItemInt, hwnd,400,ADDR wrdListReverse,FALSE
       mov wrdListReverse, eax

; initialise the wlOutputbuffer with a couple of zeros	as im intending to load [asci] numeric data primarily  
       mov wlOutputbuffer[0] , 030h  
       mov wlWorkBuffer[0],0
       push edi
; data loaded in memory in EDX [as its a pointer no offset verb reqd]

       mov edi, offset wlWorkBuffer 
; start position in buffer .. in this case zero 
       xor ecx,ecx
       mov wrdvBytecount, ecx
       mov wrdvLinecount, ecx
   wrpGetDataloop: 
 
       mov eax, wrdvBytecount	  
       cmp eax, SizeReadWrite
       jge wrpGetDataendoloop 
       mov edx, wrdvpMemoryblock 
       add edx, eax	  
       xor eax, eax 
;pre add so set counter to -1	 
       mov ecx, -1		   
       jmp wrpGetDatastart
  align 4
  wrpGetDatapre:
       mov [edi+ecx], al	   ; write BYTE to buffer
  wrpGetDatastart:
       add ecx, 1
       add wrdvBytecount, 1 
   
       mov al, [edx+ecx]	   ; read BYTE from source

       cmp al, 31		   ; test for valid ascii [ sd use table to eliminate stuff]
       ja wrpGetDatapre 	 
       cmp al, 9		   ; include TAB character
       je wrpGetDatapre
       cmp al, 13		   ; ignore  carriage return 
       je wrpGetDatastart
       cmp al, 10		   ; test for line feed 
       ja wrpGetDatastart	
    
       mov BYTE PTR [edi+ecx-1], 0   ; write terminator to buffer
       test eax, eax		   ; test for end of source
       jz wrpGetDatalbline	     ; return zero if end of source
       lea eax, [ecx+2] 	   ; add counter + 2 to EAX
		; return next spos in eax

  wrpGetDatalbline:
 
       mov wlOutputbuffer[0], 0 
       ;mov eax,offset wlWorkBuffer
       ;mov edx, offset wlOutputbuffer
       
       .if wrdListReverse == 0
	       invoke szCatStr,ADDR wlOutputbuffer,ADDR wlWorkBuffer
	       invoke SendMessage,hList1,LB_ADDSTRING,0,ADDR wlOutputbuffer
	   .else	 
	       mov wrdListReverse, eax	 
	       invoke wrpReverseline,offset wlWorkBuffer,offset wlWorkBuffer

	       .if wlWorkBuffer[0] != 0
		       invoke SendMessage,hList1,LB_ADDSTRING,0,ADDR wlWorkBuffer
	       .endif		 
       .endif 
 	   
       jmp wrpGetDataloop
  wrpGetDataendoloop: 
       pop edi	
  wrpGetDataerror:
       invoke CloseHandle,hFile 
       invoke GlobalUnlock,wrdvpMemoryblock 
       invoke GlobalFree,hMemory 
   .endif ; end true
    ret
wrpGetData endp

wrpAllocation proc uses esi edi ecx hlist:DWORD,list0entry:DWORD
 ret
wrpAllocation endp

wrpSaveData proc 
    mov wrdOpenfilename.Flags,OFN_LONGNAMES or\ 
	   OFN_EXPLORER or OFN_HIDEREADONLY 
    invoke GetSaveFileName, ADDR wrdOpenfilename 
   .if eax==TRUE 
       invoke CreateFile,ADDR wlCFilebuffer,\ 
		    GENERIC_READ or GENERIC_WRITE ,\ 
		    FILE_SHARE_READ or FILE_SHARE_WRITE,\ 
		    0,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,0 
				
       mov hFile,eax 
       invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE 
       mov  hMemory,eax 
       invoke GlobalLock,hMemory 
       mov  wrdvpMemoryblock,eax 
	   ; put in loop from listbox to o/p file instead of whats below
      ; invoke SendMessage,hwndtxtEdit,WM_GETTEXT,MEMSIZE-1,wrdvpMemoryblock 
       invoke WriteFile,hFile,wrdvpMemoryblock,eax,ADDR SizeReadWrite,NULL 
       invoke CloseHandle,hFile 
       invoke GlobalUnlock,wrdvpMemoryblock 
       invoke GlobalFree,hMemory 
   .endif ;end true
    ret
wrpSaveData endp
align 4

wrpReverseline proc uses esi edi ecx src:DWORD,dst:DWORD


   ; push esi
   ; push edi

    mov esi, src
    mov edi, dst
    xor eax, eax	    ; use EAX as a counter

  ; ---------------------------------------
  ; first loop gets the buffer length and
  ; copies the first buffer into the second
  ; ---------------------------------------
  @@:
    mov dl, [esi+eax]	    ; copy source to dest
   .if (dl > 0) && (dl < 32)
	mov dl, 32   
	mov [edi+eax], dl   
   .endif	  
    add eax, 1		    ; get the length in EAX
    test dl, dl
    jne @B
     
    mov esi, dst	    ; put dest address in ESI
    mov edi, dst	    ; same in EDI
    sub eax, 1		    ; correct for exit from 1st loop
   .if eax < 2
	jmp wrpReverselinefail
   .endif	
    lea edi, [edi+eax-1]    ; end address in edi
     shr eax, 1 	     ; int divide length by 2
     neg eax		     ; invert sign
     sub esi, eax	     ; sub half len from ESI	   

  ; ------------------------------------------
  ; second loop swaps end pairs of bytes until
  ; it reaches the middle of the buffer
  ; ------------------------------------------
  @@:

    mov cl, [esi+eax]	    ; load end pairs
    mov dl, [edi]
    mov [esi+eax], dl	    ; swap end pairs
    mov [edi], cl
    sub edi, 1
    add eax, 1
    jnz @B 
    
		   ; exit on half length

    mov eax, dst	    ; return destination address
wrpReverselinefail:
   ; pop edi
   ; pop esi

    ret

wrpReverseline endp
;~~~~~~~~~

wrpdCwrdvalidation proc cvID:DWORD
   
    ret
    
wrpdCwrdvalidation endp

;#####################################
wrpsinitValidation proc psviID:DWORD
  
  
    ret

wrpsinitValidation endp

wrpsValidation proc psvID:DWORD
   .if psvID == 401
      invoke SendMessage,hList0,LB_RESETCONTENT,0,0
	  invoke SendMessage,hList0,LB_ADDSTRING,0,ADDR wrwerdlitany
 
   .elseif psvID == 402    
      invoke SendMessage,hList1,LB_RESETCONTENT,0,0
	  invoke SendMessage,hList1,LB_ADDSTRING,0,ADDR wrdvbuffer

 
   .endif 
   
    ret

wrpsValidation endp

align 4
wrpMakelino proc uses ebx ecx edx edi esi
  ; ------------------------------------
  ; danger  .. werds at work 
 
  ; ------------------------------------

    xor eax,eax
    xor ebx,ebx
    xor ecx,ecx
    xor edx,edx
	xor edi,edi
    xor esi,esi 
	mov edx,offset werdpoem0
	
    xor ecx,ecx

almaincontrolloop:
    mov wrdvbuffer[0],0
    
	push ecx
   
  
	shl ecx,5
	;mov ebx,offset wrdvbuffer     ; this doesnt work for some reason ?
   ; mov ebx , [edx + ecx]
    invoke dwtoa,ecx,ADDR aval
    invoke szCatStr,ADDR wrdvbuffer,ADDR aval
	invoke SendMessage,hList0,LB_ADDSTRING,0,ADDR wrdvbuffer
	
	pop ecx
	inc ecx
	cmp ecx,4
	jle almaincontrolloop

mov eax,0

    ret
wrpMakelino endp

wrdpParameterwindow proc uses ebx ecx edx esi
    mov wrdebox.left,20
	mov wrdebox.top,105
	mov wrdebox.right,80
	mov wrdebox.bottom,21	
   push esi
    push edi
	mov edi, OFFSET hEditpar0
    xor esi,esi
wrdpSetEditBoxloop:	
    mov eax ,esi
	add eax,200
	mov wrdvwinid, eax
    invoke wrptxtEditBox,wrdebox.left,wrdebox.top,wrdebox.right,wrdebox.bottom,hwnd,wrdvwinid
    mov [edi], eax	

    invoke  SetDlgItemText, hwnd,wrdvwinid,ADDR badwerd   
    add esi , 1	
	.if esi < 110
	    add wrdebox.left,100
		xor edx,edx
        mov eax,esi
		mov ebx,8
        div ebx
        		
	    .if dx == 0
		    add wrdebox.top, 27

			mov wrdebox.left,20
	    .endif		
	    
	    jmp wrdpSetEditBoxloop
    .endif	
pop edi
pop esi	

mov eax ,0

      ret
wrdpParameterwindow endp


		  
wrpPaintbackground proc hBackground:DWORD
    LOCAL hdc:HDC
    LOCAL ps:PAINTSTRUCT
    LOCAL hfont:HFONT
    ;LOCAL hcomponentLib	:DWORD
    LOCAL fontOrientation :DWORD

    invoke BeginPaint,hBackground, ADDR ps
    mov    hdc,eax
    wrdmText FontName, "Roman"
    invoke CreateFont,12,12,3500,0,400,0,0,0,OEM_CHARSET,\
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
		DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
		ADDR FontName
    invoke SelectObject, hdc, eax
    mov    hfont,eax
    wrdmRGB    50,200,250
    invoke SetTextColor,hdc,eax
    wrdmRGB    110,0,55
    invoke SetBkColor,hdc,eax
    wrdmText TestString, " W E R D    .L A B made especially so you\
    can be MORE VERBOSE than you were before you encountered the wonders of sententional logic"
	   
    invoke TextOut,hdc,0,0,ADDR TestString,SIZEOF TestString
    invoke TextOut,hdc,0,400,ADDR TestString,SIZEOF TestString

    invoke SelectObject,hdc, hfont
    wrdmRGB    0,255,0
    invoke SetBkColor,hdc,eax
     
    invoke TextOut,hdc,80,0,ADDR TestString,SIZEOF TestString
    invoke TextOut,hdc,6,320,ADDR TestString,SIZEOF TestString
    invoke TextOut,hdc,40,350,ADDR TestString,SIZEOF TestString
    invoke TextOut,hdc,20,370,ADDR TestString,SIZEOF TestString
    invoke TextOut,hdc,0,390,ADDR TestString,SIZEOF TestString



    wrdmText titleFontName, "MS Sans Serif"
    invoke CreateFont,12,12,3500,0,400,0,0,0,OEM_CHARSET,\
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
		DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
		ADDR titleFontName
    invoke SelectObject, hdc, eax
    mov    hfont,eax
    wrdmRGB    50,100,150
    invoke SetTextColor,hdc,eax
    wrdmRGB    12,200,150
    invoke SetBkColor,hdc,eax
     
    wrdmText LocatorString, "Locator^"
    invoke TextOut,hdc,08,128,ADDR LocatorString,SIZEOF LocatorString
    invoke CreateFont,12,10,3650,0,400,0,0,0,OEM_CHARSET,\
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
		DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
		ADDR titleFontName
    invoke SelectObject, hdc, eax
    mov    hfont,eax
  
    wrdmRGB    80,200,90
    invoke SetBkColor,hdc,eax
   wrdmText GoString, " Comparison list (load using open file) "
    invoke TextOut,hdc,583,110,ADDR GoString,SIZEOF GoString	

    wrdmRGB    100,200,125
    invoke SetBkColor,hdc,eax
    wrdmText NegString, "Reverse  "
    invoke TextOut,hdc,90,97,ADDR NegString,SIZEOF NegString

    wrdmRGB    250,150,0    
    invoke SetBkColor,hdc,eax	      
  
    wrdmText endString, " Total Parsed Werds  "
    invoke TextOut,hdc,180,65,ADDR endString,SIZEOF endString	
	
    wrdmRGB    50,15,0    
    invoke SetBkColor,hdc,eax		
    wrdmText StartString, "  targets  "
	mov eax, wrdebox.left
	add eax, 100
    invoke TextOut,hdc,eax,36,ADDR StartString,SIZEOF StartString	

    wrdmRGB    125,25,150
    invoke SetBkColor,hdc,eax
    invoke TextOut,hdc,120,320,ADDR TestString,SIZEOF TestString
    wrdmText ListsString, "VERY LONG TOMES^"
	wrdmText SpcString, " Results List  "
    invoke TextOut,hdc,255,110,ADDR SpcString,SIZEOF SpcString     
    wrdmText titFontName, "Arial"
    invoke TextOut,hdc,08,220,ADDR ListsString,SIZEOF ListsString
    invoke CreateFont,16,16,2800,0,400,0,0,0,OEM_CHARSET,\
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
		DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
		ADDR titFontName
    invoke SelectObject, hdc, eax
    mov    hfont,eax
    wrdmRGB    125,125,125
    invoke SetBkColor,hdc,eax
    
    invoke TextOut,hdc,0,195,ADDR ListsString,SIZEOF ListsString

    invoke TextOut,hdc,194,208,ADDR ListsString,SIZEOF ListsString
    invoke TextOut,hdc,430,325,ADDR ListsString,SIZEOF ListsString
    invoke TextOut,hdc,630,275,ADDR ListsString,SIZEOF ListsString

    invoke TextOut,hdc,815,224,ADDR ListsString,SIZEOF ListsString
    invoke CreateFont,16,16,2950,0,400,0,0,0,OEM_CHARSET,\
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
		DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
		ADDR titFontName
    invoke SelectObject, hdc, eax
    invoke TextOut,hdc,300,225,ADDR ListsString,SIZEOF ListsString
    invoke TextOut,hdc,250,325,ADDR ListsString,SIZEOF ListsString
    invoke TextOut,hdc,680,295,ADDR ListsString,SIZEOF ListsString
    invoke TextOut,hdc,450,285,ADDR ListsString,SIZEOF ListsString
    invoke TextOut,hdc,750,385,ADDR ListsString,SIZEOF ListsString
    invoke EndPaint,hBackground, ADDR ps 
  
    ret

wrpPaintbackground endp

wrpPaintbackground2 proc hBackground:DWORD
    LOCAL hdc2:HDC
    LOCAL ps2:PAINTSTRUCT
    LOCAL hfont2:HFONT
   

    invoke BeginPaint,hBackground, ADDR ps2
    mov    hdc2,eax
    wrdmText FontName2, "Roman"
    invoke CreateFont,12,12,0,0,00,0,0,0,OEM_CHARSET,\
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
		DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
		ADDR FontName2
    invoke SelectObject, hdc2, eax
    mov    hfont2,eax
    wrdmRGB    200,40,20
    invoke SetTextColor,hdc2,eax
    wrdmRGB    10,150,55
    invoke SetBkColor,hdc2,eax
    wrdmText TestString2, " W E R D  C O N T R O L     P A R A M E T E R   S H E E T"
    
    invoke TextOut,hdc2,0,20,ADDR TestString,SIZEOF TestString

    invoke SelectObject,hdc2, hfont2
    wrdmRGB    255,200,0
    invoke SetBkColor,hdc2,eax
	mov eax,0
    ret
wrpPaintbackground2 endp

wrdpResizeParameters proc


mov eax ,0
ret
wrdpResizeParameters endp
wrdpmainwindow proc proc uses ebx ecx edx esi
    mov wrdebox.left,20
	mov wrdebox.top,5
	mov wrdebox.right,80
	mov wrdebox.bottom,21	
    push esi
    push edi
	mov edi, OFFSET hEditpar0
    xor esi,esi
wrpSetEditBoxloop:	
    mov eax ,esi
	add eax,200
	mov wrdvwinid, eax
    invoke wrptxtEditBox,wrdebox.left,wrdebox.top,wrdebox.right,wrdebox.bottom,hwnd,wrdvwinid
    mov [edi], eax	
	
	mov eax, esi

    invoke  SetDlgItemText, hwnd,wrdvwinid,ADDR werd
    add esi , 1	
	.if esi < WERDPARAM_LIMIT
	    add wrdebox.left,100 
	    .if esi == 9 
		    add wrdebox.top, 27
			mov wrdebox.left,20
	    .endif		
	    
	    jmp wrpSetEditBoxloop
    .endif	
pop edi
pop esi	
    invoke wrptxtEditBox,wrdlbox.left,155,40,21,hwnd,400
    mov hEditSortSequence, eax 
    invoke  SetDlgItemText, hwnd,400,ADDR werd 

	
    invoke wrptxtEditBox,20,55,80,21,hwnd,300
	invoke  SetDlgItemText, hwnd,300,ADDR werd 
    mov hnEdita1, eax
	
    invoke wrpButtonBox,20,83,40,15,hwnd,401
    mov hButtonS0, eax
    invoke wrpButtonBox,wrdlbox.left,83,40,15,hwnd,402
    mov hButtonS1, eax
   
    invoke wrpButtonBox,20,105,40,20,hwnd,411
     mov hButtonD0, eax
    invoke wrpButtonBox,wrdlbox.left,105,40,20,hwnd,412
     mov hButtonD1, eax
    
; numeric edit, 0 = normal text , otherwise reverse the line of text



   ; list box placed by wmsize in reality 
   invoke SendMessage,hwnd,LB_SETHORIZONTALEXTENT,700,0  
    invoke wrpListbox,20,125,wrdlbox.right,wrdlbox.bottom,hwnd,500
    mov hList0, eax
	
	mov eax, wrdlbox.right
	add  eax, 20
	add wrdlbox.left, eax
	
    invoke wrpListbox,wrdlbox.left,125,wrdlbox.right,wrdlbox.bottom,hwnd,501
    mov hList1, eax	

; ---------------------------------------------------
      ; This block of code reads a string that is a list of
      ; seperate items delimited by a single zero byte. The
      ; list is possibly ? terminated by a double zero byte pair.[eof]
      ; note ... the first dataname in the 200,000 long data 
      ; structure is called uz0
      ; ---------------------------------------------------
  ;  activating the horizontal scroll bar 
	  ; as otherwise the listbox truncates them 
		  
	    invoke SendMessage,hList0,LB_SETHORIZONTALEXTENT,120,0  
	    invoke SendMessage,hList0,LB_ADDSTRING,0,ADDR wrwerdlitany
	  wrdmText LongestMsg2," file comparison window "
      mov wrdvbuffer[0], 0
	  
      invoke szCatStr,ADDR wrdvbuffer,ADDR LongestMsg2

	  invoke SendMessage,hList1,LB_SETHORIZONTALEXTENT,120,0 
	  invoke SendMessage,hList1,LB_ADDSTRING,0,ADDR wrdvbuffer
	  mov eax ,0
	  ret
wrdpmainwindow endp
;
end start