/*	Thanks:	- Michael Sheker for Sphinx C-- compiler and help
			- Hutch, KetilO, TBD for their example
*/
#stack 16384
#jumptomain NONE
#pragma	option w32

#include "C--IDE.inc"
#pragma	option ia

int	main()
{
	hInstance =	GetModuleHandle(NULL);	
	IF(hRAEditDLL = LoadLibrary(#RAEditDLL))
	{
		WinMain(hInstance);
		FreeLibrary(hRAEditDLL);
	}
	ELSE	MessageBox(0,"Error loading RAEdit.dll","Error",MB_ICONWARNING);
	ExitProcess(EAX);
}
void	WinMain(HINSTANCE hInstance)
{
	dword	Wwd, Wht, Wty, Wtx;

	MSG	msg;
	WNDCLASSEX wc =	0;

	hCursor	= LoadCursor(NULL, IDC_ARROW);
	hIcon	= LoadIcon(hInstance, IDI_MAINICON);

	wc.cbSize			= sizeof(WNDCLASSEX);
	wc.style			= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc		= #WndProc;
	wc.hInstance		= hInstance;
	wc.hbrBackground	= 0;
	wc.lpszClassName	= #ClassName;
	wc.hCursor			= hCursor;
	wc.hIcon			= hIcon;
	RegisterClassEx(#wc);

	Wwd = EAX = GetSystemMetrics(SM_CXSCREEN);
	EAX >>= 3; // shift right EAX with 3
	Wtx = EAX;
	Wwd -= EAX * 2;
	Wht = EAX = GetSystemMetrics(SM_CYSCREEN);
	EAX >>= 3; // shift right EAX with 3
	Wty = EAX;
	Wht -= EAX * 2;

	hWnd =	CreateWindowEx(NULL,#ClassName,#NewFile,WS_OVERLAPPEDWINDOW,
						Wtx,Wty,Wwd,Wht,NULL,NULL,hInstance,NULL);

	hMenu =LoadMenu(hInstance,IDR_MENU);
	hProjectMenu =LoadMenu(hInstance, IDR_MENU_POPUP);
	SetMenu(hWnd,hMenu);
	SetWinCaption(#FileName);

	ShowWindow(hWnd,SW_MAXIMIZE);
	UpdateWindow(hWnd);
	WHILE(GetMessage(#msg,NULL,0,0))
	{
		TranslateMessage(#msg);
		DispatchMessage(#msg);
	}
}
dword	WndProc(dword hWnd,uMsg,wParam,lParam)
{
	switch(uMsg)	
	{
	CASE WM_CREATE:
		Wm_Create(hWnd);
		break;
	CASE WM_SIZE:
		Wm_Size();
		break;
	CASE WM_SETFOCUS:
		SetFocus(hREd);
		break;
	CASE WM_COMMAND:
		Wm_Command(hREd,uMsg, wParam, lParam);
		break;
	CASE WM_NOTIFY:
		Wm_Notify(lParam);
		BREAK;
	CASE WM_CLOSE:
		IF(ProjectChange == TRUE)
		{
			IF(MessageBox(hWnd,#ProjectNotSave,#AppName,MB_YESNO | MB_ICONQUESTION)==IDYES)
				SaveProject();
		}
		UpdateAll(WM_CLOSE);
		DestroyWindow(hWnd);
		BREAK;
	case WM_DESTROY:
		UpdateAll(WM_DESTROY);
		DeleteObject(hFont);
		DeleteObject(hLnrFont);		
		PostQuitMessage(0);
		BREAK;
	default:
		RETURN (DefWindowProc(hWnd,	uMsg, wParam, lParam));
	}
}
