void DrawTransparentBitmap(HDC  hdc,  HBITMAP  hBitmap,  short  xStart,  short  yStart,  COLORREF  cTransparentColor);

函数的实现:

void CLoginPanel::DrawTransparentBitmap(HDC  hdc,  HBITMAP  hBitmap,  short  xStart,  short  yStart,  COLORREF  cTransparentColor)  
     {  
     BITMAP          bm;  
     COLORREF      cColor;  
     HBITMAP        bmAndBack,  bmAndObject,  bmAndMem,  bmSave;  
     HBITMAP        bmBackOld,  bmObjectOld,  bmMemOld,  bmSaveOld;  
     HDC                hdcMem,  hdcBack,  hdcObject,  hdcTemp,  hdcSave;  
     POINT            ptSize;  
 
     hdcTemp  =  CreateCompatibleDC(hdc);  
     SelectObject(hdcTemp,  hBitmap);      //  Select  the  bitmap  
 
     GetObject(hBitmap,  sizeof(BITMAP),  (LPSTR)&bm);  
     ptSize.x  =  bm.bmWidth;                        //  Get  width  of  bitmap  
     ptSize.y  =  bm.bmHeight;                      //  Get  height  of  bitmap  
     DPtoLP(hdcTemp,  &ptSize,  1);            //  Convert  from  device  
 
                                                                         //  to  logical  points  
 
     //  Create  some  DCs  to  hold  temporary  data.  
     hdcBack      =  CreateCompatibleDC(hdc);  
     hdcObject  =  CreateCompatibleDC(hdc);  
     hdcMem        =  CreateCompatibleDC(hdc);  
     hdcSave      =  CreateCompatibleDC(hdc);  
 
     //  Create  a  bitmap  for  each  DC.  DCs  are  required  for  a  number  of  
     //  GDI  functions.  
 
     //  Monochrome  DC  
     bmAndBack      =  CreateBitmap(ptSize.x,  ptSize.y,  1,  1,  NULL);  
 
     //  Monochrome  DC  
     bmAndObject  =  CreateBitmap(ptSize.x,  ptSize.y,  1,  1,  NULL);  
 
     bmAndMem        =  CreateCompatibleBitmap(hdc,  ptSize.x,  ptSize.y);  
     bmSave            =  CreateCompatibleBitmap(hdc,  ptSize.x,  ptSize.y);  
 
     //  Each  DC  must  select  a  bitmap  object  to  store  pixel  data.  
     bmBackOld      = (HBITMAP)SelectObject(hdcBack,  bmAndBack);  
     bmObjectOld  =  (HBITMAP)SelectObject(hdcObject,  bmAndObject);  
     bmMemOld        = (HBITMAP)SelectObject(hdcMem,  bmAndMem);  
     bmSaveOld      = (HBITMAP)SelectObject(hdcSave,  bmSave);  
 
     //  Set  proper  mapping  mode.  
     SetMapMode(hdcTemp,  GetMapMode(hdc));  
 
     //  Save  the  bitmap  sent  here,  because  it  will  be  overwritten.  
     BitBlt(hdcSave,  0,  0,  ptSize.x,  ptSize.y,  hdcTemp,  0,  0,  SRCCOPY);  
 
     //  Set  the  background  color  of  the  source  DC  to  the  color.  
     //  contained  in  the  parts  of  the  bitmap  that  should  be  transparent  
     cColor  =  SetBkColor(hdcTemp,  cTransparentColor);  
 
     //  Create  the  object  mask  for  the  bitmap  by  performing  a  BitBlt  
     //  from  the  source  bitmap  to  a  monochrome  bitmap.  
     BitBlt(hdcObject,  0,  0,  ptSize.x,  ptSize.y,  hdcTemp,  0,  0,  
                   SRCCOPY);  
 
     //  Set  the  background  color  of  the  source  DC  back  to  the  original  
     //  color.  
     SetBkColor(hdcTemp,  cColor);  
 
     //  Create  the  inverse  of  the  object  mask.  
     BitBlt(hdcBack,  0,  0,  ptSize.x,  ptSize.y,  hdcObject,  0,  0,  
                   NOTSRCCOPY);  
 
     //  Copy  the  background  of  the  main  DC  to  the  destination.  
     BitBlt(hdcMem,  0,  0,  ptSize.x,  ptSize.y,  hdc,  xStart,  yStart,  
                   SRCCOPY);  
 
     //  Mask  out  the  places  where  the  bitmap  will  be  placed.  
     BitBlt(hdcMem,  0,  0,  ptSize.x,  ptSize.y,  hdcObject,  0,  0,  SRCAND);  
 
     //  Mask  out  the  transparent  colored  pixels  on  the  bitmap.  
     BitBlt(hdcTemp,  0,  0,  ptSize.x,  ptSize.y,  hdcBack,  0,  0,  SRCAND);  
 
     //  XOR  the  bitmap  with  the  background  on  the  destination  DC.  
     BitBlt(hdcMem,  0,  0,  ptSize.x,  ptSize.y,  hdcTemp,  0,  0,  SRCPAINT);  
 
     //  Copy  the  destination  to  the  screen.  
     BitBlt(hdc,  xStart,  yStart,  ptSize.x,  ptSize.y,  hdcMem,  0,  0,  
                   SRCCOPY);  
 
     //  Place  the  original  bitmap  back  into  the  bitmap  sent  here.  
     BitBlt(hdcTemp,  0,  0,  ptSize.x,  ptSize.y,  hdcSave,  0,  0,  SRCCOPY);  
 
     //  Delete  the  memory  bitmaps.  
     DeleteObject(SelectObject(hdcBack,  bmBackOld));  
     DeleteObject(SelectObject(hdcObject,  bmObjectOld));  
     DeleteObject(SelectObject(hdcMem,  bmMemOld));  
     DeleteObject(SelectObject(hdcSave,  bmSaveOld));  
 
     //  Delete  the  memory  DCs.  
     DeleteDC(hdcMem);  
     DeleteDC(hdcBack);  
     DeleteDC(hdcObject);  
     DeleteDC(hdcSave);  
     DeleteDC(hdcTemp);  
     }

