zoukankan      html  css  js  c++  java
  • 【转】CBitmap和HBITMAP的区别及相互转换方法

    hbitmap是bitmap的指针,

    msdn中:Handle to a bitmap.typedef HANDLE HBITMAP;

    cbitmap是mfc中封装bitmap的类;

    msdn中:Encapsulates(囊括) a Windows graphics device interface (GDI)bitmap and provides member functions to manipulate(操作) the bitmap.

    class CBitmap : public CgdiObject 

     转化方法两种,Attach和FromHandle:

     

    1 CBitmap bmp;
    2 bmp.LoadBitmap(IDB_BITMAP1);
    3 HBITMAP hbm = (HBITMAP)bmp;
    4 CBitmap bmp1;
    5 bmp1.Attach(hbm);
    6
    7 HBITMAP = CBitmap.m_hObject
    8 CBitmap* = CBitmap.FromHandle(HBITMAP)
    9
    10  //已知HBITMAP hbit;
    11  CBitmap cb;
    12 cb.FromHandle(hbit);
    13
    14  //已知CBitmap cb;
    15  HBITMAP hbit=(HBITMAP)cb;
    16
    17 CBitmap bmp;
    18 HBITMAP hBmp;
    19  //相互转换:
    20  hBmp=(HBITMAP)bmp.GetSafeHandle();
    21 bmp.Attach(hBmp);

    注意点:

    Attach和FromHandle的区别

    FromHandle得到的指针是临时变量,

    ,通过Attach连接的句柄可以长久保留,但通过FromHandle得到的只是暂时的,

    大概只在一个消息区间内有效,很快便会被删除,所以基本上不能用。

    我用了FromHandle然后一直出错!!!

    from:http://blog.csdn.net/newstarao/archive/2009/05/22/4209656.aspx

  • 相关阅读:
    ZOJ3213-Beautiful Meadow
    ZOJ3256-Tour in the Castle
    ZOJ3466-The Hive II
    hdu3377-Plan
    fzu1977-Pandora Adventure
    ural1519-Formula 1
    poj2914-Minimum Cut
    51nod-1220-约数之和
    51nod-1222-最小公倍数计数
    【html】【6】div浮动float
  • 原文地址:https://www.cnblogs.com/dahai/p/1762422.html
Copyright © 2011-2022 走看看