心跳检测View.cpp
上传用户:dtengfei
上传日期:2013-01-16
资源大小:393k
文件大小:16k
源码类别:

医药行业

开发平台:

Visual C++

  1. // 心跳检测View.cpp : implementation of the CMyView class
  2. //
  3. #include "stdafx.h"
  4. #include "心跳检测.h"
  5. #include "math.h"
  6. #include "心跳检测Doc.h"
  7. #include "心跳检测View.h"
  8. #include "Mainfrm.h"
  9. #include <windowsx.h>
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMyView
  17. IMPLEMENT_DYNCREATE(CMyView, CFormView)
  18. BEGIN_MESSAGE_MAP(CMyView, CFormView)
  19. //{{AFX_MSG_MAP(CMyView)
  20. ON_WM_PAINT()
  21. ON_BN_CLICKED(IDC_EXIT, OnExit)
  22. ON_BN_CLICKED(IDC_PRINT, OnMyPrint)
  23. ON_BN_CLICKED(IDC_OPEN, OnOpen)
  24. ON_BN_CLICKED(IDC_SAVE, OnSave)
  25. ON_BN_CLICKED(IDC_STOP, OnStop)
  26. ON_BN_CLICKED(IDC_PLAY, OnPlay)
  27. ON_BN_CLICKED(IDC_REFURBISH, OnRefurbish)
  28. ON_WM_CREATE()
  29. ON_BN_CLICKED(IDC_BITMAP, OnBitmap)
  30. //}}AFX_MSG_MAP
  31. // Standard printing commands
  32. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  33. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  34. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMyView construction/destruction
  38. CMyView::CMyView()
  39. : CFormView(CMyView::IDD)
  40. {
  41. //{{AFX_DATA_INIT(CMyView)
  42. m_StartT = 0;
  43. m_EndT = 0;
  44. m_TopE = 0;
  45. m_BottomE = 0;
  46. m_E = _T("");
  47. m_F = _T("");
  48. //}}AFX_DATA_INIT
  49. // TODO: add construction code here
  50. m_TopE=100;
  51. m_EndT=1;
  52.     m_pMemDC=new CDC;
  53. //m_pBitmap=new CBitmap;
  54. }
  55. CMyView::~CMyView()
  56. {
  57. delete m_pMemDC;
  58. //delete m_pBitmap;
  59. }
  60. void CMyView::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CFormView::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CMyView)
  64. DDX_Text(pDX, IDC_START_T, m_StartT);
  65. DDV_MinMaxInt(pDX, m_StartT, 0, 29);
  66. DDX_Text(pDX, IDC_END_T, m_EndT);
  67. DDV_MinMaxInt(pDX, m_EndT, 1, 30);
  68. DDX_Text(pDX, IDC_TOP_E, m_TopE);
  69. DDX_Text(pDX, IDC_BOTTOM_E, m_BottomE);
  70. DDX_Text(pDX, IDC_E, m_E);
  71. DDX_Text(pDX, IDC_F, m_F);
  72. //}}AFX_DATA_MAP
  73. DDX_Control(pDX, IDC_PLAY, m_Play);
  74. DDX_Control(pDX, IDC_STOP, m_Stop);
  75. DDX_Control(pDX, IDC_TRANSACT, m_Transact);
  76. DDX_Control(pDX, IDC_SAVE, m_Save);
  77. DDX_Control(pDX, IDC_OPEN, m_Open);
  78. DDX_Control(pDX, IDC_PRINT, m_Print);
  79. DDX_Control(pDX, IDC_EXIT, m_Exit);
  80. DDX_Control(pDX, IDC_REFURBISH,m_Refurbish);
  81. }
  82. BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
  83. {
  84. // TODO: Modify the Window class or styles here by modifying
  85. //  the CREATESTRUCT cs
  86. return CFormView::PreCreateWindow(cs);
  87. }
  88. void CMyView::OnInitialUpdate()
  89. {
  90. CFormView::OnInitialUpdate();
  91. // GetParentFrame()->RecalcLayout();
  92. // ResizeParentToFit();
  93. m_Play.SetIcon(IDI_PLAY);
  94. m_Play.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  95. m_Play.DrawFlatFocus(TRUE);
  96. // m_Play.SetTooltipText(_T("开始运行"));
  97. m_Stop.SetIcon(IDI_STOP);
  98. m_Stop.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  99. m_Stop.DrawFlatFocus(TRUE);
  100. m_Transact.SetIcon(IDI_TRANSACT);
  101. m_Transact.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  102. m_Transact.DrawFlatFocus(TRUE);
  103. m_Save.SetIcon(IDI_SAVE);
  104. m_Save.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  105. m_Save.DrawFlatFocus(TRUE);
  106. m_Open.SetIcon(IDI_OPEN);
  107. m_Open.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  108. m_Open.DrawFlatFocus(TRUE);
  109. m_Print.SetIcon(IDI_PRINT);
  110. m_Print.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  111. m_Print.DrawFlatFocus(TRUE);
  112. m_Exit.SetIcon(IDI_EXIT1,IDI_EXIT);
  113. m_Exit.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  114. m_Exit.DrawFlatFocus(TRUE);
  115. m_Refurbish.SetIcon(IDI_REFURBISH1,IDI_REFURBISH);
  116. m_Refurbish.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 50);
  117. m_Refurbish.DrawFlatFocus(TRUE);
  118. }
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CMyView printing
  121. BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
  122. {
  123. // default preparation
  124. return DoPreparePrinting(pInfo);
  125. }
  126. void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  127. {
  128. // TODO: add extra initialization before printing
  129. }
  130. void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  131. {
  132. // TODO: add cleanup after printing
  133. }
  134. void CMyView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  135. {
  136. // TODO: add customized printing code here
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CMyView diagnostics
  140. #ifdef _DEBUG
  141. void CMyView::AssertValid() const
  142. {
  143. CFormView::AssertValid();
  144. }
  145. void CMyView::Dump(CDumpContext& dc) const
  146. {
  147. CFormView::Dump(dc);
  148. }
  149. CMyDoc* CMyView::GetDocument() // non-debug version is inline
  150. {
  151. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
  152. return (CMyDoc*)m_pDocument;
  153. }
  154. #endif //_DEBUG
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CMyView message handlers
  157. void CMyView::OnPaint() 
  158. {
  159. CPaintDC dc(this); // device context for painting
  160. // TODO: Add your message handler code here
  161. CBitmap* pOldBitmap=m_pMemDC->SelectObject(&m_pBitmap);
  162.    //copy the memory DC to show DC
  163. dc.BitBlt(170,50,m_MaxX-150,m_MaxY-50,m_pMemDC,0,0,SRCCOPY);
  164. m_pMemDC->SelectObject(pOldBitmap);
  165. // DrawCordinate(&dc);
  166. // DrawLine(&dc);
  167. // Do not call CFormView::OnPaint() for painting messages
  168. }
  169. void CMyView::OnExit() 
  170. {
  171. // TODO: Add your control notification handler code here
  172. PostMessage(WM_QUIT);
  173. }
  174. void CMyView::OnMyPrint() 
  175. {
  176. // TODO: Add your control notification handler code here
  177. ShellExecute(GetSafeHwnd(),"open","C:\Program Files\office\Office\Winword.exe",NULL,NULL,SW_SHOWNORMAL);
  178. }
  179. void CMyView::OnOpen() 
  180. {
  181. // TODO: Add your control notification handler code here
  182. CFileDialog dlg(TRUE,"dot",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  183. "心跳检测数据(*.dot)|*.dot|所有文件(*.*)|*.*||",this);
  184.     if(dlg.DoModal()==IDCANCEL)
  185.  return;
  186. PathName=dlg.GetPathName();
  187. CStdioFile file;
  188. if(file.Open(PathName,CFile::modeRead)==0)
  189. {
  190. MessageBox("打文件"+PathName+"失败!","提示",MB_OK+MB_ICONWARNING);
  191. return;
  192. }
  193. //save the data
  194. Openfile(&file);
  195. //close the file
  196. file.Close();
  197. }
  198. void CMyView::OnSave() 
  199. {
  200. // TODO: Add your control notification handler code here
  201. CFileDialog dlg(FALSE,"dot","未命名",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  202. "心跳检测数据(*.dot)|*.dot|所有文件(*.*)|*.*||",this);
  203.     if(dlg.DoModal()==IDCANCEL)
  204.  return;
  205. PathName=dlg.GetPathName();
  206. CStdioFile file;
  207. if(file.Open(PathName,CFile::modeCreate|CFile::modeWrite)==0)
  208. {
  209. MessageBox("打文件"+PathName+"失败!","提示",MB_OK+MB_ICONWARNING);
  210. return;
  211. }
  212. //save the data
  213. SaveFile(&file);
  214. //close the file
  215. }
  216. void CMyView::OnStop() 
  217. {
  218. // TODO: Add your control notification handler code here
  219. CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
  220. m_pFrm->TP.runing=FALSE;
  221. }
  222. void CMyView::OnPlay() 
  223. {
  224. // TODO: Add your control notification handler code here
  225. CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
  226. OnStop();
  227. Sleep(100);
  228. m_pFrm->TP.PointNumber=0;
  229. /* for(int i=0;i<=m_pFrm->TP.WholeNumber;i++)
  230. {
  231. m_pFrm->TP.data[i]=0;
  232. m_pFrm->TP.data1[i]=0;
  233. }
  234. */
  235. /* for(int i=0;i<100;i++)
  236. {
  237. m_pFrm->TP.data[i]=fsimpf(i);
  238. m_pFrm->TP.data1[i]=fsimp(0,i,0.00001);
  239. }
  240. */
  241. m_pFrm->TP.runing=TRUE;
  242. ::PostThreadMessage(m_pFrm->m_JiqiThreadID,WM_CELIANG,long(&m_pFrm->TP),NULL);
  243. }
  244. void CMyView::OnRefurbish() 
  245. {
  246. // TODO: Add your control notification handler code here
  247. }
  248. void CMyView::Draw(int Point)
  249. {
  250. // Invalidate(FALSE);
  251. CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
  252. m_E.Format("%3.3f",m_pFrm->TP.data[Point]);
  253. m_F.Format("%3.3f",float(Point));
  254. UpdateData(FALSE);
  255. DrawCordinate();
  256. DrawLine();
  257. }
  258. int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  259. {
  260. if (CFormView::OnCreate(lpCreateStruct) == -1)
  261. return -1;
  262. // TODO: Add your specialized creation code here
  263. InitData();
  264. CDC* pDC=GetDC();
  265. m_MaxX=GetSystemMetrics(SM_CXSCREEN);
  266. m_MaxY=GetSystemMetrics(SM_CYSCREEN);
  267. m_pMemDC->CreateCompatibleDC(pDC);
  268. m_pBitmap.CreateCompatibleBitmap(pDC,m_MaxX,m_MaxY);
  269. ReleaseDC(pDC);
  270. DrawCordinate();
  271. return 0;
  272. }
  273. void CMyView::DrawCordinate()
  274. {
  275. CBitmap* pOldBitmap=m_pMemDC->SelectObject(&m_pBitmap);
  276. CString str;
  277. //建立字体
  278. CFont fontBT;
  279. m_FontView.lfHeight=20;
  280. m_FontView.lfEscapement=0;
  281. m_FontView.lfOrientation=0;
  282. fontBT.CreateFontIndirect(&m_FontView);
  283. CFont fontXiao;
  284. m_FontView.lfHeight=15;
  285. fontXiao.CreateFontIndirect(&m_FontView);
  286. CFont* pOldFont=m_pMemDC->SelectObject(&fontBT);
  287. m_pMemDC->SetTextColor(0);
  288. m_pMemDC->SetBkMode(TRANSPARENT);
  289. //填充背景
  290. CBrush *brush;
  291. brush=new CBrush(RGB(255,255,255));
  292. CBrush *pOldBrush=m_pMemDC->SelectObject(brush);
  293.     m_pMemDC->FillRect (CRect(LeftRange,TopRange,m_MaxX,m_MaxY),brush);
  294. //装饰条
  295. CPen pen(PS_SOLID,2, RGB(0,0,0));
  296. CPen *pOldPen=m_pMemDC->SelectObject(&pen);
  297. m_pMemDC->MoveTo(LeftRange, 0);
  298. m_pMemDC->LineTo(LeftRange, 768);
  299. m_pMemDC->MoveTo(LeftRange, TopRange);
  300. m_pMemDC->LineTo(1024, TopRange);
  301. CPen pen1(PS_DOT, 1, RGB(150,150,150));
  302. CPen pen2(PS_SOLID, 1, RGB(0,0,0));
  303. //画刻度
  304.     CRect rect(left,top,right,bottom);
  305.     m_pMemDC->Rectangle(rect);
  306. int i;
  307. //画下坐标
  308. double Xinter,Yinter;
  309. if(m_EndT-m_StartT==1)
  310. {
  311. Xinter=(right-left)/100.0;
  312. m_pMemDC->SelectObject(&pen1);
  313. for(i=1;i<100;i++)
  314. {
  315. m_pMemDC->MoveTo(int(left+i*Xinter),top);
  316. m_pMemDC->LineTo(int(left+i*Xinter),bottom);
  317. }
  318. m_pMemDC->SelectObject(&pen2);
  319. for(i=1;i<10;i++)
  320. {
  321. m_pMemDC->MoveTo(int(left+i*Xinter*10),top);
  322. m_pMemDC->LineTo(int(left+i*Xinter*10),bottom);
  323. }
  324. m_pMemDC->SelectObject(&fontXiao);
  325. for(i=0;i<=10;i++)
  326. {
  327. str.Format("%i",i*100);
  328. m_pMemDC->TextOut(int(left+i*Xinter*10-8),bottom+5,str);
  329. }
  330. }
  331. //画左坐标
  332. Yinter=(bottom-top)/100.0;
  333. m_pMemDC->SelectObject(&pen1);
  334. for(i=1;i<100;i++)
  335. {
  336. if(i/10.0==int(i/10.0))
  337. continue;
  338. m_pMemDC->MoveTo(left,int(top+i*Yinter));
  339. m_pMemDC->LineTo(right,int(top+i*Yinter));
  340. }
  341. m_pMemDC->SelectObject(&pen2);
  342. for(i=1;i<10;i++)
  343. {
  344. m_pMemDC->MoveTo(left,int(top+i*Yinter*10));
  345. m_pMemDC->LineTo(right,int(top+i*Yinter*10));
  346. }
  347. for(i=1;i<=10;i++)
  348. {
  349. str.Format("%i",i*10);
  350. m_pMemDC->TextOut(left-25,int(bottom-i*Yinter*10-8),str);
  351. }
  352. m_pMemDC->SelectObject(pOldBrush);
  353. m_pMemDC->SelectObject(pOldFont);
  354. m_pMemDC->SelectObject(pOldPen);
  355. m_pMemDC->SelectObject(pOldBitmap); 
  356. }
  357. void CMyView::InitData()
  358. {
  359. m_FontView.lfHeight=15;
  360. m_FontView.lfWidth=0;
  361. m_FontView.lfEscapement=0;
  362. m_FontView.lfOrientation=0;
  363. m_FontView.lfWeight=FW_NORMAL;
  364. m_FontView.lfItalic=FALSE;
  365. m_FontView.lfUnderline=FALSE;
  366. m_FontView.lfStrikeOut=FALSE;
  367. m_FontView.lfCharSet=GB2312_CHARSET;
  368. m_FontView.lfOutPrecision=OUT_STROKE_PRECIS;
  369. m_FontView.lfClipPrecision=CLIP_STROKE_PRECIS;
  370. m_FontView.lfQuality=DRAFT_QUALITY;
  371. m_FontView.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN;
  372. strcpy(m_FontView.lfFaceName,"System");
  373. TopRange=0;
  374. LeftRange=0;
  375. left=LeftRange+40;
  376. right=820;
  377. top=TopRange+20;
  378. bottom=630;
  379. }
  380. void CMyView::DrawLine()
  381. {
  382. CBitmap* pOldBitmap=m_pMemDC->SelectObject(&m_pBitmap);
  383. CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
  384. CPen pen1(PS_SOLID, 1, RGB(255,0,0));
  385. CPen *pOldPen = m_pMemDC->SelectObject(&pen1);
  386. double Xinter,Yinter;
  387. Xinter=(right-left)/float(m_pFrm->TP.WholeNumber);
  388. Yinter=(bottom-top)/100.0;
  389. /*
  390. for(int i=1;i<=m_pFrm->TP.PointNumber;i++)
  391. {
  392. int e1=int(bottom-m_pFrm->TP.data[i-1]*Yinter);
  393. int e2=int(bottom-m_pFrm->TP.data[i]*Yinter);
  394. if(e1<top) e1=top;
  395. if(e1>bottom) e1=bottom;
  396. if(e2<top) e2=top;
  397. if(e2>bottom) e2=bottom;
  398. m_pMemDC->MoveTo(int(left+(i-1)*Xinter),e1);
  399. m_pMemDC->LineTo(int(left+i*Xinter),e2);
  400. }
  401. */
  402. for(int i=1;i<m_pFrm->TP.PointNumber;i++)
  403. {
  404. int e1=int(bottom-m_pFrm->TP.data[i-1]*Yinter);
  405. int e2=int(bottom-m_pFrm->TP.data[i]*Yinter);
  406. int e3=int(bottom-m_pFrm->TP.data1[i-1]*Yinter);
  407. int e4=int(bottom-m_pFrm->TP.data1[i]*Yinter);
  408. m_pMemDC->MoveTo(int(left+(i-1)*Xinter),e1);
  409. m_pMemDC->LineTo(int(left+i*Xinter),e2);
  410. m_pMemDC->MoveTo(int(left+(i-1)*Xinter),e3);
  411. m_pMemDC->LineTo(int(left+i*Xinter),e4);
  412. }
  413. m_pMemDC->SelectObject(pOldPen);
  414. m_pMemDC->SelectObject(pOldBitmap); 
  415. Invalidate(FALSE);
  416. }
  417. void CMyView::SaveFile(CStdioFile *file)
  418. {
  419. CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
  420. CString mStr;
  421. for(int i=0;i<m_pFrm->TP.PointNumber;i++)
  422. {
  423. if(m_pFrm->TP.data[i]<0)
  424. break;
  425. }
  426. mStr.Format("采集点共:%dn",i);
  427. file->WriteString(mStr);
  428. for(int j=0;j<i;j++)
  429. {
  430. mStr.Format("采集点%d:%3.4fn",j,m_pFrm->TP.data[j]);
  431. file->WriteString(mStr);
  432. }
  433. }
  434. void CMyView::Openfile(CStdioFile *file)
  435. {
  436. CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
  437. CString mStr;
  438. int j;
  439. CEdit* pEdit;
  440. CString str;
  441. file->ReadString(mStr);
  442. j=mStr.Find(":",0)+1;
  443. mStr=mStr.Right(mStr.GetLength()-j);
  444. pEdit=(CEdit *)GetDlgItem(IDC_F);
  445. pEdit->SetSel(0,-1);
  446. pEdit->ReplaceSel(mStr);
  447. m_pFrm->TP.PointNumber=atoi(mStr)-1;
  448. str=mStr;
  449. int i;
  450. for(i=0;i<atoi(str);i++)
  451. {
  452. file->ReadString(mStr);
  453. j=mStr.Find(":",0)+1;
  454. mStr=mStr.Right(mStr.GetLength()-j);
  455. m_pFrm->TP.data[i]=atof(mStr);
  456. }
  457. DrawCordinate();
  458. DrawLine();
  459. /* file->Seek(-15,CFile::end);
  460. file->ReadString(mStr);
  461. j=mStr.Find(":",0)+1;
  462. mStr=mStr.Right(mStr.GetLength()-j);
  463. pEdit=(CEdit *)GetDlgItem(IDC_E);
  464. pEdit->SetSel(0,-1);
  465. pEdit->ReplaceSel(mStr);
  466. */
  467. }
  468. void CMyView::OnBitmap() 
  469. {
  470. // TODO: Add your control notification handler code here
  471. CClientDC dc(this);
  472. BITMAP btm;
  473. m_pBitmap.GetBitmap(&btm);
  474. DWORD size=btm.bmWidthBytes*btm.bmHeight;//bmWidthBytes每条扫描线字节数
  475. LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);
  476. /////////////////////////////////////////////
  477. BITMAPINFOHEADER bih;
  478. bih.biBitCount=btm.bmBitsPixel;//每个象素的位数0代表JPEG格式或被指定
  479. bih.biClrImportant=0;//显示位图时所需要的颜色数,若为0则需要所有的颜色数
  480. bih.biClrUsed=0;//指定颜色表中位图所用道的颜色索引数若为0则取最大值
  481. bih.biCompression=0;//压缩格式0指的是未压缩
  482. bih.biHeight=btm.bmHeight;//位图高
  483. bih.biPlanes=1;//必须为一
  484. bih.biSize=sizeof(BITMAPINFOHEADER);//这种结构的大小
  485. bih.biSizeImage=size;//位图大小的字节数
  486. bih.biWidth=btm.bmWidth;//位图宽
  487. bih.biXPelsPerMeter=0;//X方向每米所规定的象素方式
  488. bih.biYPelsPerMeter=0;//
  489. ///////////////////////////////////
  490. GetDIBits(dc,m_pBitmap,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
  491. /////////////////////////////////////////////
  492. BITMAPFILEHEADER bfh;
  493. bfh.bfReserved1=bfh.bfReserved2=0;
  494. bfh.bfType=((WORD)('M'<< 8)|'B');
  495. bfh.bfSize=54+size;
  496. bfh.bfOffBits=54;
  497. /////////////////////////////////////////////
  498. CFile bf;
  499. CFileDialog dlg(FALSE,"txt","未命名",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  500. "心跳检测数据(*.bmp)|*.bmp|所有文件(*.*)|*.*||",this);
  501.     if(dlg.DoModal()==IDCANCEL)
  502.  return;
  503. CString name;
  504. name=dlg.GetPathName();
  505. if(bf.Open(name,CFile::modeCreate|CFile::modeWrite))
  506. {
  507. bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
  508. bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
  509. bf.WriteHuge(lpData,size);
  510. bf.Close();
  511. }
  512. GlobalFreePtr(lpData);
  513. }
  514. double CMyView::fsimpf(double x)
  515. {
  516. double y;
  517.  //   y=log(1.0+x)/(1.0+x*x);
  518. // y=sin(x/50.0);
  519. y=sin(x/10);
  520.     return(y);
  521. }
  522. double CMyView::fsimp(double a, double b, double eps)
  523. {
  524.     int n,k;
  525.     double h,t1,t2,s1,s2,ep,p,x;
  526.     n=1; h=b-a;
  527.     t1=h*(fsimpf(a)+fsimpf(b))/2.0;  /*用梯形公式求出一个大概的估值*/
  528.     s1=t1;
  529.     ep=eps+1.0;
  530.     while (ep>=eps)
  531. {
  532. /*用梯形法则计算*/
  533. p=0.0;
  534. for (k=0;k<=n-1;k++)
  535. {
  536. x=a+(k+0.5)*h;
  537. p=p+fsimpf(x);
  538. }
  539. t2=(t1+h*p)/2.0;
  540. /*用辛普森公式求精*/
  541. s2=(4.0*t2-t1)/3.0;
  542. ep=fabs(s2-s1);
  543. t1=t2; s1=s2; n=n+n; h=h/2.0;
  544. }
  545.     return(s2);
  546. }