文档详情

不规则对话框的实现 C++.doc

发布:2018-05-21约2.61千字共3页下载文档
文本预览下载声明
不规则对话框的实现 C++ /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 在 OnInitDialog() 时初始化相关数据 HDC hdcs; HBITMAP pBitmap; CBitmap m_bmp; pBitmap = (HBITMAP)LoadImage(NULL,图片.bmp,IMAGE_BITMAP,0,0,LR_LOADFROMFILE); hdcs = CreateCompatibleDC(NULL); m_bmp.Attach( pBitmap ); BITMAP bm; m_bmp.GetBitmap(bm); CRect rtWindow; GetWindowRect(rtWindow); rtWindow.right = rtWindow.left+bm.bmWidth; rtWindow.bottom =rtWindow.top +bm.bmHeight; MoveWindow(rtWindow); CClientDC dc(this); SetupRegion(dc,m_bmp,RGB(191,194,114) ); /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 最后在 OnPaint 的else 里面 CClientDC dc(this); CDC picDC; picDC.CreateCompatibleDC (dc); CBitmap *pOldBmp; pOldBmp = picDC.SelectObject (m_bmp); BITMAP bm; m_bmp.GetBitmap(bm); dc.BitBlt (0,0,bm.bmWidth ,bm.bmHeight,picDC,0,0,SRCCOPY); dc.SelectObject(pOldBmp); /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 下面是主代码 void CtextDemoDlg::SetupRegion(CDC *pDC, CBitmap cBitmap, COLORREF TransColor) { CDC memDC; //创建与传入DC兼容的临时DC memDC.CreateCompatibleDC(pDC); CBitmap *pOldMemBmp=NULL; //将位图选入临时DC pOldMemBmp=memDC.SelectObject(cBitmap); CRgn wndRgn; //创建总的窗体区域,初始region为0 wndRgn.CreateRectRgn(0,0,0,0); BITMAP bit; cBitmap.GetBitmap (bit);//取得位图参数,这里要用到位图的长和宽 int y; for(y=0;y=bit.bmHeight ;y++) { CRgn rgnTemp; //保存临时region int iX = 0; do { //跳过透明色找到下一个非透明色的点. while (iX = bit.bmWidth memDC.GetPixel(iX, y) == TransColor) iX++; //记住这个起始点 int iLeftX = iX; //寻找下个透明色的点 while (iX = bit.bmWidth memDC.GetPix
显示全部
相似文档