在CHlloView的OnDraw(CDC*pDC)函数中添加一行程序如下: void CHello_View::OnDraw(CDC* pDC) { CHello_Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here pDC—〉 TextOut(50,20,\"Hello World!”); } 第二章 实践3
下面列出与添加代码有关的程序片段,ItemEventDoc.h中类CItemEventDoc的定义如下: classCItemEventDoc : public CDocument {
protected: // create from serialization only CItemEventDoc(); DECLARE_DYNCREATE(CItemEventDoc) CString m_String;
ItemEventDoc.cpp中类CItemEventDoc的实现: CItemEventDoc::CItemEventDoc() { // TODO: add one—time construction code here m_String=””;
ItemEventDoc.cpp中类CItemEventView的OnDraw()函数实现: void CItemEventDoc::OnMenuitemidDemo() { // TODO: Add your command handler code here m_String=”嗨!这是菜单处理程序演示\"; UpdateAllViews(NULL); }
voidCItemEventView::OnDraw(CDC* pDC) { CItemEventDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here pDC—〉TextOut(50,20,pDoc—〉 m_String); 实践5
在视类中添加代码如下:
Oid CInsertItemView::OnAddMenu() { // TODO: Add your command handler code here CWnd*pParent=GetParent(); CMenu*pMenu=pParent-〉GetMenu();
CMenu*subMenu=pMenu—>GetSubMenu(0); subMenu—>AppendMenu(MF_STRING | MF_ENABLED,3000,\"新菜单项\"); }
实践6
将在视类中添加的代码加黑显示CInsertItemView类定义如下: // InsertItemView.h : interface of the CInsertItemView class //
///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_INSERTITEMVIEW_H__FD590BE0_8111_473E_ADF1_FEA487F4813B__INCLUDED_) #define
AFX_INSERTITEMVIEW_H__FD590BE0_8111_473E_ADF1_FEA487F4813B__INCLUDED_
#if _MSC_VER > 1000 #pragma once
#endif // _MSC_VER > 1000
class CInsertItemView : public CView {
private: CString str;
protected: // create from serialization only CInsertItemView(); DECLARE_DYNCREATE(CInsertItemView)
// Attributes public: CInsertItemDoc* GetDocument();
// Operations public:
// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CInsertItemView) public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); //}}AFX_VIRTUAL
// Implementation public: virtual ~CInsertItemView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif
protected:
// Generated message map functions protected: //{{AFX_MSG(CInsertItemView) afx_msg void OnAddMenu(); afx_msg void OnMyMenuItem(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };
#ifndef _DEBUG // debug version in InsertItemView。cpp inline CInsertItemDoc* CInsertItemView::GetDocument() { return (CInsertItemDoc*)m_pDocument; } #endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DEMO06VIEW_H__FD590BE0_8111_473E_ADF1_FEA487F4813B__INCLUDED_)
CInsertItemView类实现如下:
// InsertItemView。cpp : implementation of the CInsertItemView class //
#include \"stdafx。h” #include \"InsertItem.h”
#include ”InsertItemDoc。h\"
#include ”InsertItemView。h\"
#ifdef _DEBUG
#define new DEBUG_NEW #undef THIS_FILE
static char THIS_FILE[] = __FILE__; #endif
///////////////////////////////////////////////////////////////////////////// // CInsertItemView
IMPLEMENT_DYNCREATE(CInsertItemView, CView)
BEGIN_MESSAGE_MAP(CInsertItemView, CView) //{{AFX_MSG_MAP(CInsertItemView) ON_COMMAND(ID_AddMenu, OnAddMenu) ON_COMMAND(3000,OnMyMenuItem) //}}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()
///////////////////////////////////////////////////////////////////////////// // CInsertItemView construction/destruction
CInsertItemView::CInsertItemView() { // TODO: add construction code here str=\"\"; }
CInsertItemView::~CInsertItemView() { }
BOOL CInsertItemView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}
///////////////////////////////////////////////////////////////////////////// // CInsertItemView drawing
void InsertItemView::OnDraw(CDC* pDC) { CInsertItemDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here pDC—>TextOut(20,20,str); }
///////////////////////////////////////////////////////////////////////////// // CInsertItemView printing
BOOL CInsertItemView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); }
void CInsertItemView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing }
void CInsertItemView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing }
///////////////////////////////////////////////////////////////////////////// // CInsertItemView diagnostics
#ifdef _DEBUG
void CInsertItemView::AssertValid() const { CView::AssertValid(); }
void CInsertItemView::Dump(CDumpContext& dc) const { CView::Dump(dc);
}
CInsertItemDoc* CInsertItemView::GetDocument() // non—debug version is inline { ASSERT(m_pDocument-〉IsKindOf(RUNTIME_CLASS(CInsertItemDoc))); return (CDEMO06Doc*)m_pDocument; }
#endif //_DEBUG
///////////////////////////////////////////////////////////////////////////// // CInsertItemView message handlers
void CInsertItemView::OnAddMenu() { // TODO: Add your command handler code here CWnd*pParent=GetParent(); CMenu*pMenu=pParent-〉GetMenu(); CMenu*subMenu=pMenu-〉GetSubMenu(0); subMenu—〉AppendMenu(MF_STRING | MF_ENABLED,3000,”新菜单项\"); }
void CInsertItemView::OnMyMenuItem() { str=\"你选中了新添加的菜单项 \"; Invalidate(); } 实践7
在框架类中添加代码如下:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return —1; // TODO: Add your specialized creation code here if(!m_wndToolBar。CreateEx(this,TBSTYLE_FLAT, WS_CHILD|WS_VISIBLE|CBRS_TOP| CBRS_GRIPPER|CBRS_TOOLTIPS| CBRS_FLYBY|CBRS_SIZE_DYNAMIC)|| !m_wndToolBar。LoadToolBar(IDR_MAINFRAME)) {
TRACE0(\"Failed to create toolbar\\n”); return —1; //fail to create } m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } 实践8
在框架类中添加代码如下: static UINT indicators[]= { ID_SEPARATOR, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, };
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return —1; // TODO: Add your specialized creation code here if(!m_wndStatusBar。Create(this)||!m_wndStatusBar。SetIndicators(indicators,sizeof(indicators)/sizeof(UINT))) { TRACE0(”Failed to cerate status bar\\n”); return —1; //fail to create } return 0; }
第三章 实践11
在视类中添加代码如下:
void CDlgAppDlg::OnButtonStatic() { // TODO: Add your control notification handler code here m_nRecordClicked+=1; m_strShowRecord.Format(”您单击了按钮%d次\ this-〉 SetDlgItemText(IDC_STATIC_RECORD_CLICK,m_strShowRecord);
}
实践12
在VC开发环境下复习按钮的添加过程,并在按钮的事件函数中添加消息框.弹出消息框的代码非常简单,只有一条语句,代码如下: void CDlgApp1Dlg::OnMessageBox() { // TODO: Add your control notification handler code here AfxMessageBox(\"这是一个消息框\"); }
实践13
添加代码如下:
void CDlgAppDlg::OnNewDlg() { // TODO: Add your control notification handler code here CNewDlg newdlg; newdlg。DoModal(); 实践14
添加代码如下:
void CDlgAppDlg::OnButtonModelessDialog() { // TODO: Add your control notification handler code here CNewDlg * dlg= new CNewDlg(); dlg->Create(IDD_DIALOG1); dlg->ShowWindow(SW_SHOW); }
第4章 实践15
在OnRadio1()中添加代码:
void CRadioAppDlg::OnRadio2() { // TODO: Add your control notification handler code here UpdateData(); m_txt=”您的性别是:女\"; UpdateData(false); }
在OnRadio2()中添加代码:
void CRadioAppDlg::OnRadio1() { // TODO: Add your control notification handler code here UpdateData();
m_txt=\"您的性别是:男\"; UpdateData(false); }
实践16
为函数OnOK()添加代码:
void CCheckAppDlg::OnOK() { // TODO: Add extra validation here UpdateData(); CString str; str=”您的爱好为:\"; if(m_chk1==true) { str=str+” 篮球 ”; } if(m_chk2==true) { str=str+” 足球 ”; } if(m_chk3==true) { str=str+\" 排球 \"; } if(m_chk4==true) { str=str+\" 乒乓球 ”; } m_txt=str; UpdateData(false); }
实践17
为函数OnOK()添加代码: void CGroupAppDlg::OnOK() { // TODO: Add extra validation here UpdateData(); CString str; str=”您是一位”; if(m_rad1==0) { str=str+”未婚\"; }
else { str=str+\"已婚\"; } if(m_rad3==0) { str=str+\"男性”; } else { str=str+\"女性\"; } m_txt=str; UpdateData(false); }
实践18
ON_BUTTON1;BN_CLICKED事件添加的代码为: void CListAppDlg::OnButton1() { // TODO: Add your control notification handler code here CString str; m_txt。GetWindowText(str); m_list.AddString(str); m_txt.SetWindowText(\"\"); m_txt.SetFocus();
ON_BUTTON2;BN_CLICKED事件添加的代码为: void CListAppDlg::OnButton2() { // TODO: Add your control notification handler code here int st; st=m_list。GetCurSel(); m_list。DeleteString(st); }
在OnInitDialog()函数中添加代码: BOOL CListAppDlg::OnInitDialog() { CDialog::OnInitDialog(); m_list。AddString(\"语文\"); m_list。AddString(\"数学\"); m_list.AddString(\"英语”);
实践19
为OnButton1添加事件代码如下:
void CListToListDlg::OnButton1() { // TODO: Add your control notification handler code here int st; st=m_list1。GetCurSel(); CString str; m_list1.GetText(st,str); m_list1.DeleteString(st); m_list2.AddString(str); }
为OnButton2添加事件代码如下:
void CListToListDlg::OnButton2() { // TODO: Add your control notification handler code here int st2; st2=m_list2。GetCurSel(); CString str2; m_list2.GetText(st2,str2); m_list2。DeleteString(st2); m_list1。AddString(str2); }
实践20
为OnOK()添加代码如下:
void CComboAppDlg::OnOK() { // TODO: Add extra validation here UpdateData(); m_txt=”您的目的地是:”+m_str; UpdateData(false); }
实践21
为IDDK添加代码如下:
void CComTestAppDlg::OnOK() // TODO: Add extra validation here UpdateData(); CString m_str; if(m_sel==0) { m_str=\"使用自行车需要很久”; }
if(m_sel==1) { m_str=”使用火车需要几天”; }if(m_sel==2) { m_str=”使用飞机当天就能到达\"; } m_txt=\"从\"+m_com1+”到”+m_com2+m_str; UpdateData(false); }
第六章 实践28
为OnButton1() 添加代码如下:
void CDrawLineDlg::OnButton1() { // TODO: Add your control notification handler code here CString k1,k2,k3,k4; int m1,m2,m3,m4; m_1。GetWindowText(k1); m_2.GetWindowText(k2); m_3。GetWindowText(k3); m_4.GetWindowText(k4); m1=atoi(k1); m2=atoi(k2); m3=atoi(k3); m4=atoi(k4); CDC * pDC = GetDC(); CLine m_line(CPoint(m1,m2),CPoint(m3,m4)); m_line。Draw(pDC); }
下面列出与添加代码有关的程序片段,在Line。h中: CLine::CLine() { }
CLine::~CLine() { }
CLine::CLine(CPoint pFrom, CPoint pTo)
{ m_pFrom=pFrom; m_pTo=pTo; }
void CLine::Draw(CDC *pDC) { //Draw the line pDC -> MoveTo(m_pFrom); pDC -〉 LineTo(m_pTo); }
实践29
OnMouseMove()事件代码如下:
void CMouseLineAppDlg::OnMouseMove(UINT nFlags, CPoint point) { CClientDC dc(this); CPen pen(0,0,RGB(0,0,0)); CPen* pOldPen=dc。SelectObject(&pen); dc。SetROP2(R2_NOT); //设置成R2_NOT if(mPointOld != point) { dc。MoveTo(mPointOrign); dc。LineTo(mPointOld); dc。MoveTo(mPointOrign); dc。LineTo(point); mPointOld = point; } }
OnLButtonUp()事件代码如下:
void CMouseLineAppDlg::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default
ReleaseCapture(); }
OnLButtonDown()事件代码如下:
void CMouseLineAppDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default mPointOrign=point; mPointOld=point;
SetCapture(); }
实践30
在PreCreateWindow()事件中添加如下代码:
BOOL CMouseEllipseView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs pb=0; return CView::PreCreateWindow(cs); }
OnMouseMove()事件代码如下:
void CMouseEllipseView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); double r; CPen pen(0,0,RGB(0,0,0)); CPen*pOldPen=dc。SelectObject(&pen); dc.SetROP2(R2_NOT); if(pb!=0) { if(mPointOld!=point) { dc.SelectStockObject(NULL_BRUSH); r=sqrt(pow((mPointOrign。x—mPointOld.x),2)+pow((mPointOrign.y—mPointOld。y),2)); dc。Ellipse(mPointOrign。x—r,mPointOrign.y—r,mPointOrign。x+r,mPointOrign.y+r); r=sqrt(pow((mPointOrign。x-point.x),2)+pow((mPointOrign.y-point.y),2)); dc.Ellipse(mPointOrign。x—r,mPointOrign。y-r,mPointOrign。x+r,mPointOrign。y+r); mPointOld=point; } } }
OnLButtonDown ()事件代码如下:
void CMouseEllipseView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC myDC(this);
OnPrepareDC(&myDC); CPoint m_Point1,m_Point2; double r; if(pb==0) { mPointOrign=point; mPointOld=point; myDC。SetPixel(point.x,point。y,0x0000ff00); pb=1; SetCapture(); } else { r=sqrt(pow((mPointOrign.x-mPointOld。x),2)+pow((mPointOrign。y—mPointOld。y),2)); m_Point1。x=mPointOrign。x-r; m_Point1.y=mPointOrign.y-r; m_Point2。x=mPointOrign。x+r; m_Point2。y=mPointOrign.y+r; myDC.Ellipse(m_Point1。x,m_Point1.y,m_Point2.x,m_Point2.y); ReleaseCapture(); pb=0; } }
实践31
OnLButtonDown()事件中新增如下代码:
void CMouseEllipseView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC myDC(this); OnPrepareDC(&myDC); CPoint m_Point1,m_Point2; double r; if(pb==0) { mPointOrign=point; mPointOld=point; myDC。SetPixel(point.x,point.y,0x0000ff00); pb=1; SetCapture(); } else {
r=sqrt(pow((mPointOrign。x-mPointOld。x),2)+pow((mPointOrign.y-mPointOld.y),2)); m_Point1。x=mPointOrign.x—r; m_Point1。y=mPointOrign。y-r; m_Point2.x=mPointOrign。x+r; m_Point2.y=mPointOrign.y+r; myDC。Ellipse(m_Point1。x,m_Point1。y,m_Point2.x,m_Point2。y); ReleaseCapture(); pb=0; CGraph * pGraph; pGraph = new CGraph(mPointOrign,point); m_ptrArray.Add(pGraph); } }
在OnDraw()函数中添加如下代码:
void CMouseEllipseView::OnDraw(CDC* pDC) { CMouseEllipseDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CPoint m_Point1,m_Point2; double r; CBrush * pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL)); pDC—>SelectObject(pBrush); for(int i=0;i 实践32 DrawToBmpView.cpp中:OnDraw(CDC* pDC)函数的代码如下: void CDrawToBmpView::OnDraw(CDC* pDC) { CDrawToBmpDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CRect rc; GetClientRect(&rc); DrawCurve(pDC,rc); } DrawToBmpView。cpp中SaveAsBmp(CString filename)函数的代码如下: void CDrawToBmpView::SaveAsBmp(CString filename) { //定义图形大小 int iWidth=800; int iHeight=600; int iPixel=16; //图形格式参数 LPBITMAPINFO lpbmih=new BITMAPINFO; lpbmih->bmiHeader。biSize=sizeof(BITMAPINFOHEADER); lpbmih->bmiHeader。biWidth=iWidth; lpbmih-〉bmiHeader。biHeight=iHeight; lpbmih-〉bmiHeader.biPlanes=1; lpbmih->bmiHeader。biBitCount=iPixel; lpbmih->bmiHeader。biCompression=BI_RGB; lpbmih—〉bmiHeader.biSizeImage=0; lpbmih-〉bmiHeader.biXPelsPerMeter=0; lpbmih—〉bmiHeader。biYPelsPerMeter=0; lpbmih->bmiHeader.biClrUsed=0; lpbmih-〉bmiHeader。biClrImportant=0; //创建位图数据 HDC hdc,hdcMem; HBITMAP hBitMap=NULL; CBitmap*pBitMap=NULL; CDC*pMemDC=NULL; BYTE*pBits; hdc=CreateIC(TEXT(\"DISPLAY”),NULL,NULL,NULL); hdcMem=CreateCompatibleDC(hdc); hBitMap=CreateDIBSection(hdcMem,lpbmih,DIB_PAL_COLORS,(void**)&pBits,NULL,0); pBitMap=new CBitmap; pBitMap—>Attach(hBitMap); pMemDC=new CDC; pMemDC-〉Attach(hdcMem); pMemDC—〉SelectObject(pBitMap); // CRect rc(0,0,iWidth,iHeight); pMemDC-〉SetBkMode(TRANSPARENT); //添加自绘图形 DrawCurve(pMemDC,rc); //保存到文件并创建位图结构 BITMAPFILEHEADER bmfh; ZeroMemory(&bmfh,sizeof(BITMAPFILEHEADER)); *((char*)&bmfh.bfType)=’B'; *(((char*)&bmfh。bfType)+1)=’M'; bmfh。bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPFILEHEADER); bmfh.bfSize=bmfh.bfOffBits+(iWidth*iHeight)*iPixel/8; TCHAR szBMPFileName[28]; int iBMPBytes = iWidth*iHeight*iPixel/8; strcpy(szBMPFileName,filename); CFile file; if(file。Open(szBMPFileName,CFile::modeWrite|CFile::modeCreate)) { file.Write(&bmfh,sizeof(BITMAPFILEHEADER)); file。Write(&(lpbmih->bmiHeader),sizeof(BITMAPFILEHEADER)); file.Write(pBits,iBMPBytes); file。Close(); } pMemDC—>DeleteDC(); delete pMemDC; pMemDC=NULL; delete pBitMap; pBitMap=NULL; delete lpbmih; lpbmih=NULL; } DrawToBmpView。cpp中OnRButtonDown()函数的代码: void CDrawToBmpView::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CFileDialog dlg(false,NULL,NULL,OFN_HIDEREADONLYOFN_OVERWRITEPROMPT,”位图文件(*。bmp)|*.bmp|\); if(dlg.DoModal()!=IDOK)return; CString filename=dlg.GetFileName()+\".bmp”; SaveAsBmp(filename); CView::OnRButtonDown(nFlags, point); } void CDrawToBmpView::DrawCurve(CDC *pDC, CRect rcClient) { //页面背景色 | CBrush brushCtl; brushCtl。CreateSolidBrush(RGB(255,255,255)); pDC->Rectangle(rcClient); pDC—〉FillRect(rcClient,&brushCtl); brushCtl。DeleteObject(); CPen pen; pen。CreatePen(PS_SOLID,1,RGB(255,255,0)); CPen*oldPen=pDC-〉SelectObject(&pen); pDC-〉Ellipse(100,100,300,300); pDC->Ellipse(500,100,700,300); pDC-〉Rectangle(300,300,500,500); pDC—〉SelectObject(oldPen); pen.DeleteObject(); oldPen=NULL; } 实践33 CSineTest。h中添加的主要代码如下: class CSineCurve { public: CSineCurve(); virtual~CSineCurve(); void Init(int x,int y,int wid,int hei,CDC*pDC); void DrawSine(); void DrawFrame(); void DrawCoordinate(); void DrawScale(); void DrawCurve(); private: int left; int top; int width; int height; CDC*pDC; int leftSpace; int topSpace; int curveHeight; int halfCurveHeight; int space; }; CSineText.cpp中添加的主要代码如下: SCineCurve::~CSineCurve() { } void CSineCurve::Init(int x,int y,int wid,int hei,CDC*pDC) { left=x; top=y; width=wid; height=hei; this—〉pDC=pDC; } void CSineCurve::DrawSine() { DrawFrame(); DrawCoordinate(); DrawScale(); DrawCurve(); } void CSineCurve::DrawFrame() { pDC—〉Rectangle(left,top,left+width,top+height); CFont m_listCtrlFont; m_listCtrlFont.CreateFont(12,9,0,0,FW_BLACK,FALSE,FALSE,FALSE, DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS, PROOF_QUALITY,DEFAULT_PITCH|FF_DONTCARE,\"宋体”); pDC—>TextOut(left+100,top+10,”正弦曲线图\"); pDC->TextOut(left+10,top+20,”Y”); pDC->TextOut(left+width-leftSpace,top+topSpace+halfCurveHeight,”X\"); } void CSineCurve::DrawCoordinate() { POINT p; p.x=left+leftSpace; p.y=top+topSpace+curveHeight; pDC—〉MoveTo(p。x—space,p。y-halfCurveHeight); pDC-〉LineTo(p.x+width-leftSpace*2,p.y-halfCurveHeight); pDC—〉MoveTo(p.x,p.y+space); pDC—〉MoveTo(p.x,p。y-curveHeight—space); } void CSineCurve::DrawScale() { int number = 4; int tmpy=top+topSpace; pDC->MoveTo(left+leftSpace,tmpy); pDC-〉LineTo(left+leftSpace-4,tmpy); CString scale=\"1”; pDC-〉TextOut(left+4,tmpy—8,scale); tmpy=top+topSpace+curveHeight; pDC-〉MoveTo(left+leftSpace,tmpy); pDC->LineTo(left+leftSpace-4,tmpy); scale=\"-1\"; pDC-〉TextOut(left+4,tmpy—8,scale); } void CSineCurve::DrawCurve() { int mode=pDC->GetROP2(); pDC—>SetROP2(R2_XORPEN); for(int i=0;i〈width—leftSpace*2;i++) { int tmpy=(int)(sin(i * 3.1416/180.0) * halfCurveHeight); int py=top+topSpace+halfCurveHeight—tmpy; pDC-〉SetPixel(left+leftSpace+i,py,RGB(0,255,0)); } pDC—〉SetROP2(mode); }
因篇幅问题不能全部显示,请点此查看更多更全内容