www.pudn.com > IFSEditor.rar > IFSEditor.cpp
// IFSEditor.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "IFSEditor.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "IFSEditorDoc.h"
#include "IFSEditorView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIFSEditorApp
BEGIN_MESSAGE_MAP(CIFSEditorApp, CWinApp)
//{{AFX_MSG_MAP(CIFSEditorApp)
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
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIFSEditorApp construction
CIFSEditorApp::CIFSEditorApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CIFSEditorApp object
CIFSEditorApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CIFSEditorApp initialization
BOOL CIFSEditorApp::InitInstance()
{
AfxEnableControlContainer();
// 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
// Set Rand Seed
srand((unsigned)time(NULL));
// 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"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_IFSTYPE,
RUNTIME_CLASS(CIFSEditorDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CIFSEditorView));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if(cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
{
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
}
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
HICON m_hIcon;
int m_AveEnergy;
int m_RectWidth,m_RectHeight;
int m_BmpWidth,m_BmpHeight;
int *m_pLastPlane;
int *m_pCurPlane;
int *m_pV;
int m_BPP;
BYTE *m_pBackBmp;
BYTE *m_pCurBmp;
CBitmap m_Back;
CAboutDlg();
~CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
m_AveEnergy=0;
m_Back.LoadBitmap(IDB_BITMAP1);
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pLastPlane=NULL;
m_pCurPlane=NULL;
m_pBackBmp=NULL;
m_pCurBmp=NULL;
m_pV=NULL;
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
CAboutDlg::~CAboutDlg()
{
m_Back.DeleteObject();
if(m_pLastPlane)
{
delete []m_pLastPlane;
}
if(m_pCurPlane)
{
delete []m_pCurPlane;
}
if(m_pBackBmp)
{
delete []m_pBackBmp;
}
if(m_pCurBmp)
{
delete []m_pCurBmp;
}
if(m_pV)
{
delete []m_pV;
}
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rect;
GetClientRect(rect);
m_RectWidth=rect.Width();
m_RectHeight=rect.Height();
BITMAP BmpInfo;
m_Back.GetBitmap(&BmpInfo);
m_BmpWidth=BmpInfo.bmWidth;
m_BmpHeight=BmpInfo.bmHeight;
m_BPP=BmpInfo.bmBitsPixel;
m_pLastPlane=new int[m_RectWidth*m_RectHeight];
m_pCurPlane=new int[m_RectWidth*m_RectHeight];
m_pV=new int[m_RectWidth*m_RectHeight];
memset(m_pLastPlane,0,m_RectWidth*m_RectHeight*sizeof(int));
memset(m_pCurPlane,0,m_RectWidth*m_RectHeight*sizeof(int));
memset(m_pV,0,m_RectWidth*m_RectHeight*sizeof(int));
m_pBackBmp=new BYTE[m_BmpWidth*m_BmpHeight*m_BPP/8];
m_pCurBmp=new BYTE[m_BmpWidth*m_BmpHeight*m_BPP/8];
m_Back.GetBitmapBits(m_BmpWidth*m_BmpHeight*m_BPP/8,m_pBackBmp);
memcpy(m_pCurBmp,m_pBackBmp,m_BmpWidth*m_BmpHeight*m_BPP/8*sizeof(BYTE));
SetTimer(1,50,NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
}
void CAboutDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap *pOldBmp;
pOldBmp=(CBitmap *)memdc.SelectObject(&m_Back);
CFont *pFont,NewFont;
pFont=memdc.GetCurrentFont();
LOGFONT LogFont;
pFont->GetLogFont(&LogFont);
LogFont.lfCharSet=GB2312_CHARSET;
strcpy(LogFont.lfFaceName,"宋体");
LogFont.lfHeight=12;
LogFont.lfWidth=0;
LogFont.lfWeight=FW_NORMAL;
NewFont.CreateFontIndirect(&LogFont);
memdc.SelectObject(&NewFont);
memdc.SetBkMode(TRANSPARENT);
CRect rectText;
rectText.right=m_RectWidth-1;
rectText.bottom=m_RectHeight-1;
rectText.left=0;
rectText.top=53;
CString s;
memdc.DrawIcon(m_RectWidth/2-16,12,m_hIcon);
s.Format("IFS编辑器 1.0 版\n\n版权所有(C) 2005\n\n浙江大学 信电系2001级 沈捷 设计制作");
memdc.DrawText(s,rectText,DT_CENTER);
memdc.SetBkMode(OPAQUE);
memdc.SelectObject(pFont);
NewFont.DeleteObject();
dc.BitBlt(0,0,m_RectWidth,m_RectHeight,&memdc,0,0,SRCCOPY);
memdc.SelectObject(pOldBmp);
// Do not call CDialog::OnPaint() for painting messages
}
void CAboutDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
// 波运动
int TempEnergy=0;
if(!(rand()%4))
{
m_pLastPlane[(rand()%m_RectHeight)*m_RectWidth+rand()%m_RectWidth]=-2000;
}
for(int y=0;y>5;//速度的自动衰减
m_pCurPlane[y*m_RectWidth+x]=m_pLastPlane[y*m_RectWidth+x]+m_pV[y*m_RectWidth+x];//下一刻的位移
m_pCurPlane[y*m_RectWidth+x]-=m_pCurPlane[y*m_RectWidth+x]>>7;//位移的衰减
m_pCurPlane[y*m_RectWidth+x]-=m_AveEnergy;
TempEnergy+=m_pCurPlane[y*m_RectWidth+x];
}
}
m_AveEnergy=TempEnergy/(m_RectWidth*m_RectHeight);
//交换缓冲区
int *pTemp=m_pCurPlane;
m_pCurPlane=m_pLastPlane;
m_pLastPlane=pTemp;
for(y=1;y=m_RectWidth) continue;
if(nx<0) continue;
if(ny>=m_RectHeight) continue;
if(ny<0) continue;
for(int i=0;i<=m_BPP/8-1;i++)
{
m_pCurBmp[(y*m_BmpWidth+x)*m_BPP/8+i]=m_pBackBmp[(ny*m_BmpWidth+nx)*m_BPP/8+i];
}
}
}
m_Back.SetBitmapBits(m_BmpWidth*m_BmpHeight*m_BPP/8,m_pCurBmp);
Invalidate(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(point.x>=0&&point.x<=m_RectWidth-1&&point.y>=0&&point.y<=m_RectHeight-1)
{
m_pLastPlane[point.y*m_RectWidth+point.x]=-2000;
}
CDialog::OnMouseMove(nFlags, point);
}
BOOL CAboutDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
// 不做处理
return TRUE;
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CIFSEditorApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CIFSEditorApp message handlers