首页 >> 读书频道 >> 电脑 >> 在VB中利用API实现窗体的平滑显示
 
· 用VB实现应用程序在局域
· 用VB制作常居上层的浮动
· 动态拖曳ListBox
· 在VB中使用Delphi
· 更改文件日期时间
· 将MdiForm内的Fo
· 侦测离开Form进入其他
· Disable Form
· 隐藏TextBox的Ca
· 按下HotKey以叫起视
· 按下某组键(HotKey
· 隐藏Mouse
 
· 电视剧《刁蛮公主》下载和
· 美容养颜手册
· 加油金顺剧情分集介绍完整
· 红楼梦:120回全本[清
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 武林寓言故事
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

在VB中利用API实现窗体的平滑显示


查看有无更新版本

关键字:VB 2006-9-18

 

Win98的一个新功能是窗体能够平滑显示,那我们是否能编程来实现这种功能呢?答案是肯定的。首先讲述一下原理,其实我并没有让窗体本身平滑地显示,而是在窗体显示之前在窗体的位置上画一系列的矩形,利用视觉暂留让人以为是窗体在从小变大。
下面就用VB来实现这种功能。
建立两个窗体form1和form2,在form1上添加如下控件:由五个optionbutton控件组成的控件数组,index为0-4,caption属性分别为“从中间扩散”、“右上到左下”、“左上到右下”、“右下到左上”和“左上到右下”,一个commandbutton,caption属性为“显示窗体”, 添加一个模块其中代码如下:
Option Explicit
`声明所用的API函数、常量和变量 
Public Declare Function GetDC Lib “user32” (ByVal hwnd As Long) As Long
Public Declare Function Rectangle Lib “gdi32” (ByVal hdc As Long, _
ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2_
As Long) As Long
Public Declare Function SelectObject Lib “gdi32” (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Public Declare Function DeleteObject Lib “gdi32”(ByVal hObject As _
Long) As Long
Public Declare Function ReleaseDC Lib “user32” (ByVal hwnd As Long,_
ByVal hdc As Long) As Long
Public Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
Public Declare Function CreateSolidBrush Lib “gdi32” (ByVal crColor As_
Long) As Long
Public Declare Function GetBkColor Lib “gdi32” (ByVal hdc As Long) As Long
Public hbrush As Long, hdc5 As Long
Public dx As Long, dy As Long
Public rx1 As Long, rx2 As Long, ry1 As Long, ry2 As Long
Public i As Long, j As Long, bcolor As Long
Public ind As Integer
Public DispCnt As Long

Public Sub showform(win As Form, ind)
DispCnt = 60 `画几个矩形后显示窗体
`下面这段代码用来获得窗体颜色,不用me.backcolor的原因是窗体颜色不一定是系统调色板的颜色,如果用me.backcolor的话颜色可能会不准。
hdc5 = GetDC(0) 
bcolor = GetBkColor(win.hdc)
hbrush = CreateSolidBrush(bcolor)`设定刷子颜色
Call SelectObject(hdc5, hbrush)
dx = win.Width \ (DispCnt)
dy = win.Height \ (DispCnt)
j = 1
Select Case ind
Case 1
dx = dx \ 2; dy = dy \ 2
For i = DispCnt To 1 Step -1
rx1 = (win.Left + dx * (i - 1)) \ Screen.TwipsPerPixelX
ry1 = (win.Top + dy * (i - 1)) \ Screen.TwipsPerPixelY
rx2 = rx1 + dx * 2 * j \ Screen.TwipsPerPixelX
ry2 = rx1 + dy * 2 * j \ Screen.TwipsPerPixelY
j = j + 1
Call Rectangle(hdc5, rx1, ry1, rx2, ry2)
Sleep (1); Next i
Case 2
For i = DispCnt To 1 Step -1
rx1 = (win.Left + win.Width - dx * j) \ Screen.TwipsPerPixelX
ry1 = win.Top \ Screen.TwipsPerPixelY
rx2 = (win.Left + win.Width) \ Screen.TwipsPerPixelX
ry2 = (win.Top + dy * j) \ Screen.TwipsPerPixelY
j = j + 1
Call Rectangle(hdc5, rx1, ry1, rx2, ry2)
Sleep (1); Next i
Case 3
For i = DispCnt To 1 Step -1
rx1 = win.Left \ Screen.TwipsPerPixelX
ry1 = win.Top \ Screen.TwipsPerPixelY
rx2 = rx1 + dx * j \ Screen.TwipsPerPixelX
ry2 = rx1 + dy * j \ Screen.TwipsPerPixelY
j = j + 1
Call Rectangle(hdc5, rx1, ry1, rx2, ry2)
Sleep (1); Next i
Case 4
For i = DispCnt To 1 Step -1
rx1 = (win.Left + dx * (i - 1)) \ Screen.TwipsPerPixelX
ry1 = (win.Top + dy * (i - 1)) \ Screen.TwipsPerPixelY
rx2 = (win.Left + win.Width) \ Screen.TwipsPerPixelX
ry2 = (win.Top + win.Height) \ Screen.TwipsPerPixelY
j = j + 1
Call Rectangle(hdc5, rx1, ry1, rx2, ry2)
Sleep (1); Next i
Case 5
For i = DispCnt To 1 Step -1
rx1 = (win.Left) \ Screen.TwipsPerPixelX
ry1 = (win.Top + win.Height - dy * j) \ Screen.TwipsPerPixelY
rx2 = (win.Left + dx * j) \ Screen.TwipsPerPixelX
ry2 = (win.Top + win.Height) \ Screen.TwipsPerPixelY
j = j + 1
Call Rectangle(hdc5, rx1, ry1, rx2, ry2)
Sleep (1); Next i
End Select
Call ReleaseDC(0, hdc5)`释放设备描述表
Call DeleteObject(hbrush)`删除刷子
End Sub 
在form1中输入如下代码
Private Sub Command1_Click()`显示窗体
Unload Form2
Load Form2
Form2.Show
End Sub

Private Sub Form_Load()
ind = 1`初始化参数
End Sub

Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0
ind = 1
Case 1
ind = 2
Case 2
ind = 3
Case 3
ind = 4
Case 4
ind = 5
Case 5
ind = 6
End Select
 
End Sub
在form2中输入如下代码
Private Sub Form_Load()
Call showform(Me, ind)
End Sub
本程序调用了一些有关系统和绘图的API函数,有利于大家进一步了解API函数的功能。本程序在vb5企业版,Win98中运行通过。

在VB中利用API实现窗体的平滑显示

[ 1 ]
在VB中利用API实现窗体的平滑显示 num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