Visual C++ 7.1Visual C++ 7.0Windows 2003Windows 2000Visual C++ 6.0Windows XPMFC中级开发Visual StudioWindowsC++
位图轮廓到 Windows 区域
一篇关于如何生成位图轮廓的文章。用于设计用户自定义形状的对话框。
引言
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 } //