稳定盈利的期货交易方法-量化趋势交易

alantop -专业量化投资者

爱好:量化投资,逆向工程,渗透
随笔 - 595, 文章 - 0, 评论 - 921, 引用 - 0
数据加载中……

从文件中加载位图,双缓冲显示

上一篇讲了如何从资源中加载位图,这里讲如何从文件中加载。
资源加载位图 http://www.cppblog.com/alantop/archive/2008/03/13/44395.html

整个程序的流程是一样的,不明白的,可以看上一篇。
这里主要的 不同是怎样产生CBitmap对象。
从资源中加载是:
    CBitmap bmp;
    bmp
.LoadBitmap(IDB_BITMAP1)
从文件中加载是:
    CBitmap bitmap;
    bitmap
.m_hObject=(HBITMAP)::LoadImage(NULL,"test.bmp",IMAGE_BITMAP,500,400,LR_LOADFROMFILE);

这里需要注意的是从文件加载位图,并不是通过调用CBitmap的成员函数完成。
而是使用SDK函数LoadImage,通过将其返回值赋值给CBitmap的成员变量m_hObject而完成对CBitmap的对象的赋值过程。
此处的强制类型可以不使用,使用是强调的意思。

注意: When you no longer need the memory DC, call the DeleteDC function.

完全从文件加载位图,双缓冲代码如下,放在OnDraw(CDC* pDC)函数中即可。
    CBitmap bitmap;
    bitmap
.m_hObject=(HBITMAP)::LoadImage(NULL,"test.bmp",IMAGE_BITMAP,500,400,LR_LOADFROMFILE);
    
if (bitmap.m_hObject)
    {
        
// Get the size of the bitmap
        BITMAP bmpInfo;
        bitmap
.GetBitmap(&bmpInfo);
        
        
// Create an in-memory DC compatible with the
        // display DC we're using to paint

        CDC dcMemory;
        dcMemory
.CreateCompatibleDC(pDC);
        
        
// Select the bitmap into the in-memory DC
        CBitmap* pOldBitmap = dcMemory.SelectObject(&bitmap);
        
        
// Find a centerpoint for the bitmap in the client area
        CRect rect;
        GetClientRect(
&rect);
        int nX 
= rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
        int nY 
= rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;
        
        POINT ptstart
, ptend;
        ptstart
.= ptstart.= 0;
        ptend
.= ptend.= 500;
        
        
        dcMemory
.MoveTo(ptstart);
        dcMemory
.LineTo(ptend);
            
        
// Copy the bits from the in-memory DC into the on-
        // screen DC to actually do the painting. Use the centerpoint
        // we computed for the target offset.

        pDC->BitBlt(0, 0, bmpInfo.bmWidth * 2, bmpInfo.bmHeight * 2, &dcMemory, 
            
0, 0, SRCCOPY);
        
        dcMemory
.SelectObject(pOldBitmap);
        
        SIZE si;
        si
.cx = bmpInfo.bmWidth;
        si
.cy = bmpInfo.bmHeight;
        SetScrollSizes(MM_TEXT
, si);
    }
    
else
        TRACE0(
"ERROR: Where's IDB_BITMAP1?\n");

posted on 2008-03-14 07:29 AlanTop 阅读(3040) 评论(0)  编辑 收藏 引用 所属分类: 图像处理


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理