// Reply 6 updated
// Compile for Windows
#define BUTTON_1 1
#define STATIC_2 2
#define STATIC_3 3

DECLARE IMPORT,InvalidateRect(hWnd as unsigned int,lpRect as POINTER,bErase as INT),INT;
DECLARE IMPORT,SetPropA(hwnd as unsigned int,lpString as STRING,hData as unsigned int),INT;
DECLARE IMPORT,_TrackMouseEvent(tme as TRACKMOUSEEVENT),INT;

struct TRACKMOUSEEVENT
{
    unsigned INT cbSize;
    unsigned INT dwFlags;
    unsigned INT hwndTrack;
    unsigned INT dwHoverTime;
}

CONST TME_HOVER = 1;
CONST TME_LEAVE = 2;
CONST WM_MOUSEHOVER = 0x2A1;
CONST WM_MOUSELEAVE = 0x2A3;


class HoverButton:CButton
{
declare OnMouseMove(int x,int y,int flags),int;
declare WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int;
CStatic *pStatic; //reference to another control for displaying messages
}

class dlg:Cdialog
{
	declare OnInitDialog(),int;
	declare OnClose(),int;
	declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
	HoverButton *pHover;
}

global sub main()
{
	dlg d1;
	d1.Create(0,0,300,202,0x80C80080,0,"Caption",0);
	d1.AddControl(CTBUTTON,"Button1",115,91,70,20,0x5000000B,0x0,BUTTON_1);
	d1.AddControl(CTSTATIC,"On Mouse Leave demo",92,27,129,18,0x5000010B,0x0,STATIC_2);
	d1.AddControl(CTSTATIC,"",87,138,126,21,0x50000100,0x0,STATIC_3);

	d1.DoModal();
return 0;
}

dlg::OnClose(),int
{
	if(pHover <> NULL)
		delete pHover;
	CloseDialog(1);
return true;
}

dlg::OnInitDialog(),int
{
	/* Initialize any controls here */
	CControl *pControl;
	pHover = new(HoverButton,1);
	//tell the button to use our class
	pControl = GetControl(BUTTON_1);
	pHover->m_hWnd = pControl->m_hWnd;
	SetPropA(pHover->m_hWnd,"THIS",pHover+0);
	//use the static control for info display
	pHover->pStatic = GetControl(STATIC_3);
	CenterWindow();
return true;
}

dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
	select nID
	{
		case BUTTON_1:
			if(nNotifyCode = 0)
			{
				/*button clicked*/
			}
	}
return true;
}


HoverButton::OnMouseMove(int x,int y,int flags),int
{
	TRACKMOUSEEVENT tme;
	tme.cbSize = LEN(TRACKMOUSEEVENT);
	tme.dwFlags = TME_HOVER | TME_LEAVE;
	tme.hwndTrack = m_hwnd;
	tme.dwHoverTime = 25;
	_TrackMouseEvent(tme);
	return true;
}

HoverButton::WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int
{
	select message
	{
		case WM_MOUSEHOVER:
			pStatic->SetText("Hover!");
			SetColor(m_fg,RGB(255,255,0));
			InvalidateRect(m_hWnd,NULL,true);
		case WM_MOUSELEAVE:
			pStatic->SetText("Mouse Leave!");
			SetColor(m_fg,RGB(200,200,200));
			InvalidateRect(m_hWnd,NULL,true);
	}
return CButton!!WndProc(message,wParam,lParam);
}