https://blog.csdn.net/goodowxy/article/details/2038014

程序中图片透明 函数(使用SetBkColor API函数)的更多相关文章

  1. C#中图片透明【转】

    C#中图片透明 /// <summary> /// 处理图片透明操作 /// </summary> /// <param name="srcImage" ...

  2. Visual C++中最常用的类与API函数

    这篇文章能让初学者快速了解visual C++ MFC中常见的核心的类与函数,虽然全部看下来有点枯燥,但对初学者快速了解MFC的框架结构很有好处. 常用类 CArchive类:用于二进制保存档案 CB ...

  3. C#中可直接调用WIN32的API函数--USER32.DLL

    Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...

  4. 微信小程序中图片上传阿里云Oss

    本人今年6月份毕业,最近刚在上海一家小公司实习,做微信小程序开发.最近工作遇到一个小问题. 微信小程序图片上传阿里云服务器Oss也折腾了蛮久才解决的,所以特意去记录一下. 第一步:配置阿里云地址: 我 ...

  5. 软件看门狗--别让你地程序无响应(使用未公开API函数IsHungAppWindow,知识点较全)

    正文一.概述一些重要的程序,必须让它一直跑着:而且还要时时关心它的状态——不能让它出现死锁现象.当然,如果一个主程序会出现死锁,肯定是设计或者编程上的失误.我们首要做的事是,把这个Bug揪出来.但如果 ...

  6. 在 Windows 8、Windows 10 桌面模式下的 .NET Framework 程序中,引用 Windows.Runtime 的 API。

    参考:1.https://www.cnblogs.com/webtojs/p/9675956.html 2.http://jennal.com/2016/04/28/using-windows-run ...

  7. C#API函数

    API函数是构筑Windows应用程序的基石,是Windows编程的必备利器.每一种Windows应用程序开发工具都提供了间接或直接调用了Windows API函数的方法,或者是调用Windows A ...

  8. 替换应用程序exe图标,主要使用BeginUpdateResource,UpdateResource API函数

    替换应用程序exe图标,主要使用的API函数是BeginUpdateResource(),UpdateResource(),EndUpdateResource()来使用自定义的ico文件类替换exe程 ...

  9. API函数ShellExecute与ShellExecuteEx用法

    ShellExecute: 1.函数功能:你可以给它任何文件的名字,它都能识别出来并打开它.2.函数原型: HINSTANCE ShellExecute( HWND hwnd, LPCTSTR lpO ...

随机推荐

  1. MAC 下的简单 SHELL 入门

    1.创建文件 .sh 文件 本例,将 sh 文件全名为 demo.sh,接下来使用随意熟悉的编辑器编辑命令就可以 2.编写 .sh 文件 #!/bin/sh echo +--------------- ...

  2. 修正EasyUI的BUG——Form中存在FileBox时的数据载入错误

    使用EasyUI载入服务端返回的数据时经常使用 $('#fm').form('load', row); 实现,既方便又简洁,可是.当Form中包括有FileBox时,代码就会报错,经过跟踪发现.由于E ...

  3. OpenLayers3基础教程——OL3之Popup

    概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用Overlay取代OL2的Popup功能. 接口简单介绍: overlay跟ol.control.Control一样,是一 ...

  4. strongSwan IKEv2服务器配置

    strongSwan IKEv2服务器配置 资料来源 https://www.cl.cam.ac.uk/~mas90/resources/strongswan/ 经过大量的反复试验,我配置了一个str ...

  5. Kinect 开发 —— 用户交互设计的若干思考

    Metro 风格 windows 8 Kinect Hub 手势原型设计 悬停选择     翻页控制 关节点重叠的处理方法 将箭靶设置在画面的边缘,这样玩家持弓的角度与屏幕保持一个大约45度的锐角,这 ...

  6. Codefroces Educational Round 26 837 C. Two Seals

    C. Two Seals time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. vue 实例的生命周期

      Vue把整个生命周期划分为创建.挂载.更新.销毁等阶段,每个阶段都会给一些"钩子"让我们来做一些我们想实现的动作. 分为以下几个阶段 1.beforeCreate   此阶段为 ...

  8. 2017国家集训队作业[agc008f]Black Radius

    2017国家集训队作业[agc008f]Black Radius 时隔4个月,经历了省赛打酱油和中考各种被吊打后,我终于回想起了我博客园的密码= = 题意: ​ 给你一棵树,树上有若干个关键点.选中某 ...

  9. ZJOI2008骑士

    Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战火绵延五百里,在和平环境 ...

  10. Linux运维命令总结

    .什么是运维?什么是游戏运维? 1)运维是指大型组织已经建立好的网络软硬件的维护,就是要保证业务的上线与运作的正常, 在他运转的过程中,对他进行维护,他集合了网络.系统.数据库.开发.安全.监控于一身 ...