Click here to Skip to main content
15,879,239 members
Articles / Desktop Programming / MFC

Auto-Task Tool for Web Game Travian

Rate me:
Please Sign up or sign in to vote.
4.84/5 (26 votes)
29 Oct 20075 min read 780.5K   7.1K   45  
Developing Auto-Task Tool for Web Game Travian
// MainFrm.cpp : implementation file
//

#include "stdafx.h"
#include "TravianAutoTask.h"
#include "MainFrm.h"
#include "FormTask.h"
#include "ViewOutput.h"
#include "ViewTaskList.h"


// CMainFrm

IMPLEMENT_DYNCREATE(CMainFrm, CFrameWnd)

CMainFrm::CMainFrm(): m_bCreated(false)
{
}

CMainFrm::~CMainFrm()
{
}


BEGIN_MESSAGE_MAP(CMainFrm, CFrameWnd)
	ON_WM_CREATE()
	ON_UPDATE_COMMAND_UI(ID_FILE_OPEN,	&CMainFrm::OnUpdateFileOpen)
	ON_COMMAND(ID_FILE_OPEN,			&CMainFrm::OnFileOpen)
	ON_COMMAND(ID_FILE_FONT,			&CMainFrm::OnFileFont)
	ON_WM_CLOSE()
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};


// CMainFrm message handlers
int CMainFrm::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	SetIcon(::AfxGetApp()->LoadIcon(IDR_MAIN), TRUE);
	SetIcon(::AfxGetApp()->LoadIcon(IDR_MAIN), FALSE);


	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_MAIN))
	{
		TRACE0("Create tool bar failed\n");
		return -1;  
	}
	{	// CToolBar only can load 16 color bitmap, so here reload 256 bitmap file.
		CBitmap bmp;
		bmp.LoadBitmap(IDR_TOOLBAR256);
		m_wndToolBar.SetBitmap( (HBITMAP)(bmp.Detach()) );
	}

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


	return 0;
}

BOOL CMainFrm::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
	// TODO: Add your specialized code here and/or call the base class

	// create a splitter with 2 row, 2 columns
	if (!m_wndSplitter.CreateStatic(this, 2, 1))
	{
		TRACE0("Failed to CreateStaticSplitter\n");
		return FALSE;
	}

	// add the second splitter pane - which is a nested splitter with 2 cols
	if (!m_wndSplitter2.CreateStatic(
		&m_wndSplitter,     // our parent window is the first splitter
		1, 2,               // the new splitter is 1 rows, 2 column
		WS_CHILD | WS_VISIBLE | WS_BORDER,  // style, WS_BORDER is needed
		m_wndSplitter.IdFromRowCol(0, 0)
			// new splitter is in the first row, 2nd column of first splitter
	   ))
	{
		TRACE0("Failed to create nested splitter\n");
		return FALSE;
	}

	// add the first splitter pane - the default view in column 1
	if (!m_wndSplitter.CreateView(1, 0,
		RUNTIME_CLASS(CViewOutput), CSize(lpcs->cx, ((lpcs->cy)>>1) ), pContext))
	{
		TRACE0("Failed to create first pane\n");
		return FALSE;
	}

	// now create the two views inside the nested splitter

	if (!m_wndSplitter2.CreateView(0, 0,
		RUNTIME_CLASS(CFormTask), CSize( ((lpcs->cx)>>1), ((lpcs->cy)>>1) ), pContext))
	{
		TRACE0("Failed to create second pane\n");
		return FALSE;
	}
	if (!m_wndSplitter2.CreateView(0, 1,
		RUNTIME_CLASS(CViewTaskList), CSize( ((lpcs->cx)>>1), ((lpcs->cy)>>1) ), pContext))
	{
		TRACE0("Failed to create third pane\n");
		return FALSE;
	}

	m_bCreated = true;
	if (m_bCreated)
	{
		CRect rect;
		GetWindowRect( &rect );
		m_wndSplitter.SetRowInfo(0, rect.Height()>>1, 10);
		m_wndSplitter2.SetColumnInfo(0, rect.Width()>>1, 10);
		m_wndSplitter.RecalcLayout();
		m_wndSplitter2.RecalcLayout();
	}
	return true;

	//return CFrameWnd::OnCreateClient(lpcs, pContext);
}


void CMainFrm::Init()
{
	((CViewOutput*)m_wndSplitter.GetPane(1, 0))->Init();
	((CFormTask*)m_wndSplitter2.GetPane(0, 0))->Init( (CViewTaskList*)(m_wndSplitter2.GetPane(0, 1)) );
}



void CMainFrm::OnUpdateFileOpen(CCmdUI *pCmdUI)
{
	// TODO: Add your command update UI handler code here

	// because this application has no document, so no message route to client area sub-view, we should dispatch manually.
	((CFormTask*)(m_wndSplitter2.GetPane(0, 0)))->OnUpdateFileOpen(pCmdUI);
}

void CMainFrm::OnFileOpen()
{
	// TODO: Add your command handler code here

	// because this application has no document, so no message route to client area sub-view, we should dispatch manually.
	m_wndSplitter2.GetPane(0, 0)->PostMessage(WM_COMMAND, ID_FILE_OPEN, NULL);
}

void CMainFrm::OnFileFont()
{
	// TODO: Add your command handler code here
	// because this application has no document, so no message route to client area sub-view, we should dispatch manually.
	m_wndSplitter.GetPane(1, 0)->PostMessage(WM_COMMAND, ID_FILE_FONT, NULL);
}

void CMainFrm::OnClose()
{
	// TODO: Add your message handler code here and/or call default

	((CFormTask*)m_wndSplitter2.GetPane(0, 0))->WaitScheduleThreadEnd();
	CFrameWnd::OnClose();
}



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions