www.pudn.com > fd.zip > SCROLL.ASM


locals 
.386 
.model flat,stdcall 
include win32.asi 
include win32.ase 
include fdui.asi 
 
	public handlesb,scrollkeys,DisplayWindowBars,SetBarRanges, ShiftState 
	extrn  Translate : PROC, Dispatch : PROC 
.data 
ShiftState	db	? 
 
.code 
 
;----------------------------------------------------------------------------- 
; 
; this routine calculates the new scroll bar position, then redraws 
; the scroll bar and invalidates the screen 
; 
handlesb	PROC	hwnd : dword, sbdata : dword, \ 
			sbmsg : dword, newpos : dword 
 
		mov	ebx,[sbdata] 
		mov	eax,[sbmsg] 
		call	Dispatch 
		dd	8 
		dd	SB_BOTTOM,offset sbbot 
		dd	SB_TOP,offset sbtop 
		dd	SB_THUMBPOSITION,offset sbtpos 
		dd	SB_THUMBTRACK,offset sbttrack 
		dd	SB_PAGEUP,offset sbpup 
		dd	SB_PAGEDOWN,offset sbpdown 
		dd	SB_LINEUP,offset sblup 
		dd	SB_LINEDOWN,offset sbldown 
		jc	badbx 
		call	SetScrollPos,[hwnd],[ebx + sbinfo.sbstyle],\ 
					[ebx + sbinfo.sbpos],1 
                call    InvalidateRect,[hwnd],0,0,0,0 
badbx: 
		ret 
 
sbbot	PROC 
		mov	[ebx + sbinfo.sbpos],0 
		ret 
sbbot	ENDP 
sbtop	PROC 
		mov	eax,[ebx + sbinfo.sbheight] 
		mov	[ebx + sbinfo.sbpos],eax 
		ret 
sbtop	ENDP 
sbtpos	PROC 
		mov	eax,[newpos] 
		mov	dword ptr [ebx + sbinfo.sbpos],eax 
		ret 
sbtpos	ENDP 
sbttrack	PROC 
		; intercept the tunhmbtrack message if you want to give 
		; feedback while they ard dragging the scrollbar 
		 
		mov	eax,[newpos] 
		mov	dword ptr [ebx + sbinfo.sbpos],eax 
		ret 
sbttrack	ENDP 
sbpup	PROC 
		 
		mov	eax,[ebx + sbinfo.sbpaging] 
		sub	dword ptr [ebx + sbinfo.sbpos],eax 
		jns	sbpupx 
		mov	dword ptr [ebx + sbinfo.sbpos],0 
sbpupx: 
		ret 
sbpup	ENDP 
sbpdown	PROC 
		mov	eax,[ebx + sbinfo.sbpaging] 
		add	dword ptr [ebx + sbinfo.sbpos],eax 
		mov     eax,[ebx + sbinfo.sbheight] 
		cmp	dword ptr [ebx + sbinfo.sbpos],eax 
		jc	sbpdownx 
		mov	dword ptr [ebx + sbinfo.sbpos],eax 
sbpdownx: 
		ret 
sbpdown	ENDP 
sblup	PROC 
		dec	dword ptr [ebx + sbinfo.sbpos] 
		jns	sblupx 
		mov	dword ptr [ebx + sbinfo.sbpos],0 
sblupx: 
		ret 
sblup	ENDP 
sbldown	PROC 
		inc	dword ptr [ebx + sbinfo.sbpos] 
		mov	eax,[ebx + sbinfo.sbheight] 
		cmp	dword ptr [ebx + sbinfo.sbpos],eax 
		jc	sbldownx 
		mov	dword ptr [ebx + sbinfo.sbpos],eax 
sbldownx: 
		ret 
sbldown	ENDP 
handlesb	ENDP 
;----------------------------------------------------------------------------- 
; 
; this function translates a keypress into something handlesb can 
; use 
; 
; we are using shift-right and shift-left here to do page-right and page-left 
; 
scrollkeys	proc	hwnd : dword, key : dword, dwdata : dword 
		mov	eax,key 
		mov	ebx,[dwdata] 
		test	[ShiftState],1 
		jnz	isshifted 
		call	Translate 
		dd	4 
		dd	VK_NEXT,SB_PAGEDOWN 
		dd	VK_PRIOR,SB_PAGEUP 
		dd	VK_UP,SB_LINEUP 
		dd	VK_DOWN,SB_LINEDOWN 
		jc	sk_chkhorz 
		lea	ebx,[ebx + dwinfo.pvsb] 
		call	handlesb,[hwnd],ebx,eax,0 
		ret 
sk_chkhorz: 
		call	Translate 
		dd	2 
		dd	VK_LEFT,SB_LINEUP 
		dd	VK_RIGHT,SB_LINEDOWN 
		jnc	skhorz 
		ret 
isshifted: 
		call	Translate 
		dd	2 
		dd	VK_LEFT,SB_PAGEUP 
		dd	VK_RIGHT,SB_PAGEDOWN 
		jc	sk_noredraw 
skhorz: 
		lea	ebx,[ebx + dwinfo.phsb] 
		call	handlesb,[hwnd],ebx,eax,0 
sk_noredraw: 
		ret 
scrollkeys	endp 
;----------------------------------------------------------------------------- 
DisplayWindowBars PROC hwnd : dword, flag : dword 
 
		call   ShowScrollBar,[hwnd],SB_BOTH,[flag] 
		ret 
DisplayWindowBars ENDP 
 
SetBarRanges PROC hwnd : dword, sbr_vert : dword, sbr_horiz : dword 
		 mov	ebx,[sbr_horiz] 
		 call	SetScrollRange,[hwnd],SB_HORZ, \ 
				0,[ebx + sbinfo.sbpos],[ebx + sbinfo.sbheight],1 
		 mov	ebx,[sbr_vert] 
		 call	SetScrollRange,[hwnd],SB_VERT, \ 
				0,[ebx + sbinfo.sbpos],[ebx + sbinfo.sbheight],1 
                call    InvalidateRect,[hwnd],0,0,0,0 
		ret 
SetBarRanges ENDP 
end