CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

98窗体透明

楼主sunxl(小呆)2002-07-10 09:13:20 在 VB / 基础类 提问

对不起   我说的是半透明   good_sun的例子不行  
   
  但是   看good_sun给我发了例子   决定给good_sun100分  
   
  还是那句话   谁能实现   98窗体半透明我给1000分  
   
  问题点数:100、回复次数:11Top

1 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2002-07-10 09:19:59 得分 0

他是怎么做的?  
  是在运行前保存屏幕吗?Top

2 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2002-07-10 09:32:42 得分 20

其实Windows自身的拖动文件的半透明都没有算好  
  拖动的文件的图标所在的窗体不会刷新  
  而且那图标只在拖动所在的窗体  
  不像普通窗体一样可以跑到其他窗体的上面Top

3 楼sunxl(小呆)回复于 2002-07-10 09:40:59 得分 0

CombineRgn  
  抠去客户区区域  
  他把窗体抠窟窿  
  他指不规则窗体是透明窗体  
   
   
  Public   Function   TransForm(lpForm   As   Form,   Optional   lpTitleBar   As   Boolean   =   False)  
          Dim   ctl   As   Control,   AllRgn   As   Long,   tmpRgn   As   Long,   SM   As   Integer  
           
          '储存窗体度量单位  
          SM   =   lpForm.ScaleMode  
          '改变度量单位为——点  
          lpForm.ScaleMode   =   vbPixels  
           
          '创建初始窗体区域  
          AllRgn   =   CreateRectRgn(0,   0,   0,   0)  
           
          '如果要保留标题栏和窗体边框则执行以下语句  
          If   lpTitleBar   Then  
                  Dim   tmpBoardRgn   As   Long,   tmpCilentRgn   As   Long,   tmpRect   As   RECT  
                  '得到窗体大小  
                  GetWindowRect   lpForm.hwnd,   tmpRect  
                  '创建一个与窗体一样大小的区域  
                  tmpBoardRgn   =   CreateRectRgn(0,   0,   tmpRect.Right   -   tmpRect.Left,   tmpRect.Bottom   -   tmpRect.Top)  
                  '创建一个与窗体客户区(窗体除去标题栏和边框的区域叫客户区)一样大小的区域  
                  tmpCilentRgn   =   CreateRectRgn(GetWindowBoardWidth(lpForm)   -   1,   _  
                                                  GetWindowCaptionWidth(lpForm)   +   GetWindowBoardWidth(lpForm)   -   1,   _  
                                                  tmpRect.Right   -   tmpRect.Left   -   GetWindowBoardWidth(lpForm),   _  
                                                  tmpRect.Bottom   -   tmpRect.Top   -   GetWindowBoardWidth(lpForm))  
                  '合并区域  
                  CombineRgn   AllRgn,   AllRgn,   tmpBoardRgn,   RGN_OR  
                  '抠去客户区区域  
                  CombineRgn   AllRgn,   AllRgn,   tmpCilentRgn,   RGN_DIFF  
                  '释放资源  
                  DeleteObject   tmpBoardRgn  
                  DeleteObject   tmpCilentRgn  
          End   If  
           
          '开始创建控件区域  
          On   Error   Resume   Next  
          '扫描窗体上每一个控件的区域  
          For   Each   ctl   In   lpForm.Controls  
                  '只有当当前控件的容器是窗体并且当前控件可见,才将此控件区域计算在内  
                  If   ctl.Container.Name   =   lpForm.Name   And   ctl.Visible   =   True   Then  
                          tmpRgn   =   CreateRectRgn(ctl.Left   +   GetWindowBoardWidth(lpForm),   _  
                                          ctl.Top   +   GetWindowCaptionWidth(lpForm)   +   GetWindowBoardWidth(lpForm),   _  
                                          ctl.Left   +   ctl.Width   +   GetWindowBoardWidth(lpForm),   _  
                                          ctl.Top   +   ctl.Height   +   GetWindowCaptionWidth(lpForm)   +   GetWindowBoardWidth(lpForm))  
                          If   Not   Err   Then  
                                  '如果产生错误说明当前控件在运行时不可显示在窗体上  
                                  '或此控件没有Width  
                                  '和Height属性,那就不考虑此控件的区域。(例如Timer控件、Line控件)  
                                  CombineRgn   AllRgn,   AllRgn,   tmpRgn,   RGN_OR  
                          End   If  
                          '清除错误  
                          Err.Clear  
                          '释放资源  
                          DeleteObject   tmpRgn  
                  End   If  
          Next  
          On   Error   GoTo   0  
           
          '改变窗体,释放资源  
          SetWindowRgn   lpForm.hwnd,   AllRgn,   True  
          DeleteObject   AllRgn  
           
          '恢复窗体度量单位  
          lpForm.ScaleMode   =   SM  
  End   Function  
   
   
  Top

