• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB调用API制作渐变的窗口背景色

发布: 2007-6-21 21:57 | 作者: 吴斌  | 来源: 水木清华  | 查看: 151次 | 进入软件测试论坛讨论

领测软件测试网

   
  在许多Windows软件的安装程序中,时常可以看到以某种颜色由浅至深的渐变为背景的窗口。使用VB制作这类窗口的方法有不少,而通过调用API函数绘制渐变的窗口背景色,似乎是一种既简单又节省资源的方法。

  首先,在module文件中加入下列声明语句:

  Declare Function CreateSolidBrush Lib"GDI"(ByVal _
crColor As Long) As Integer

  Declare Function FillRect Lib"USER"(ByVal hDC As _
Integer,lpRect As RECT,ByVal hBrush As Integer)As Integer

  Declare Function DeleteObject Lib"GDI"(ByVal hObject _
As Integer)As Integer

  Type RECT
  left As Integer
   top As Integer
   right As Integer
   bottom As Integer
  EndType

  然后,在窗口的Paint事件中加入下列代码:

  Private Sub Form_Paint()
  Dim Color As Integer
  Dim hBrush As Integer
  Dim OldMode As Integer
  Dim RetVal As Integer
  Dim StepSize As Integer
  Dim X As Integer
  Dim FillArea As RECT

  OldMode%=Me.ScaleMode
  Me.ScaleMode=3
  StepSize%=1+Me.ScaleHeight/80
  Color%=255
  FillArea.left=0
  FillArea.right=Me.ScaleWidth
  FillArea.top=0
  FillArea.bottom=StepSize%
  For X%=1 To 80
  hBrush%=CreateSolidBrush (RGB(0,0,Color%))
   RetVal%=FillRect(Me.hDC,FillArea,hBrush%)
   RetVal%=DeleteObject(hBrush%)
  Color%=Color%-4
   If Color% $#@60; 0 Then Color%=0
   FillArea.top=FillArea.bottom
  FillArea.bottom=FillArea.bottom+StepSize%
  Next
  Me.ScaleMode=OldMode%
  EndSub

  按F5运行,就会出现一个以从上至下、由浅至深的渐变蓝色为背景的窗口。对上述代码稍加改动,便可制作出各种颜色和水平方向的渐变背景。

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网