.386
.model flat, stdcall
option casemap :none
include windows.inc

incboth	MACRO	incl
	include incl.inc
	includelib incl.lib
ENDM

m2m	MACRO	m1, m2
	push m2
	pop m1
ENDM

incboth kernel32
incboth user32
incboth gdi32
incboth comctl32

InitRollup			PROTO
RollupWindowProc	PROTO	:HWND, :DWORD, :DWORD, :DWORD
RollupHandler		PROTO	:HWND, :DWORD, :DWORD, :DWORD

DlgProc				PROTO	:HWND, :DWORD, :DWORD, :DWORD

.data?
	hInstance			HINSTANCE				?
	hRollUp				HANDLE					?
	hMainDialog			HANDLE					?
	hTextBox			HANDLE					?
	
.data
	szRollUpName		db						"Roll Up Test",0
	
	szHelloEveryone		db						"Roolup Toolbars",13,10
						db						"by Entro-P (entro-p@asmz.com)",13,10,13,10
						db						"One of the last things I added was",13,10
						db						"auto-switch focus, to demonstrate the",13,10
						db						"the workings a bit more visibly.",13,10
						db						"best seen if there's some text in the",13,10
						db						"main window, as well as in the rollup.",13,10,0

.code
start:
	invoke GetModuleHandle, NULL
	mov hInstance, eax

	invoke InitRollup
	
	invoke MessageBox, NULL, addr szHelloEveryone, addr szRollUpName, MB_OK + MB_ICONINFORMATION
	
	invoke DialogBoxParam, hInstance, 101, NULL, addr DlgProc, NULL
	invoke ExitProcess, NULL
	
ActualDialogProc	PROC	hWnd:HWND, uMsg:DWORD, wParam:DWORD, lParam:DWORD
	local		p				:POINT
	local		hWndParent		:HANDLE
	.IF uMsg == WM_MOUSEMOVE
		invoke GetFocus	
		.IF eax == hWnd
			jmp adp_WM_MOUSEMOVE_exit
		.ENDIF
		invoke GetParent	,eax
		.IF eax == hWnd
			jmp adp_WM_MOUSEMOVE_exit
		.ENDIF
		mov eax, lParam
		and eax, 0FFFFh
		mov p.x, eax
		mov eax, lParam
		shr eax, 16
		mov p.y, eax
		invoke GetParent	,hWnd
		mov hWndParent, eax
		invoke MapWindowPoints	,hWnd, hWndParent, addr p, 1
		shl p.y, 16
		mov eax, p.x
		or eax, p.y
		mov p.x, eax
		invoke SendMessage, hWndParent, uMsg, wParam, p.x
adp_WM_MOUSEMOVE_exit:
		mov eax, FALSE
		ret
	.ELSE
		mov eax, FALSE
		ret
	.ENDIF
	mov eax, TRUE
	ret
ActualDialogProc	ENDP


include rollupprocs.asm

DlgProc		PROC		hWnd:HWND, uMsg:DWORD, wParam:DWORD, lParam:DWORD
	LOCAL	r					:RECT
	
	invoke RollupHandler, hWnd, uMsg, wParam, lParam

	.IF uMsg == WM_INITDIALOG
		invoke GetWindowRect, hWnd, addr r
		add r.top, 30
		add r.left, 200
		m2m hMainDialog, hWnd
		invoke CreateWindowEx, 10000h, \ ;NULL , \ ;WS_EX_TOOLWINDOW	, \
			addr szRollUpClass, \
			addr szRollUpName, \
			94000044h, \;NULL , \ ; WS_SYSMENU + WS_CLIPCHILDREN + WS_DLGFRAME, \
			r.left, r.top, \
			0, 0, \
			hWnd, NULL, \
			hInstance, NULL
		mov hRollUp, eax
	
		invoke ShowWindow, hRollUp, SW_SHOW			
		
		invoke GetDlgItem	,hWnd, 3000
		mov hTextBox, eax
		invoke GetClientRect	,hWnd, addr r
		invoke MoveWindow	,hTextBox, 0, 0, r.right, r.bottom, TRUE
			
	.ELSEIF uMsg == WM_NCACTIVATE
		.IF ! wParam
			invoke PostMessage	,hWnd, uMsg, TRUE, lParam
		.ENDIF
		mov eax, FALSE
		ret

	.ELSEIF uMsg == WM_CLOSE
		invoke EndDialog, hWnd, NULL
	.ELSE
		xor eax, eax
		ret
	.ENDIF
	mov eax, TRUE
	ret		
DlgProc		ENDP

end start