.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
EnumChild proto :DWORD,:DWORD
SetDlgToolArea proto :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.const
IDD_MAINDIALOG equ 101
.data
ToolTipsClassName db "Tooltips_class32",0
MainDialogText1 db "This is the upper left area of the dialog",0
MainDialogText2 db "This is the upper right area of the dialog",0
MainDialogText3 db "This is the lower left area of the dialog",0
MainDialogText4 db "This is the lower right area of the dialog",0
.data?
hwndTool dd ?
hInstance dd ?
.code
start:
	invoke GetModuleHandle,NULL
	mov hInstance,eax
	invoke DialogBoxParam,hInstance,IDD_MAINDIALOG,NULL,addr DlgProc,NULL
	invoke ExitProcess,eax
DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
	LOCAL ti:TOOLINFO
	LOCAL id:DWORD
	LOCAL rect:RECT
	.if uMsg==WM_INITDIALOG
		invoke InitCommonControls
		invoke CreateWindowEx,NULL,ADDR ToolTipsClassName,NULL,\
	           TTS_ALWAYSTIP,CW_USEDEFAULT,\
	           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
	           hInstance,NULL
		mov hwndTool,eax
		mov id,0
		mov ti.cbSize,sizeof TOOLINFO
		mov ti.uFlags,TTF_SUBCLASS
		push hDlg
		pop ti.hWnd
		invoke GetWindowRect,hDlg,addr rect
		invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText1,id,addr rect
		inc id
		invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText2,id,addr rect
		inc id
		invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText3,id,addr rect
		inc id
		invoke SetDlgToolArea,hDlg,addr ti,addr MainDialogText4,id,addr rect
		invoke EnumChildWindows,hDlg,addr EnumChild,addr ti
	.elseif uMsg==WM_CLOSE
		invoke EndDialog,hDlg,NULL
	.else
		mov eax,FALSE
		ret
	.endif
	mov eax,TRUE
	ret
DlgProc endp
EnumChild proc uses edi hwndChild:DWORD,lParam:DWORD
	LOCAL buffer[256]:BYTE
	mov edi,lParam
	assume edi:ptr TOOLINFO
	push hwndChild
	pop [edi].uId
	or [edi].uFlags,TTF_IDISHWND
	invoke GetWindowText,hwndChild,addr buffer,255
	lea eax,buffer
	mov [edi].lpszText,eax
	invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,edi
	assume edi:nothing
	ret
EnumChild endp
SetDlgToolArea proc uses edi esi hDlg:DWORD,lpti:DWORD,lpText:DWORD,id:DWORD,lprect:DWORD
	mov edi,lpti
	mov esi,lprect
	assume esi:ptr RECT
	assume edi:ptr TOOLINFO
	.if id==0
		mov [edi].rect.left,0
		mov [edi].rect.top,0
		mov eax,[esi].right
		sub eax,[esi].left
		shr eax,1
		mov [edi].rect.right,eax
		mov eax,[esi].bottom
		sub eax,[esi].top
		shr eax,1
		mov [edi].rect.bottom,eax
	.elseif id==1
		mov eax,[esi].right
		sub eax,[esi].left
		shr eax,1
		inc eax
		mov [edi].rect.left,eax
		mov [edi].rect.top,0
		mov eax,[esi].right
		sub eax,[esi].left
		mov [edi].rect.right,eax
		mov eax,[esi].bottom
		sub eax,[esi].top
		mov [edi].rect.bottom,eax
	.elseif id==2
		mov [edi].rect.left,0
		mov eax,[esi].bottom
		sub eax,[esi].top
		shr eax,1
		inc eax
		mov [edi].rect.top,eax
		mov eax,[esi].right
		sub eax,[esi].left
		shr eax,1
		mov [edi].rect.right,eax
		mov eax,[esi].bottom
		sub eax,[esi].top
		mov [edi].rect.bottom,eax
	.else
		mov eax,[esi].right
		sub eax,[esi].left
		shr eax,1
		inc eax
		mov [edi].rect.left,eax
		mov eax,[esi].bottom
		sub eax,[esi].top
		shr eax,1
		inc eax
		mov [edi].rect.top,eax
		mov eax,[esi].right
		sub eax,[esi].left
		mov [edi].rect.right,eax
		mov eax,[esi].bottom
		sub eax,[esi].top
		mov [edi].rect.bottom,eax
	.endif
	push lpText
	pop [edi].lpszText
	invoke SendMessage,hwndTool,TTM_ADDTOOL,NULL,lpti
	assume edi:nothing
	assume esi:nothing
	ret
SetDlgToolArea endp
end start
