⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wgos.cpp

📁 一个简单而又高效的嵌入式操作系统.包括GUI及文件系统.仿Windows设计,类似于MFC风格
💻 CPP
字号:
// WGOS.cpp : Defines the class behaviors for the application.
//

#include "Wstdafx.h"
#include "WGOS.h"
#include "WMainFrm.h"
#include "GOS_WIN.h"
#include <afxtempl.h>


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

typedef struct _tagTCB
{
	PVOID sp;
	DWORD nTick;
}OS_TCB,*POS_TCB;
extern POS_TCB pOsCurThread;
extern POS_TCB pOsNextThread;
extern BOOL m_bGuiPaint;
extern OS_TCB aOsThread[];
extern void HAL_ENTRY(void);
extern void	HeapFree(void*);
extern int* pOsHeap;
class KFile;


PBITMAPINFO m_pBmpInfo;
HACCEL m_hAccelTable;
CView* m_pView;
CFile fileVFS;
/////////////////////////////////////////////////////////////////////////////
// WGOSApp

BEGIN_MESSAGE_MAP(WGOSApp, CWinApp)
	//{{AFX_MSG_MAP(WGOSApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


extern "C" void HAL_CreateThread(int tcb,int sp1,int sp2,int pFunc)
{
	static int i=THREAD_PRIORITY_NORMAL;
	HeapFree((PVOID)sp1);
	AfxBeginThread((AFX_THREADPROC)pFunc,NULL,++i);
}


extern "C" void Win_OnIdle() 
{
	// TODO: Add your specialized code here and/or call the base class
	MSG msg;

	// Main message loop:
	if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)) 
	{
		if (!TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	else if(m_bGuiPaint)
	{
		m_pView->Invalidate(FALSE);
		m_bGuiPaint=FALSE;
	}
	else
	{
		SleepEx(50,TRUE);
	}
}

BOOL File_WriteBlock(LPVOID pBuf,int nBlock)
{
	UINT nNeedLen=FILE_BLOCKBYTES*(nBlock+1);
	if(fileVFS.GetLength()<nNeedLen)fileVFS.SetLength(nNeedLen);
	fileVFS.Seek(nNeedLen-FILE_BLOCKBYTES,CFile::begin);
	fileVFS.Write(pBuf,FILE_BLOCKBYTES);
	return TRUE;
}

BOOL File_ReadBlock(LPVOID pBuf,int nBlock)
{
	UINT nNeedLen=FILE_BLOCKBYTES*(nBlock+1);
	if(fileVFS.GetLength()<nNeedLen)fileVFS.SetLength(nNeedLen);
	fileVFS.Seek(nNeedLen-FILE_BLOCKBYTES,CFile::begin);
	fileVFS.Read(pBuf,FILE_BLOCKBYTES);
	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// WGOSApp construction

WGOSApp::WGOSApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only WGOSApp object

WGOSApp theApp;

/////////////////////////////////////////////////////////////////////////////
// WGOSApp initialization

BOOL WGOSApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	// To create the main window, this code creates a new frame window
	// object and then sets it as the application's main window object.
	WMainFrame* pFrame = new WMainFrame;
	m_pMainWnd = pFrame;

	// create and load the frame with its resources

	pFrame->LoadFrame(IDR_MAINFRAME,
		WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
		NULL);




	// The one and only window has been initialized, so show and update it.
	pFrame->ShowWindow(SW_SHOW);
	pFrame->UpdateWindow();

	CRect rView,rFrame;
	pFrame->GetWindowRect(rFrame);
	m_pView->GetClientRect(rView);
	rFrame.right+=GUI_CXSCREEN*2-rView.Width();
	rFrame.bottom+=GUI_CYSCREEN*2-rView.Height();
	pFrame->MoveWindow(rFrame);

	m_pBmpInfo=(PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*3);
	BITMAPINFOHEADER& bh=m_pBmpInfo->bmiHeader;
	RGBQUAD* bc=m_pBmpInfo->bmiColors;

	bh.biSize=sizeof(BITMAPINFOHEADER);
	bh.biWidth=GUI_CXSCREEN;
	bh.biHeight=GUI_CYSCREEN;
	bh.biPlanes=1;
	bh.biBitCount=16;
	bh.biCompression=BI_BITFIELDS;
	bh.biSizeImage=GUI_CXSCREEN*GUI_CYSCREEN*2;
	bh.biXPelsPerMeter=3270;
	bh.biYPelsPerMeter=3270;
	bh.biClrUsed=0;
	bh.biClrImportant=0;
	*PDWORD(&bc[0])=31<<11;
	*PDWORD(&bc[1])=63<<5;
	*PDWORD(&bc[2])=31;

	CString str;
	LPTSTR szPath=str.GetBuffer(1024);
	::GetModuleFileName(NULL,szPath,1024);
	str.ReleaseBuffer();
	int nAT=str.ReverseFind('.');
	str=str.Left(nAT+1)+"TXT";
	nAT=fileVFS.Open(str,CFile::modeReadWrite);
	if(!nAT)
	{
		nAT=fileVFS.Open(str,CFile::modeCreate);
	}

	HAL_ENTRY(); 

	fileVFS.Close();
	free(m_pBmpInfo);
	return FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// WGOSApp message handlers





/////////////////////////////////////////////////////////////////////////////
// WAboutDlg dialog used for App About

class WAboutDlg : public CDialog
{
public:
	WAboutDlg();

// Dialog Data
	//{{AFX_DATA(WAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(WAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(WAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

WAboutDlg::WAboutDlg() : CDialog(WAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(WAboutDlg)
	//}}AFX_DATA_INIT
}

void WAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(WAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(WAboutDlg, CDialog)
	//{{AFX_MSG_MAP(WAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void WGOSApp::OnAppAbout()
{
	WAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// WGOSApp message handlers


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -