;-dropmany.asm---------------------------------------------------------------
;          x86 - Dos & Win32 - Assembly Language Programming                ;
;                                                                           ;
; Written by: John A Lyons                                                  ;
; Email     : sysop@megablast.8k.com                                        ;
; Page      : http://www.asmsource.8k.com/                                  ;
; Compiler  : Masm32 v6.13 Microsoft Macro Assembler                        ;
; Date      : 1-Jan-2001                                                    ;
; Purpose   : Changes the windows to allow it to accept a dropped in file,  ;
;             and then prints out the number of files drop, and there names.;
;                                                                           ;
;----------------------------------------------------------------------------
; Compile with nmake
;


.386                    ; 32-Bit when .386 appears before .MODEL
.MODEL  FLAT , STDCALL

include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
include shell32.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
includelib shell32.lib


EXTRN wsprintfA:PROC

.data
ClassName       db "SimpleWinClass",0
AppName         db "Dropmany",0
TestString      db "Drop in me",0
fileno          db "%lu files dropped",0

hInstance       HINSTANCE ?
CommandLine     LPSTR ?
hwnd            HWND ?
hdc             HDC ?

buff            db 200 dup(0)

.code

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD
	LOCAL wc:WNDCLASSEX
	LOCAL msg:MSG

	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  hInstance
        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,0
        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,           ;postion
          300,100,            ;size
          NULL,NULL,\
           hInst,NULL
        mov   hwnd,eax

        INVOKE DragAcceptFiles,hwnd,TRUE

        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 ps:PAINTSTRUCT
        LOCAL total:DWORD

	mov   eax,uMsg
	.IF eax==WM_DESTROY
		invoke PostQuitMessage,NULL
        .ELSEIF ax==WM_PAINT
                invoke BeginPaint,hWnd, ADDR ps
                mov    hdc,eax

                invoke TextOut,hdc,0,0,ADDR TestString,(SIZEOF TestString) -1

                invoke EndPaint,hWnd, ADDR ps
        .ELSEIF ax==WM_DROPFILES

                mov ebx,wParam


                invoke GetDC,hWnd
                mov    hdc,eax

                invoke DragQueryFile,wParam,-1,ADDR buff,200
                mov [total],eax

                push eax
                push offset fileno
                lea eax,buff
                push eax
                call wsprintfA

                mov esi,0
                call text

                mov ebx,0
                mov esi,15
redt:
                invoke DragQueryFile,wParam,ebx,ADDR buff,200
                call text

                add esi,15
                inc ebx
                cmp ebx,[total]
                jb redt


                invoke EndPaint,hWnd, ADDR ps


        .ELSE
                invoke DefWindowProc,hWnd,uMsg,wParam,lParam
                ret
	.ENDIF
        xor    eax,eax
	ret
WndProc endp
text proc
                push eax
                push edi

                lea edi,buff-1
                xor eax,eax
got1:
                inc eax
                inc edi
                cmp [edi],byte ptr 0
                jne got1
                dec eax

                invoke TextOut,hdc,0,esi,ADDR buff,eax

                pop edi
                pop eax

        ret
text endp

start:

	invoke GetModuleHandle, NULL
	mov    hInstance,eax
	invoke GetCommandLine
        invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
	invoke ExitProcess,eax

        end start
