********************************************************************
制造出透明的Form
注释:form上有Command1, command2两个Button并事先设定form之BorderStyle = 0
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const GWL_EXSTYLE = (-20)
Const WS_EX_TRANSPARENT = &H20&
Private PreValue As Long
Private Sub Command2_Click() 注释:还原变成不透明
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, PreValue)
Me.Hide
Me.Show
End Sub
Private Sub Form_Load()
Dim i As Long
i = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
注释:变成透明的Form
PreValue = SetWindowLong(Me.hwnd, GWL_EXSTYLE, i Or WS_EX_TRANSPARENT)
Me.Show
DoEvents
Command1.Refresh 注释:令Command1可见
Command2.Refresh 注释:令Command2可见
End Sub
********************************************************************
问题是当还原的时候窗体的一些参数也跟着还原了.比如窗体的位置又回到默认的地方(屏幕中心),透明度回到了完全可见状态(假如窗体有设置透明度的功能).
这样的话要还原成窗体透明之前的状态就很麻烦了,设置窗体透明之前窗体的位置和透明度的相关参数要事先记录;还原的时候再把记录的参数赋给窗体,大大增加了工作量和程序的臃肿度(啤酒肚?).
除了用Me.Hide Me.Show以外有没有简单一点的方法?SetWindowLong中有没有相关的参数可以直接使窗体还原(不影响其他设置)?
顺便帮lzanze (小泽) 兄弟解决问题:
http://community.csdn.net/Expert/topic/4192/4192833.xml?temp=.5794031
拜托各位了 m(_ _)m
7 个解决方案
#1
吐啊吐啊就习惯了,呵呵
#2
瞧你那呕样!!!
哈哈哈....
顶一下
哈哈哈....
顶一下
#3
up
#4
没别的办法了吗?
#5
只是要制作透明窗体??
可以利用这个:
declare function CreateCompatibleBitmap lib "gdi32" (byval hdc as long,byval nWidth as long,byval nHeight as long) as long
declare function SelectObject lib "gdi32" (byval hdc as long,byval hObject as long) as long
Private Sub MakeWindow()
Dim hBmp As Long
AutoRedraw = True
hBmp = CreateCompatibleBitmap(hdc, 0, 0)
SelectObject hdc, hBmp
Refresh
End Sub
这个窗体虽然透明,但一移动就会穿帮了。
可以利用这个:
declare function CreateCompatibleBitmap lib "gdi32" (byval hdc as long,byval nWidth as long,byval nHeight as long) as long
declare function SelectObject lib "gdi32" (byval hdc as long,byval hObject as long) as long
Private Sub MakeWindow()
Dim hBmp As Long
AutoRedraw = True
hBmp = CreateCompatibleBitmap(hdc, 0, 0)
SelectObject hdc, hBmp
Refresh
End Sub
这个窗体虽然透明,但一移动就会穿帮了。
#6
用Me.Refresh或Me.SetFocus也可以,但效果也不是很好,只是窗体的位置不改变了
#7
唉,算是白问了,还得我自己解决
把Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, PreValue)中的PreValue替换成记录透明值的变量就OK了.哈哈,结贴
把Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, PreValue)中的PreValue替换成记录透明值的变量就OK了.哈哈,结贴
#1
吐啊吐啊就习惯了,呵呵
#2
瞧你那呕样!!!
哈哈哈....
顶一下
哈哈哈....
顶一下
#3
up
#4
没别的办法了吗?
#5
只是要制作透明窗体??
可以利用这个:
declare function CreateCompatibleBitmap lib "gdi32" (byval hdc as long,byval nWidth as long,byval nHeight as long) as long
declare function SelectObject lib "gdi32" (byval hdc as long,byval hObject as long) as long
Private Sub MakeWindow()
Dim hBmp As Long
AutoRedraw = True
hBmp = CreateCompatibleBitmap(hdc, 0, 0)
SelectObject hdc, hBmp
Refresh
End Sub
这个窗体虽然透明,但一移动就会穿帮了。
可以利用这个:
declare function CreateCompatibleBitmap lib "gdi32" (byval hdc as long,byval nWidth as long,byval nHeight as long) as long
declare function SelectObject lib "gdi32" (byval hdc as long,byval hObject as long) as long
Private Sub MakeWindow()
Dim hBmp As Long
AutoRedraw = True
hBmp = CreateCompatibleBitmap(hdc, 0, 0)
SelectObject hdc, hBmp
Refresh
End Sub
这个窗体虽然透明,但一移动就会穿帮了。
#6
用Me.Refresh或Me.SetFocus也可以,但效果也不是很好,只是窗体的位置不改变了
#7
唉,算是白问了,还得我自己解决
把Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, PreValue)中的PreValue替换成记录透明值的变量就OK了.哈哈,结贴
把Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, PreValue)中的PreValue替换成记录透明值的变量就OK了.哈哈,结贴