我的系统要在客户区画一写曲线,这一步已经实现了,但是当有遮挡时就需要刷新,但如何将这些曲线信息存起来啊,或者有什么更好的方法?谢谢了

解决方案 »

  1.   

    CDC   MemDC;   //定义一个显示设备对象   
    CBitmap   MemBitmap;//定义一个位图对象   
    //建立与屏幕显示兼容的内存显示设备   
      MemDC.CreateCompatibleDC(NULL);       
    //建立一个与屏幕显示兼容的位图,位图的大小用窗口的大小   
      MemBitmap.CreateCompatibleBitmap(pDC,300,300);       
    //将位图选入到内存显示设备中      
    CBitmap   *pOldBit=MemDC.SelectObject(&MemBitmap);   
    //用背景色将位图清除干净      
    //  MemDC.FillSolidRect(0,0,300,300,RGB(0,0,0)); 
    //绘图 
    画曲线的代码 ....
    //显示在窗口
    pDC->BitBlt(0,0,300,300,&MemDC,0,0,SRCCOPY);   
    //绘图完成后的清理   
    MemBitmap.DeleteObject();   
    MemDC.DeleteDC();
      

  2.   

    忘了说了,需要重载OnEraseBkgnd函数,返回值为ture就可以了;
      

  3.   


    以前我做过的一个例子:
    现在复制过来// DrawDlg.h : header file
    //#if !defined(AFX_DRAWDLG_H__DBD98072_5313_4D48_8485_C102C4DDAA90__INCLUDED_)
    #define AFX_DRAWDLG_H__DBD98072_5313_4D48_8485_C102C4DDAA90__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CDrawDlg dialogclass CDrawDlg : public CDialog
    {
    // Construction
    public:
    CBitmap* m_bitmap;
    CDrawDlg(CWnd* pParent = NULL);// standard constructor// Dialog Data
    //{{AFX_DATA(CDrawDlg)
    enum { IDD = IDD_DRAW_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA// ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDrawDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon;// Generated message map functions
    //{{AFX_MSG(CDrawDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnDestroy();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DRAWDLG_H__DBD98072_5313_4D48_8485_C102C4DDAA90__INCLUDED_)// DrawDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "Draw.h"
    #include "DrawDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    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)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CDrawDlg dialogCDrawDlg::CDrawDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CDrawDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CDrawDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);m_bitmap=NULL;
    }void CDrawDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDrawDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CDrawDlg, CDialog)
    //{{AFX_MSG_MAP(CDrawDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_LBUTTONDOWN()
    ON_WM_DESTROY()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CDrawDlg message handlersBOOL CDrawDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    }// Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);// Set big icon
    SetIcon(m_hIcon, FALSE);// Set small icon// TODO: Add extra initialization here
    CRect rc;
    GetClientRect(&rc);CPaintDC dc(this);
    m_bitmap=new CBitmap();
    m_bitmap->CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());CDC           myDC; 
    myDC.CreateCompatibleDC(&dc);   
    CBitmap   *pOldBitmap   =   myDC.SelectObject(m_bitmap);   CBrush mybrush(RGB(255,255,255));
    myDC.FillRect(&rc,&mybrush);
    myDC.SelectObject(pOldBitmap);
    myDC.DeleteDC();
    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CDrawDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CDrawDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CPaintDC dc(this);
    if(!m_bitmap)
    return;
    BITMAP   bmp;   
    m_bitmap->GetBitmap(&bmp);   
    CDC cdc; 
    cdc.CreateCompatibleDC(&dc);
    CBitmap* pOldbm;
    pOldbm=cdc.SelectObject(m_bitmap); 
       dc.BitBlt(0,0,bmp.bmWidth,bmp.bmHeight,&cdc,0,0,SRCCOPY);
    cdc.SelectObject(pOldbm);
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CDrawDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CDrawDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CPaintDC dc(this);
    CDC           myDC; 
    myDC.CreateCompatibleDC(&dc);   
    CBitmap   *pOldBitmap   =   myDC.SelectObject(m_bitmap);   //_____________________画图(在这里用myDC画曲线)
    //CBrush   brush;   
    //brush.CreateSolidBrush(RGB(255,0,0));   
    //myDC.SelectObject(&brush);   
    //CRect rcShape (point.x - 4, point.y - 4, point.x + 4, point.y + 4);    
    //myDC.Ellipse(rcShape);Your画曲线的过程(&myDC);//_____________________
    myDC.SelectObject(pOldBitmap);
    myDC.DeleteDC();
    Invalidate(FALSE);
    CDialog::OnLButtonDown(nFlags, point);
    }void CDrawDlg::OnDestroy() 
    {
    CDialog::OnDestroy();// TODO: Add your message handler code here
    delete m_bitmap;
    }