#pragma	option ia	// assembly	instructions as	identifier

dword hEditProc(dword hCtl,	uMsg, wParam, lParam)
{
	POINT	Pt;
	RECT	rect;
	dword	hSM;
	HDC	hDC;

	switch(uMsg)
	{
	CASE WM_KEYDOWN:
		switch(wParam)
		{
		CASE VK_F1:
			help_file();
			break;
		CASE VK_F3:
			TextFind(hREd,0);
			break;
		CASE VK_F6:		// Refresh
			Refresh();
			break;
		CASE 0x46:	// CTRL	+ F
			IF(HIBYTE(GetKeyState(VK_CONTROL))> 0)
				DialogBoxParam(hInstance,frmFind,hWnd,#SearchProc,0);
			return 0;
		CASE 0x52:	// CTRL	+ R
//			IF(HIBYTE(GetKeyState(VK_CONTROL))> 0)
//				DialogBoxParam(hInstance,frmReplace,hWnd,#SearchProc,0);
				MessageBox(hWnd, "Not Finish Yet", #AppName,MB_OK);
			return 0;
		case 0x53:	// CTRL	+ S
			IF(HIBYTE(GetKeyState(VK_CONTROL))> 0)FileSave(hREd);
			BREAK;
		case 0x59:	// CTRL	+ Y
			IF(HIBYTE(GetKeyState(VK_CONTROL))> 0)SendMessage(hREd,EM_REDO,0,0);
			BREAK;
		case 0x5A:	// CTRL	+ Z
			IF(HIBYTE(GetKeyState(VK_CONTROL))> 0)SendMessage(hREd,EM_UNDO,0,0);
			break;
		}
		BREAK;
	case WM_RBUTTONDOWN:
		GetCursorPos(#Pt);
		hSM	= GetSubMenu(hMenu,menu_popup);
		TrackPopupMenu(hSM,TPM_LEFTALIGN | TPM_LEFTBUTTON, Pt.x,Pt.y,0,	hWnd,NULL);
		BREAK;

	case WM_PAINT:
		hDC	= GetDC(hCtl);
		GetUpdateRect(hCtl,#rect,FALSE);
		CallWindowProc(lpfnhEditProc,hCtl,uMsg,wParam,lParam);
		ReleaseDC(hCtl,hDC);
		EAX	= 0;
		break;
	}
	CallWindowProc(lpfnhEditProc,hCtl,uMsg,wParam,lParam);
}
void	help_file()
{
	char	buff[100];

	SendMessage(hREd, REM_GETWORD, 100, #buff);
	WinHelp(hWnd,"\\masm32\\help\\win32.hlp",HELP_KEY,#buff);
}

	char confirm[] = "File is not saved, Save it now ?";
:dword Confirmation(dword hEditor,lpFileName)
{
	byte	buffer[MAX_PATH]=0;
	
	IF(SendMessage(hEditor,WM_GETTEXTLENGTH,0,0)==0) RETURN	0;
	IF(SendMessage(hEditor,EM_GETMODIFY,0,0)==0) RETURN	0;	// zero	= unmodified

	lstrcpy(#buffer,lpFileName);
	lstrcat(#buffer,"\n");
	lstrcat(#buffer,#confirm);
	MessageBox(hWnd,#buffer,#AppName,MB_YESNOCANCEL | MB_ICONQUESTION);
}
:void Select_All(dword hEdit)
{
	CHARRANGE Cr;	//structure	specifies a	range of characters	in a rich edit control.

	Cr.cpMin = 0;

	GetWindowTextLength(hEdit);	//retrieves	the	length,	in characters, of the specified	window's title bar text	(if	the	window has a title bar)
	EAX++;
	Cr.cpMax = EAX;

	SendMessage(hEdit,EM_EXSETSEL,0,#Cr);	//selects a	range of characters	and/or OLE objects in a	rich edit control.
}
:void	SetFont(dword hWin)
{
	CHOOSEFONT	cf;
	
	RtlZeroMemory(#cf,sizeof(cf));
	cf.lStructSize = sizeof	(cf);
	cf.hwndOwner = hWin;
	cf.lpLogFont = #lfnt;
	cf.Flags = CF_SCREENFONTS |	CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
	cf.rgbColors = rgb;
	IF(ChooseFont(#cf))
	{
		DeleteObject(hFont);
		hFont =	CreateFontIndirect(#lfnt);
		rgb	= cf.rgbColors;
		SetFormat(hREd);
	}
	SetFocus(hREd);
}
void	SetFormat(dword	hWin)
{
	RAFONT	rafnt;

	mov		EAX,hFont
	mov		rafnt.hFont,EAX
	mov		EAX,hIFont
	mov		rafnt.hIFont,EAX
	mov		EAX,hLnrFont
	mov		rafnt.hLnrFont,EAX
	//Set fonts
	SendMessage(hWin,REM_SETFONT,0,# rafnt);
	//Set tab width	& expand tabs
	SendMessage(hWin,REM_TABWIDTH,edopt.tabsize,edopt.exptabs);
	//Set autoindent
	SendMessage(hWin,REM_AUTOINDENT,0,edopt.indent);
	//Set number of	lines mouse	wheel will scroll
	//NOTE!	If you have	mouse software installed, set to 0
	SendMessage(hWin,REM_MOUSEWHEEL,3,0);
//	//Set selection	bar	width
//	SendMessage,hWin,REM_SELBARWIDTH,20,0
//	//Set linenumber width
//	SendMessage,hWin,REM_LINENUMBERWIDTH,40,0
}
void	CreateNew()
{
	lstrcpy(#FileName,#NewFile);
	CreateRAEdit();
	TabToolAdd(hREd,#FileName);
	SetWinCaption(#FileName);
	SetFocus(hREd);
}
void	CreateRAEdit()
{
	ShowWindow(hREd,SW_HIDE);
	hREd = CreateWindowEx(WS_EX_CLIENTEDGE,#szRAEditClass,NULL,WS_CHILD	| WS_VISIBLE | STYLE_NOBACKBUFFER,0,0,0,0,hWnd,NULL,hInstance,0);
	lpfnhEditProc =	SendMessage(hREd, REM_SUBCLASS,0 ,#hEditProc);
	SetFormat(hREd);
	//Set colors
	SendMessage(hREd,REM_SETCOLOR,0,#col);
	SendMessage(hWnd,WM_SIZE,0,0);
}
void	SetWinCaption(dword lpFileName)
{
	byte	buffer[sizeof(AppName)+3+MAX_PATH];

	lstrcpy(#buffer,#AppName);
	IF(lstrcmp(#ProjectName,"")!=0)
	{
		lstrcat(#buffer," - ");
		lstrcat(#buffer,RemovePath(#ProjectName));
	}
	lstrcat(#buffer," - [");
	lstrcat(#buffer,lpFileName);
	lstrcat(#buffer,"]");
	SetWindowText(hWnd,#buffer);
}
:void	Refresh()
{
	byte	line[256]=0,FindName[128]=0;
	dword	hTemp,nInx,nList=0,tList,tInx;
	TC_ITEM	tci;

	SendMessage(hProperty,LB_RESETCONTENT,0,0);
	PUSH	EBX
	nInx = -1;
	tci.mask = TCIF_PARAM;
	EAX = TRUE;
	WHILE(EAX)
	{
		nInx++;
		IF(SendMessage(hTab,TCM_GETITEM,nInx,# tci))
		{
			EBX = tci.lParam;
			hTemp = CreateWindowEx(WS_EX_CLIENTEDGE,#szRAEditClass,NULL,WS_CHILD | WS_VISIBLE | STYLE_NOBACKBUFFER | STYLE_NOCOLLAPSE,0,0,0,0,hWnd,NULL,hInstance,0);		
			LoadFile(hTemp,#EBX.TABMEM.filename);
			SetProcMark(hTemp);
			GetProc(hTemp);
			DestroyWindow(hTemp);
		}
	}
	POP		EBX
	SSWORD[#line] = 256;
	tList = SendMessage(hProject,LB_GETCOUNT,0,0);
	while(nList<=tList)
	{
		SendMessage(hProject,LB_GETTEXT,nList,#line);
		lstrcpy(#FindName,#ProjectPath);
		lstrcat(#FindName,#line);
		PUSH	EBX
		nInx = 0;
		tci.mask = TCIF_PARAM;
		tInx = SendMessage(hTab,TCM_GETITEMCOUNT,0,0);
		while(nInx<=tInx)
		{
			IF(SendMessage(hTab,TCM_GETITEM,nInx,# tci))
			{
				EBX = tci.lParam;
				IF(lstrcmpi(#EBX.TABMEM.filename,#FindName)!=0)
				{
					hTemp = CreateWindowEx(WS_EX_CLIENTEDGE,#szRAEditClass,NULL,WS_CHILD | WS_VISIBLE | STYLE_NOBACKBUFFER | STYLE_NOCOLLAPSE,0,0,0,0,hWnd,NULL,hInstance,0);		
					LoadFile(hTemp,#FindName);
					SetProcMark(hTemp);
					GetProc(hTemp);
					DestroyWindow(hTemp);
				}
			}
			nInx++;
		}
		POP		EBX
		nList++;
	}
}