Programming Technology

VC下实现窗体透明效果(clarity for CDialog)

VC下实现窗体透明效果,我只测试了CStatic是不可以实现这个效果的,应该是只有CWnd子类才可以实现这个效果,如果想使用空间透明化,只能把他放窗体上了....
20%透明效果如下图:
20%透明窗体演示

具体代码实现:

  1. //参数说明:透明度(范围是0-255)
  2. void CSizeDlg::SetWindowAttributes(int Attributes)
  3. {
  4.         //////////////////////////////////////////////////////////////////////////
  5.         //透明实现
  6.         SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
  7.                 GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
  8.         HINSTANCE hInst = LoadLibrary("User32.DLL");
  9.         if(hInst)
  10.         {
  11.                 typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
  12.                 MYFUNC fun = NULL;
  13.  
  14.                 //取得SetLayeredWindowAttributes函数指针    
  15.                 fun=(MYFUNC)GetProcAddress(hInst,"SetLayeredWindowAttributes");  
  16.                 if(fun)fun(this->GetSafeHwnd(),0,Attributes,2);
  17.                 FreeLibrary(hInst);
  18.         }
  19.         //////////////////////////////////////////////////////////////////////////
  20. }

这个函数在Vista下,使用也可实现透明效果

Re: BSoD

你说是固定函数么?可以查阅一下,我觉得这个是为了更好的移植性来写的

Comment by wupei (2009/10/08 14:28)

if(ptransparent_fun) ptransparent_fun(this->GetSafeHwnd(), RGB(0, 0, 0), Attributes, 0X2 | 0X1); 好像可以实现的STATIC 不知道你说的是不是这个意思
Comment by BSoD (2009/07/14 18:18)

发表评论 ( 如果您刚刚提交过评论,但是还没有被显示出来,请点击这里刷新一下: 刷新评论 )

标题

内容*

昵称*

电子邮件

个人网页


 authimage