永发信息网

VB中能不能把窗口变成透明的

答案:4  悬赏:40  手机版
解决时间 2021-07-31 06:55
  • 提问者网友:山高云阔
  • 2021-07-30 06:47

就是VB运行时窗口里没有控件的地方是透明的 直接给出方法或者代码就可以了

最佳答案
  • 五星知识达人网友:長槍戰八方
  • 2021-07-30 08:09

调试过


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 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 WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1




Private Sub Form_Load() '窗体透明,控件不透明
Me.BackColor = &H0
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes Me.hwnd, &H0, 255, LWA_ALPHA Or LWA_COLORKEY '这里的255是透明度,0-255之间
End Sub

全部回答
  • 1楼网友:孤独入客枕
  • 2021-07-30 10:54

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 WS_EX_LAYERED = &H80000 Private Const GWL_EXSTYLE = (-20) Private Const LWA_ALPHA = &H2 Private Const LWA_COLORKEY = &H1

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) As Long Private Const HWND_TOPMosT = -1 Private Const SWP_NOMOVE = &H2 Private Const SWP_NosIZE = &H1 '''''''''''''''''''''''''''''''''''''' Private Sub Form_Load() Me.BackColor = RGB(88, 88, 88) SetWindowPos Me.hwnd, HWND_TOPMosT, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NosIZE Dim rtn As Long BorderStyler = 0 rtn = GetWindowLong(hwnd, GWL_EXSTYLE) rtn = rtn Or WS_EX_LAYERED SetWindowLong hwnd, GWL_EXSTYLE, rtn SetLayeredWindowAttributes hwnd, RGB(88, 88, 88), 0, LWA_COLORKEY End Sub

  • 2楼网友:逐風
  • 2021-07-30 09:49

可以,使用api函数就可以做得到

  • 3楼网友:西岸风
  • 2021-07-30 09:18

可以,我把代码发给你

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