Source file: /~heha/hsn/maus32.zip/mbutton/mbutto32.asm

	.nolist
	include	windows.inc		;die von Windows 3.1 reicht!
	.list
	ideal
	P386
	model	flat
	includelib	"import32"
CHAR		equ	BYTE
MEF_Move	equ	0001h
MEF_LeftDown	equ	0002h
MEF_LeftUp	equ	0004h
MEF_RightDown	equ	0008h		;für Linkshänder
MEF_RightUp	equ	0010h
MEF_Absolute	equ	8000h
MAGIC		equ	's#h'

SEGMENT _shar dword use32 private "SHAR"
HHook		dd	0		;den brauchen wir für CallNextHookEx
Usage		dd	0		;nur zum Spaß - ein Zähler!
p_x		dd	?
p_y		dd	?
swapped		db	?		;<>0 wenn Linkshänder-Maus
;hallo$		db	'Code %d, x=%d y=%d Wnd=%X Hit=%d Extra=%d',0
ENDS

DATASEG
LHook	dd	0		;wie HHook, jedoch nur im Kontext von LLIB

UDATASEG
murks	db	?	;ohne UDATASEG will NT nicht laden!!!
;Buf	db	60 dup (?)

CODESEG

procdesc CallNextHookEx stdcall hhook:DWORD,code:DWORD,wParam:DWORD,lParam:DWORD
procdesc GetClassNameA stdcall wnd:DWORD,str:PTR BYTE,sl:DWORD
procdesc lstrcmpiA stdcall s1:PTR BYTE,s2:PTR BYTE
procdesc GetClientRect stdcall wnd:DWORD,r:PTR DWORD
procdesc ScreenToClient stdcall wnd:DWORD,p:PTR DWORD
procdesc SetRect stdcall r:PTR DWORD,l:DWORD,t:DWORD,r:DWORD,b:DWORD
procdesc MessageBeep stdcall ton:DWORD
procdesc _wsprintfA stdcall
procdesc MessageBoxA stdcall w:DWORD,t:PTR CHAR,h:PTR CHAR,b:DWORD
procdesc DisableThreadLibraryCalls stdcall hmodule:DWORD
procdesc SetWindowsHookExA stdcall t:DWORD,a:DWORD,hmodule:DWORD,hthread:DWORD
procdesc UnhookWindowsHookEx stdcall hhook:DWORD
procdesc mouse_event stdcall dwFlags:DWORD,dx:DWORD,dy:DWORD,cButtons:DWORD,dwExtraInfo:DWORD
procdesc GetSystemMetrics stdcall nIndex:DWORD

proc send_me
;Sende Mouse-Ereignis AL
;Leider ergeben sich unschöne Warteschlangen-Effekte, deshalb wird
;mit einer speziellen ExtraInfo-ID nochmal die Position gepatcht
	cmp	[swapped],0
	jz	@@1
	shl	al,2			;rechte statt linke Taste
@@1:	cbw
	cwde
	call	mouse_event,eax,0,0,0,MAGIC
	ret
endp

proc MouseHook
;	int 3
	pushad
@@code		equ	DWORD esp+24h
@@wParam	equ	DWORD esp+28h
@@lParam	equ	DWORD esp+2Ch
	 call	CallNextHookEx,[HHook],[@@code],[@@wParam],[@@lParam]
	 mov	[esp+1Ch],eax
	 cld
	 mov	esi,[@@lParam]
;	 mov	eax,[@@wParam]		;Message
;	 push	[dword esi+10h]
;	 push	[dword esi+0Ch]
;	 push	[dword esi+8]
;	 push	[dword esi+4]
;	 push	[dword esi]
;	 push	eax
;	 push	offset Hallo$
;	 push	offset Buf
;	 call	_wsprintfA
;	 add	esp,8*4
;	 call	MessageBoxA,0,offset Buf,0,0
	 mov	eax,[@@wParam]
	 lea	edi,[p_x]
	 cmp	ax,WM_MouseMove
	 je	@@getpos
	 cmp	ax,WM_LButtonDown
	 je	@@setpos
	 cmp	ax,WM_LButtonDblClk
	 je	@@setpos
	 cmp	ax,WM_LButtonUp
	 je	@@setpos
	 cmp	ax,WM_MButtonUp
	 je	@@lass
	 cmp	ax,WM_NCMButtonUp
	 je	@@lass
	 cmp	ax,WM_MButtonDown
	 je	@@fang
	 cmp	ax,WM_NCMButtonDown
;	 je	@@fang
	 jne	@@ex2
@@fang:
	 call	GetSystemMetrics,SM_SwapButton
	 mov	[swapped],al
	 mov	al,MEF_LeftDown
	 call	send_me
	 mov	al,MEF_LeftUp
	 call	send_me
	 mov	al,MEF_LeftDown
	 call	send_me
	 jmp	@@ex1
@@lass:
	 mov	al,MEF_LeftUp
	 call	send_me
@@ex1:
	 mov	[byte esp+1Ch],1	;Verarbeitung verhindern
	 jmp	@@ex2
@@getpos:
	 jmp	@@ex20			;Koordinaten retten
@@setpos:
	 cmp	[dword esi+10h],MAGIC	;Unsere Ursache?
	 jne	@@ex2
;	 call	MessageBeep,-1
	 xchg	esi,edi			;Koordinaten rückschreiben
@@ex20:
	 movsd
	 movsd
@@ex2:	
	popad
	ret	3*4
endp

proc startdll stdcall
arg @@hinstDLL:DWORD, @@fdwReason:DWORD, @@lpvReserved:DWORD
	cmp	[@@fdwReason],1		;DLL_PROCESS_ATTACH
	jne	@@detach
	inc	[Usage]
;	call	MessageBeep,0
	call	DisableThreadLibraryCalls,[@@hinstDLL]
	cmp	[HHook],0		;Erster Aufruf?
	jnz	@@exi
	call	SetWindowsHookExA,WH_Mouse,offset MouseHook,[@@hInstDLL],0
	jmp	@@ex0
@@detach:
	cmp	[@@fdwReason],0
	jnz	@@exi			;ein Irrläufer!?
	dec	[Usage]
	cmp	[LHook],0
	jz	@@exi		;Es war nicht der Prozess, der Hook setzte
	call	UnhookWindowsHookEx,[HHook]
	xor	eax,eax			;sicherheitshalber
@@ex0:
	mov	[HHook],eax
	mov	[LHook],eax
@@exi:
	ret
endp

end	startdll

;Änderungen:
;01/02: Beachtung Linkshändermaus
Detected encoding: OEM (CP437)1
Wrong umlauts? - Assume file is ANSI (CP1252) encoded