// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "main.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "MainWnd.h"
/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_WM_GETMINMAXINFO()
	ON_WM_TIMER()
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here

	whichBitmap = 0;
	rect1 = CRect(390,80,620,411);
	rect2 = CRect(390,467,620,580);
	cout.clip(2);
	cout.setTextBkColor(RGB(0,0,255));
	cout.setTextColor(RGB(255,255,255));
	cout.setTextBkMode(TRANSPARENT);
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
/*	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
*/
	ModifyStyle(WS_CAPTION,0);
	ModifyStyle(WS_BORDER,0);
	ModifyStyle(WS_THICKFRAME,0);
	ModifyStyleEx(WS_EX_CLIENTEDGE,0);	
//	ModifyStyleEx(0,WS_EX_TRANSPARENT);
	CBitmap bmp;
	bmp.LoadBitmap(IDB_BITMAP_WELCOME);
	BITMAP BM;
	bmp.GetObject(sizeof(BM),&BM);
	int left = 150;	
	int hide = 20;
	top = 130-hide;
	SetWindowPos(NULL,left,-hide,BM.bmWidth,top+hide+BM.bmHeight,SWP_SHOWWINDOW);
//	SetWindowPos(NULL,100,-50,BM.bmWidth,200+BM.bmHeight,SWP_SHOWWINDOW);
//	SetTimer(1,50,NULL);
	return 0;

}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here

//	if(whichBitmap == 0)]
//			DisplayBitmap(&dc,&bmp,IDB_BITMAP_WELCOME,0,35);
//	else if(whichBitmap == 1)
//		DisplayBitmap(&dc,&bmp,IDB_BITMAP_MAIN,0,35);

	CBitmap bmp;
	DisplayBitmap(&dc,&bmp,IDB_BITMAP_WELCOME,0,top);

	// Do not call CFrameWnd::OnPaint() for painting messages
}

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
{
	// TODO: Add your message handler code here and/or call default
	lpMMI->ptMaxSize.x = 1000;
	lpMMI->ptMaxSize.y = 1000;
	lpMMI->ptMaxPosition.y = -100;
	lpMMI->ptMaxTrackSize.y = 1000;

	CFrameWnd::OnGetMinMaxInfo(lpMMI);
}

void CMainFrame::DisplayBitmap(CDC *pDC, CBitmap *pBitmap, UINT ID, int x, int y)
{
	pBitmap->LoadBitmap(ID);
	BITMAP BM;
	CDC MemDC;
	MemDC.CreateCompatibleDC(NULL);
	MemDC.SelectObject(pBitmap);
	pBitmap->GetObject(sizeof(BM),&BM);
	pDC->BitBlt(x,y,BM.bmWidth,BM.bmHeight,&MemDC,0,0,SRCCOPY);

}

void CMainFrame::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	static pixels = 0;
	CDC *pDC = GetDC();
	cout.setDC(pDC);
	cout.setDisplayArea(rect1);
	int h = rect1.Height()+rect2.Height()+(rect2.top-rect1.bottom); 
	CString s = "    如今，计算机的应用已不再局限于科学计算，而更多的用于控制、管理及数据处理等非数值计算的处理工作。与此相应，计算机加工处理的对象由纯粹的数值发展到字符、表格和图像等各种具有一定结构的数据。这就给程序设计带来一些新的问题。为了编写出一个“好”的程序，必须分析待处理的对象的特性以及各处理对象之间存在的关系。这就是“数据结构”这门学科的形成和发展的背景。";
	cout.setStart(0,h);
	cout.scrollPixel(pixels);
	if(cout.y < rect1.top+30)
	{
		pixels = 0;
		KillTimer(nIDEvent);
	}
	cout.clearBackground(RGB(0,0,255));
	cout<<s;//y值停留在输出的最后一行上

	cout.setDisplayArea(rect2);
	cout.setStart(0,rect2.Height());
	cout.scrollPixel(pixels);
	cout.clearBackground(RGB(0,0,255));
	cout<<s;
	pixels+=1;
	ReleaseDC(pDC);
	CFrameWnd::OnTimer(nIDEvent);
}

void CMainFrame::openMainWnd()
{
	CMainWnd mainWnd;
	mainWnd.DoModal();

}








void CMainFrame::OnSize(UINT nType, int cx, int cy) 
{
	CFrameWnd::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
}

BOOL CMainFrame::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
//	return CFrameWnd::OnEraseBkgnd(pDC);
	return true;
}

void CMainFrame::SetDisplayScreen()
{
	DEVMODE *pMode = new DEVMODE;
	int result = EnumDisplaySettings(NULL,0,pMode);
	for(int i=1;result;i++)
	{
		if((pMode->dmPelsWidth == 800) && (pMode->dmPelsHeight == 600))
		{
			if((pMode->dmBitsPerPel == 32) || (pMode->dmBitsPerPel == 24))
			{
				pMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
				ChangeDisplaySettings(pMode,0);
				//::MessageBox(NULL,"ok","",MB_OK);
				break;
			}
		}
		result = EnumDisplaySettings(NULL,i,pMode);
	}
	::ShowWindow(::FindWindow("Shell_TrayWnd",NULL),SW_HIDE);

}
