# Re: 将视窗所覆盖桌面贴到视窗背景

Posted by Honey on July 24, 1999 at 23:32:44:

In Reply to: 将视窗所覆盖桌面贴到视窗背景 posted by hspeed on July 24, 1999 at 15:04:09:

想制作透明表单呀 在form上放一个command1
贴上以下程式码 form的AutoRedraw属性要改成true
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal _
hDestDC As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal _
nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc _
As Long, ByVal ySrc As Long, ByVal dwRop As Long) _
As Long
Private Declare Function ReleaseDC Lib "user32" _
(ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd _
As Long) As Long
Private Sub Command1_Click()
Dim SCRhDC As Long
Dim X As Long, Y As Long
Dim X1 As Long, Y1 As Long
Me.Hide
DoEvents
SCRhDC = GetDC(0)
X = Me.ScaleWidth \ _
Screen.TwipsPerPixelX '/*表单内部宽度单位换成像数*/
Y = Me.ScaleHeight \ _
Screen.TwipsPerPixelY '/*表单内部高度单位换成像数*/
If Me.BorderStyle = 0 Then '/*没有线框*/
X1 = Me.Left \ Screen.TwipsPerPixelX
Y1 = Me.Top \ Screen.TwipsPerPixelY
Else '/*有线框*/
X1 = (Me.Width - Me.ScaleWidth) \ 2 \ Screen.TwipsPerPixelX '/*线框宽度*/
Y1 = (Me.Height - Me.ScaleHeight) \ Screen.TwipsPerPixelY '/*工具bar高度*/
Y1 = Y1 - X1 + Me.Top \ Screen.TwipsPerPixelY
X1 = Me.Left \ Screen.TwipsPerPixelX + X1
End If
BitBlt Me.hDC, 0, 0, _
X, Y, SCRhDC, X1, Y1, vbSrcCopy
ReleaseDC 0, SCRhDC
Me.Show
End Sub
'以上示范定位的方法
'其实就是在程式执行前 将表单隐藏 抓下萤幕的图示
'而后现出表单 绘上图示 在表单移动时也得不断的抓取图示
但form不能一再隐藏 否则闪烁会很严重 你得将之前抓到的图示存起来
一块一块的覆盖上新的部分 不过用VB做 恐怕会闪的很严重
加点DirectX的技术吧

Follow Ups: