65.9K
CodeProject 正在变化。 阅读更多。
Home

位图轮廓到 Windows 区域

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.20/5 (12投票s)

2003年11月26日

CPOL
viewsIcon

95340

downloadIcon

1602

一篇关于如何生成位图轮廓的文章。用于设计用户自定义形状的对话框。

Sample screenshot

引言

CBitmapHandling 类被设计用来计算位图中的轮廓点。它查看位图并找到与白色不同的像素点,然后将这些起始和停止像素点放置在 CPoint 类的顶点中。当它找到位图的轮廓后,它将生成一个 Windows 区域。如果你在 OnInitDialog 中使用这个区域,然后使用 SetWindowRgn(m_WinRgn, TRUE ) 设置窗口区域,你的窗口就会被塑造成轮廓的形状。

使用代码

代码由一个头文件和一个 CPP 文件组成。

//
#include "BitMapHandling.h"
using namespace HandlingBitmaps;

BOOL CMyShapedWindowDlg::OnInitDialog()
{
 CDialog::OnInitDialog();
 
 VERIFY( SetWindowPos( NULL, 0, 0, m_nW, 
         m_nH, SWP_NOMOVE | SWP_NOOWNERZORDER ) ); // size and pos. of window
         // cut of areas of region, which you do not really need. 
         // fx. maybe you have bitmap buttons drawn under your bitmap window.
 CBitmapHandling bh;
 bh.BitMapContourToWinRgn(&m_WinRgn, IDB_BITMAP);
 VERIFY( SetWindowRgn(m_WinRgn , TRUE ) );

 return TRUE; // return TRUE unless you set the focus to a control
}
//
© . All rights reserved.