4 楼sunxl(小呆)回复于 2002-07-10 09:49:02 得分 0

 
  Private   Declare   Function   CreateRectRgn   Lib   "gdi32"   (ByVal   X1   As   Long,   ByVal   Y1   As   Long,   ByVal   X2   As   Long,   ByVal   Y2   As   Long)   As   Long  
  Private   Declare   Function   SetWindowRgn   Lib   "user32"   (ByVal   hwnd   As   Long,   ByVal   hRgn   As   Long,   ByVal   bRedraw   As   Boolean)   As   Long  
  Private   Declare   Function   DeleteObject   Lib   "gdi32"   (ByVal   hObject   As   Long)   As   Long  
  Private   Declare   Function   CombineRgn   Lib   "gdi32"   (ByVal   hDestRgn   As   Long,   ByVal   hSrcRgn1   As   Long,   ByVal   hSrcRgn2   As   Long,   ByVal   nCombineMode   As   Long)   As   Long  
  Private   Declare   Function   GetClientRect   Lib   "user32"   (ByVal   hwnd   As   Long,   lpRect   As   RECT)   As   Long  
  Private   Declare   Function   GetWindowRect   Lib   "user32"   (ByVal   hwnd   As   Long,   lpRect   As   RECT)   As   Long  
  Private   Const   RGN_OR   =   2  
  Private   Const   RGN_DIFF   =   4  
  Private   Type   RECT  
                  Left   As   Long  
                  Top   As   Long  
                  Right   As   Long  
                  Bottom   As   Long  
  End   Type  
   
  Private   Declare   Function   ReleaseCapture   Lib   "user32"   ()   As   Long  
  Private   Declare   Function   SendMessage   Lib   "user32"   Alias   "SendMessageA"   (ByVal   hwnd   As   Long,   ByVal   wMsg   As   Long,   ByVal   wParam   As   Long,   lParam   As   Any)   As   Long  
  Private   Const   WM_NCLBUTTONDOWN   =   &HA1  
  Private   Const   HTCAPTION   =   2'GetWindowBoardWidth函数用来得到窗体边框宽度  
  Private   Function   GetWindowBoardWidth(lpForm   As   Form)   As   Long  
          Dim   tmpRect   As   RECT,   tmpRect2   As   RECT  
           
          GetWindowRect   lpForm.hwnd,   tmpRect  
          GetClientRect   lpForm.hwnd,   tmpRect2  
           
          GetWindowBoardWidth   =   (tmpRect.Right   -   tmpRect.Left   -   tmpRect2.Right   +   tmpRect2.Left)   /   2  
  End   Function  
   
  'GetWindowCaptionWidth函数用来得到窗体标题栏宽度  
  Private   Function   GetWindowCaptionWidth(lpForm   As   Form)   As   Long  
          Dim   tmpRect   As   RECT,   tmpRect2   As   RECT  
           
          GetWindowRect   lpForm.hwnd,   tmpRect  
          GetClientRect   lpForm.hwnd,   tmpRect2  
   
          GetWindowCaptionWidth   =   (tmpRect.Bottom   -   tmpRect.Top   -   tmpRect2.Bottom   +   tmpRect2.Top)   -   GetWindowBoardWidth(lpForm)   *   2  
  End   Function  
   
  Top

5 楼shenxin(木头)回复于 2002-07-10 09:49:37 得分 0

基本上很难,而且没有什么意义,在2000上已经很简单了  
  何必执着于98?Top

6 楼shenxin(木头)回复于 2002-07-10 09:54:17 得分 0

2000下的透明窗口相当简单,何必非执着于98Top

7 楼sunxl(小呆)回复于 2002-07-10 11:01:27 得分 0

如果   我要是隔一点(像素)一抠   能不能仿透明效果呢  
   
   
  示意图:  
   
  ■□■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□■  
  ■□■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□■  
  ■□■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□■  
  ■□■□■□■□■□■□■□■□■□■□■■□■□■□■□■□■□  
   
   
  Top

8 楼sunxl(小呆)回复于 2002-07-10 11:12:56 得分 0

■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  ■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  ■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  ■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  ■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  ■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□  
  □■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□Top

9 楼sunxl(小呆)回复于 2002-07-10 11:20:13 得分 0

我隔一点一抠   是不是可以实现半透明呢Top

10 楼good_sun(汉堡+泡面)回复于 2002-07-10 13:13:20 得分 80

谢了!  
   
  隔一点一抠的方法我也想过,这会有以下的缺点:  
  首先效果肯定不太理想。  
  其次,当用户点击窗体,希望使窗体得到焦点时,可能会让窗体下面的东西得到焦点。  
  我觉着在98里应该可以用BlendAlpha函数实现半透明,但具体的方法还没研究出来。Top

11 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2002-07-10 13:39:35 得分 0

关键在于无法得到下层图像  
  这样就无法通过BlendAlpha计算半透明Top

12 楼good_sun(汉堡+泡面)回复于 2002-07-10 13:43:23 得分 0

是呀~  
  头痛ing~  
  真想知道2000的那个API是怎么实现的Top

相关问题

  • 透明窗体
  • 窗体透明
  • 半透明窗体?
  • 半透明窗体.
  • VB中的透明窗体。
  • 关于透明窗体
  • 透明窗体的作法
  • 如何让窗体"透明"
  • 关于 透明的窗体
  • 透明窗体制作

关键词

  • 区域
  • sun
  • 窗体
  • lpform
  • tmprect
  • allrgn
  • longprivate
  • 半透明
  • tmprgn
  • 透明

得分解答快速导航

  • 帖主:sunxl
  • zyl910
  • good_sun

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo