📄 subject_33782.htm
字号:
<p>
序号:33782 发表者:苦闷 发表日期:2003-03-24 11:07:24
<br>主题:高分求解
<br>内容:我想让输出的波形每隔1秒钟在正弦波形和余弦波形之间变化。
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:iwill 回复日期:2003-03-24 11:34:18
<br>内容:算法有问题,在不修改算法基础上的视图类的修改:<BR>// item2View.cpp : implementation of the CItem2View class<BR>//<BR><BR>#include "stdafx.h"<BR>#include "item2.h"<BR><BR>#include "item2Doc.h"<BR>#include "item2View.h"<BR>#include"math.h"<BR>#ifdef _DEBUG<BR>#define new DEBUG_NEW<BR>#undef THIS_FILE<BR>static char THIS_FILE[] = __FILE__;<BR>#endif<BR>#define M_PI 3.1415926<BR>/////////////////////////////////////////////////////////////////////////////<BR>// CItem2View<BR><BR>IMPLEMENT_DYNCREATE(CItem2View, CView)<BR><BR>BEGIN_MESSAGE_MAP(CItem2View, CView)<BR> //{{AFX_MSG_MAP(CItem2View)<BR> ON_WM_CREATE()<BR> ON_WM_TIMER()<BR> //}}AFX_MSG_MAP<BR> // Standard printing commands<BR> ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)<BR> ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)<BR> ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)<BR>END_MESSAGE_MAP()<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CItem2View construction/destruction<BR><BR>CItem2View::CItem2View()<BR>{<BR> // TODO: add construction code here<BR><BR>}<BR><BR>CItem2View::~CItem2View()<BR>{<BR>}<BR><BR>BOOL CItem2View::PreCreateWindow(CREATESTRUCT& cs)<BR>{<BR> // TODO: Modify the Window class or styles here by modifying<BR> // the CREATESTRUCT cs<BR><BR> return CView::PreCreateWindow(cs);<BR>}<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CItem2View drawing<BR><BR>void CItem2View::OnDraw(CDC* pDC)<BR>{<BR> CItem2Doc* pDoc = GetDocument();<BR> ASSERT_VALID(pDoc);<BR> // TODO: add draw code for native data here<BR> int i;<BR> static int init=0;<BR> CRect Rect;<BR> double x,y;<BR> GetClientRect(&Rect);<BR> for(i=0;i<=360;i++)<BR> {<BR> COLORREF rgb(RGB(255,0,0));<BR> float x,y;<BR> x= (float)(Rect.left + ((float)i/180) * (Rect.right-Rect.left)*1/2);<BR> y= (float)(Rect.bottom - ((Rect.bottom-Rect.top) * 1/2)-<BR> sin((float)(M_PI *( i-init) /180)) * 120);<BR> pDC->SetPixel(x,y,rgb);<BR> }<BR> init++;<BR> if(init>360)<BR> init=0;<BR>}<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CItem2View printing<BR><BR>BOOL CItem2View::OnPreparePrinting(CPrintInfo* pInfo)<BR>{<BR> // default preparation<BR> return DoPreparePrinting(pInfo);<BR>}<BR><BR>void CItem2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)<BR>{<BR> // TODO: add extra initialization before printing<BR>}<BR><BR>void CItem2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)<BR>{<BR> // TODO: add cleanup after printing<BR>}<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CItem2View diagnostics<BR><BR>#ifdef _DEBUG<BR>void CItem2View::AssertValid() const<BR>{<BR> CView::AssertValid();<BR>}<BR><BR>void CItem2View::Dump(CDumpContext& dc) const<BR>{<BR> CView::Dump(dc);<BR>}<BR><BR>CItem2Doc* CItem2View::GetDocument() // non-debug version is inline<BR>{<BR> ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CItem2Doc)));<BR> return (CItem2Doc*)m_pDocument;<BR>}<BR>#endif //_DEBUG<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CItem2View message handlers<BR><BR>int CItem2View::OnCreate(LPCREATESTRUCT lpCreateStruct) <BR>{<BR> if (CView::OnCreate(lpCreateStruct) == -1)<BR> return -1;<BR> <BR> // TODO: Add your specialized creation code here<BR> SetTimer(1,20,NULL);<BR> return 0;<BR>}<BR><BR>void CItem2View::OnTimer(UINT nIDEvent) <BR>{<BR> // TODO: Add your message handler code here and/or call default<BR> Invalidate();<BR>/* int i;<BR> CRect Rect;<BR> double x,y;<BR> GetClientRect(&Rect);<BR> CDC* pDC=GetDC(); <BR> for(i=0;i<=360;i++)<BR> {<BR> COLORREF rgb(RGB(255,0,0));<BR> float x,y;<BR> x= (float)(Rect.left + ((float)i/180) * (Rect.right-Rect.left)*1/2);<BR> y= (float)(Rect.bottom - ((Rect.bottom-Rect.top) * 1/2)-<BR> cos((float)(M_PI * i /180)) * 120);<BR> pDC->SetPixel(x,y,rgb) ;<BR> }<BR>*/ CView::OnTimer(nIDEvent);<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:苦闷 回复日期:2003-03-24 12:44:18
<br>内容:你这里没有输出余弦波形啊。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:iwill 回复日期:2003-03-24 12:52:31
<br>内容:只是一个相位的问题,自己应该能够解决呀 <BR><BR>CItem2Doc* pDoc = GetDocument();<BR> ASSERT_VALID(pDoc);<BR> // TODO: add draw code for native data here<BR> int i;<BR> static int init=0;<BR> CRect Rect;<BR> double x,y;<BR> GetClientRect(&Rect);<BR> for(i=0;i<=360;i++)<BR> {<BR> COLORREF rgb(RGB(255,0,0));<BR> float x,y;<BR> x= (float)(Rect.left + ((float)i/180) * (Rect.right-Rect.left)*1/2);<BR> y= (float)(Rect.bottom - ((Rect.bottom-Rect.top) * 1/2)-<BR> sin((float)(M_PI *( i+init) /180)) * 120);<BR> pDC->SetPixel(x,y,rgb);<BR> }<BR> init+=90;<BR> if(init>90)<BR> init=0;
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -