VB6.0 透明的窗体怎么弄?

在网上找了一些代码,但它的效果是整个界面都透明了,包括窗体里的按钮,文本框等等。我需要一个透明的窗体,他只是窗体透明,但里面的按钮等其他元素是非透明的,看起来就像几个按钮... 在网上找了一些代码,但它的效果是整个界面都透明了,包括窗体里的按钮,文本框等等。
我需要一个透明的窗体,他只是窗体透明,但里面的按钮等其他元素是非透明的,看起来就像几个按钮漂浮在屏幕上,并且把窗体的标题栏去掉,
太久没弄VB了,呵呵,请大神们帮帮我!
展开
 我来答
floatingsnows
推荐于2016-07-06 · TA获得超过1798个赞
知道小有建树答主
回答量:1318
采纳率:66%
帮助的人:419万
展开全部
设置:窗体的Borderstyle=0 '此时窗体无边框
然后:
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
Private Declare Function SetLayeredWindowAttributes Lib "磨知瞎user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function SetWindowPos& Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
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_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Form_Load()
Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
Me.BackColor = vbred '透明色为红色
SetWindowLong Me.hwnd, -20, GetWindowLong(Me.hwnd, -20) Or &H80000
SetLayeredWindowAttributes Me.hwnd, vbred, 0, 1
end sub

这样的话所有的红色元素都会消猛或失
此时你会无法移动窗体
所以
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
End Sub
这样你按住command1就可以拖动窗体瞎空了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
aspd199
2010-08-26 · TA获得超过906个赞
知道小有建树答主
回答量:865
采纳率:50%
帮助的人:484万
展开全部
很简单,form的borderstyle=0 '去闷激掉标题栏
用SetLayeredWindowAttributes 设置窗体透胡缓明即可蚂做袜

参考资料: vb专业解答团 http://zhidao.baidu.com/team/view/VB%D7%A8%D2%B5%BD%E2%B4%F0%CD%C5

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
_Bluedream
2010-08-26
知道答主
回答量:10
采纳率:0%
帮助的人:0
展开全部
怎么会都是透明的呢。用SetLayeredWindowAttributes呗,把某不常用颜色设为掩码色,运行岁消后所有此颜色处将透明。
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
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Const WS_EX_LAYERED = &H80000

Private Sub Form_Load()
Me.BackColor = RGB(88, 88, 88)
'庆迟Label1.BackColor = RGB(88, 88, 88)
'需要透明的控件的背景色设为同样的颜色
Me.BorderStyler = 0 ‘去掉标题栏
Dim rtn As Long
rtn = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes Me.hWnd, RGB(88, 88, 88), 0, LWA_COLORKEY
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式