CartonRippleView.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:9k
- // CartonRippleView.cpp : implementation of the CCartonRippleView class
- //
- #include "stdafx.h"
- #include "CartonRipple.h"
- #include "math.h"
- #include "CartonRippleDoc.h"
- #include "CartonRippleView.h"
- #include "SampleDlg.h"
- #include "MainFrm.h"
- #include <time.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCartonRippleView
- IMPLEMENT_DYNCREATE(CCartonRippleView, CView)
- BEGIN_MESSAGE_MAP(CCartonRippleView, CView)
- //{{AFX_MSG_MAP(CCartonRippleView)
- ON_WM_TIMER()
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_COMMAND(ID_LOAD_FILE, OnLoadFile)
- ON_COMMAND(ID_RAIN_EFFECT, OnRainEffect)
- ON_COMMAND(ID_STONE_EFFECT, OnStoneEffect)
- ON_COMMAND(ID_SETTING_PARAMETER, OnSettingParameter)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCartonRippleView construction/destruction
- CCartonRippleView::CCartonRippleView()
- {
- // TODO: add construction code here
- m_iMouseClickedRadius=50;
- m_iMouseClickedHeight=500;
- m_iMouseMoveRadius=5;
- m_iMouseMoveHeight=50;
- m_iRainFrequency=60;
- m_pParameterDlg=NULL;
- m_iRefreshFrequency=30;
- }
- CCartonRippleView::~CCartonRippleView()
- {
- if(m_pParameterDlg!=NULL)
- {
- delete m_pParameterDlg;
- }
- }
- BOOL CCartonRippleView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCartonRippleView drawing
- void CCartonRippleView::OnDraw(CDC* pDC)
- {
- CCartonRippleDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCartonRippleView printing
- BOOL CCartonRippleView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CCartonRippleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CCartonRippleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCartonRippleView diagnostics
- #ifdef _DEBUG
- void CCartonRippleView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CCartonRippleView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CCartonRippleDoc* CCartonRippleView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCartonRippleDoc)));
- return (CCartonRippleDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CCartonRippleView message handlers
- void CCartonRippleView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(nIDEvent==1)
- {
- m_myWater.Render((DWORD*)m_bmpRenderSource.GetDIBits(),(DWORD*)m_bmpRenderTarget.GetDIBits());
- CClientDC dc(this);
- CPoint ptOrigin(0,0);
- m_bmpRenderTarget.Draw(&dc,ptOrigin);
- }
- if(nIDEvent==2)//rain
- {
- CPoint point;
- int count=rand()%8+2;//同时激活的雨滴数目
- while(count>0)
- {
- point.x = rand()%BMP_WIDTH;
- point.y = rand()%BMP_HEIGHT;
- //=5;
- //=50;
- //m_myWater.HeightBlob(point.x,point.y,10+rand()%20,60-rand()%20,m_myWater.m_iHpage);
- m_myWater.HeightBlob(point.x,point.y,m_iMouseMoveRadius+rand()%10,m_iMouseMoveHeight+rand()%10,m_myWater.m_iHpage);
- count--;
- }
- m_myWater.Render((DWORD*)m_bmpRenderSource.GetDIBits(),(DWORD*)m_bmpRenderTarget.GetDIBits());
- CClientDC dc(this);
- CPoint ptOrigin(0,0);
- m_bmpRenderTarget.Draw(&dc,ptOrigin);
- }
- CView::OnTimer(nIDEvent);
- }
- void CCartonRippleView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- point.y -= 20;
- point.y = BMP_HEIGHT-point.y;
- m_myWater.HeightBlob(point.x-15,point.y,m_iMouseClickedRadius,m_iMouseClickedHeight,
- m_myWater.m_iHpage);
- CView::OnLButtonDown(nFlags, point);
- }
- void CCartonRippleView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- point.y -= 20;
- point.y = BMP_HEIGHT-point.y;
- m_myWater.HeightBlob(point.x -15,point.y,m_iMouseMoveRadius,m_iMouseMoveHeight,m_myWater.m_iHpage);
- m_myWater.Render((DWORD*)m_bmpRenderSource.GetDIBits(),(DWORD*)m_bmpRenderTarget.GetDIBits());
- CClientDC dc(this);
- CPoint ptOrigin(0,0);
- m_bmpRenderTarget.Draw(&dc,ptOrigin);
- CView::OnMouseMove(nFlags, point);
- }
- BOOL CCartonRippleView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
- void CCartonRippleView::OnLoadFile()
- {
- // TODO: Add your command handler code here
- static bool first=true;
- if(!first)
- {
- KillTimer(1);
- KillTimer(2);
- first=true;
- m_bmpRenderSource.DeleteObject();
- m_bmpRenderTarget.DeleteObject();
- }
- CSampleDlg dlg;
- if(dlg.DoModal()==IDOK)
- {
- CPictureHolder myTmpPicture;
- switch(dlg.m_iSelected)
- {
- case 0:
- myTmpPicture.CreateFromBitmap(IDB_BITMAP1);
- break;
- case 1:
- myTmpPicture.CreateFromBitmap(IDB_BITMAP4);
- break;
- case 2:
- myTmpPicture.CreateFromBitmap(IDB_BITMAP3);
- break;
- case 3:
- myTmpPicture.CreateFromBitmap(IDB_BITMAP2);
- break;
- }
- m_bmpRenderSource.Create32BitFromPicture(&myTmpPicture,BMP_WIDTH,BMP_HEIGHT);
- m_bmpRenderTarget.Create32BitFromPicture(&myTmpPicture,BMP_WIDTH,BMP_HEIGHT);
- //创建水纹对象
- m_myWater.Create(BMP_WIDTH,BMP_HEIGHT);
- }
- if(first)
- {
- SetTimer(1,m_iRefreshFrequency,NULL);
- first=false;
- }
- CMenu *menu=((CMainFrame*)(AfxGetMainWnd()))->GetMenu();
- CMenu * sub =menu->GetSubMenu(3);
- sub->EnableMenuItem(ID_RAIN_EFFECT, MF_ENABLED);
- // sub->EnableMenuItem(ID_STONE_EFFECT,MF_ENABLED);
- }
- void CCartonRippleView::ResetRefreshFrequency()
- {
- KillTimer(1);
- SetTimer(1,m_iRefreshFrequency,NULL);
- }
- void CCartonRippleView::OnRainEffect()
- {
- // TODO: Add your command handler code here
- static bool first=true;
- if(!first)
- {
- KillTimer(2);
- CMenu *menu=((CMainFrame*)(AfxGetMainWnd()))->GetMenu();
- CMenu * sub =menu->GetSubMenu(3);
- sub->ModifyMenu(2,MF_STRING,0,"ssss");
- sub->EnableMenuItem(ID_RAIN_EFFECT, MF_ENABLED);
- sub->EnableMenuItem(ID_STONE_EFFECT,MF_ENABLED);
- first=true;
- }
- else
- {
- first=false;
- srand((unsigned int)time(NULL));
- SetTimer(2,m_iRainFrequency,NULL);
- }
- }
- //interface for class CParameterSettingDlg
- void CCartonRippleView::ResetRainEffect()
- {
- // TODO: Add your command handler code here
- KillTimer(2);
- srand((unsigned int)time(NULL));
- SetTimer(2,m_iRainFrequency,NULL);
- }
- //这个函数现在负责填充障碍物
- void CCartonRippleView::OnStoneEffect()
- {
- // TODO: Add your command handler code here
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory( &si, sizeof(si) );
- si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- // Start the child process.
- if( !CreateProcess( NULL, // No module name (use command line).
- "ScanConverting.exe", // Command line.
- NULL, // Process handle not inheritable.
- NULL, // Thread handle not inheritable.
- FALSE, // Set handle inheritance to FALSE.
- 0, // No creation flags.
- NULL, // Use parent's environment block.
- NULL, // Use parent's starting directory.
- &si, // Pointer to STARTUPINFO structure.
- &pi ) // Pointer to PROCESS_INFORMATION structure.
- )
- {
- AfxMessageBox("创建子进程失败!");
- }
- // Wait until child process exits.
- WaitForSingleObject( pi.hProcess, INFINITE );
- // Close process and thread handles.
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
-
- m_myWater.LoadBarrierData();
- }
- void CCartonRippleView::OnSettingParameter()
- {
- // TODO: Add your command handler code here
- static bool first=true;
- if(first)
- {
- m_pParameterDlg= new CParameterSettingDlg;
- m_pParameterDlg->Init(this);
- if(!m_pParameterDlg->Create(IDD_DIALOG2,AfxGetMainWnd()))
- {
- AfxMessageBox("Error creating Dialog");
- }
- first=false;
- }
- m_pParameterDlg->ShowWindow(SW_SHOW);
- }