CreatePolygonRgn VB声明 Declare Function CreatePolygonRgn Lib "gdi32" Alias "CreatePolygonRgn" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long 说明 创建一个由一系列点围成的区域。windows在需要时自动将最后点与第一点相连以封闭多边形 返回值 Long,执行成功为创建的区域句柄,失败则为0 参数表 参数 类型及说明 lpPoint POINTAPI,nCount个POINTAPI结构中的第一个POINTAPI结构 nCount Long,多边形的点数 nPolyFillMode Long,描述多边形填充模式。可为ALTERNATE 或 WINDING常数。参考SetPolyFillMode函数对多边形填充模式的解释 注解 不用时一定要用DeleteObject函数删除该区域
Option Explicit 'Public Const LWA_COLORKEY = &H1 Public Const LWA_ALPHA = &H2 Public Const GWL_EXSTYLE = (-20) Public Const WS_EX_LAYERED = &H80000 Public Const WS_EX_TRANSPARENT As Long = &H20& Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public 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 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Const HWND_TOPMOST = -1
Public Function SetMouseIn(ByVal hwnd As Long, Optional TouMing As Long = 200, Optional Top As Boolean = True) As Long Dim Ret As Long Ret = GetWindowLong(hwnd, GWL_EXSTYLE) Ret = Ret Or WS_EX_LAYERED' Or WS_EX_TRANSPARENT SetWindowLong hwnd, GWL_EXSTYLE, Ret SetLayeredWindowAttributes hwnd, 0, TouMing, LWA_ALPHA If Top Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End Function
WINXP,楼上的方法我没弄出来,请再指教
Option Explicit 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 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 Sub Form_Load() Dim rtn As Long rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取的窗口原先的样式 rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体 SetLayeredWindowAttributes Me.hwnd, vbBlue, 0, LWA_COLORKEY '表明不显示窗体中的透明色,而第二个参数表示透明色为蓝色,并且你可以用RGB函数来指定颜色值 End Sub
Declare Function CreatePolygonRgn Lib "gdi32" Alias "CreatePolygonRgn" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
说明
创建一个由一系列点围成的区域。windows在需要时自动将最后点与第一点相连以封闭多边形
返回值
Long,执行成功为创建的区域句柄,失败则为0
参数表
参数 类型及说明
lpPoint POINTAPI,nCount个POINTAPI结构中的第一个POINTAPI结构
nCount Long,多边形的点数
nPolyFillMode Long,描述多边形填充模式。可为ALTERNATE 或 WINDING常数。参考SetPolyFillMode函数对多边形填充模式的解释
注解
不用时一定要用DeleteObject函数删除该区域
'Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT As Long = &H20&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public 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
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Function SetMouseIn(ByVal hwnd As Long, Optional TouMing As Long = 200, Optional Top As Boolean = True) As Long
Dim Ret As Long
Ret = GetWindowLong(hwnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED' Or WS_EX_TRANSPARENT
SetWindowLong hwnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes hwnd, 0, TouMing, LWA_ALPHA
If Top Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Function
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 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 Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取的窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体
SetLayeredWindowAttributes Me.hwnd, vbBlue, 0, LWA_COLORKEY '表明不显示窗体中的透明色,而第二个参数表示透明色为蓝色,并且你可以用RGB函数来指定颜色值
End Sub
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Sub Form_Load()
Dim ShapeV(128) As POINTAPI
On Error Resume Next
ShapeV(0).X = 4: ShapeV(0).Y = 51
ShapeV(1).X = 4: ShapeV(1).Y = 69
ShapeV(2).X = 42: ShapeV(2).Y = 65
ShapeV(3).X = 41: ShapeV(3).Y = 99
ShapeV(4).X = 9: ShapeV(4).Y = 99
ShapeV(5).X = 9: ShapeV(5).Y = 260
ShapeV(6).X = 26: ShapeV(6).Y = 261
ShapeV(7).X = 26: ShapeV(7).Y = 256
ShapeV(8).X = 102: ShapeV(8).Y = 255
ShapeV(9).X = 103: ShapeV(9).Y = 261
ShapeV(10).X = 120: ShapeV(10).Y = 261
ShapeV(11).X = 119: ShapeV(11).Y = 100
ShapeV(12).X = 87: ShapeV(12).Y = 100
ShapeV(13).X = 87: ShapeV(13).Y = 66
ShapeV(14).X = 123: ShapeV(14).Y = 66
ShapeV(15).X = 123: ShapeV(15).Y = 52
ShapeV(16).X = 4: ShapeV(16).Y = 51
ShapeV(17).X = 27: ShapeV(17).Y = 113
ShapeV(18).X = 4: ShapeV(18).Y = 51
ShapeV(19).X = 27: ShapeV(19).Y = 113
ShapeV(20).X = 4: ShapeV(20).Y = 51
ShapeV(21).X = -2: ShapeV(21).Y = 0
ShapeV(22).X = -2: ShapeV(22).Y = 19
ShapeV(23).X = 255: ShapeV(23).Y = 19
ShapeV(24).X = 255: ShapeV(24).Y = 0
ShapeV(25).X = -2: ShapeV(25).Y = 0
ShapeV(26).X = 4: ShapeV(26).Y = 51
ShapeV(27).X = 27: ShapeV(27).Y = 113
ShapeV(28).X = 4: ShapeV(28).Y = 51
ShapeV(29).X = 57: ShapeV(29).Y = 65
ShapeV(30).X = 57: ShapeV(30).Y = 101
ShapeV(31).X = 72: ShapeV(31).Y = 101
ShapeV(32).X = 72: ShapeV(32).Y = 65
ShapeV(33).X = 57: ShapeV(33).Y = 65
ShapeV(34).X = 4: ShapeV(34).Y = 51
ShapeV(35).X = 27: ShapeV(35).Y = 221
ShapeV(36).X = 27: ShapeV(36).Y = 243
ShapeV(37).X = 102: ShapeV(37).Y = 243
ShapeV(38).X = 102: ShapeV(38).Y = 221
ShapeV(39).X = 27: ShapeV(39).Y = 221
ShapeV(40).X = 4: ShapeV(40).Y = 51
ShapeV(41).X = 166: ShapeV(41).Y = 190
ShapeV(42).X = 4: ShapeV(42).Y = 51
ShapeV(43).X = 166: ShapeV(43).Y = 191
ShapeV(44).X = 166: ShapeV(44).Y = 235
ShapeV(45).X = 214: ShapeV(45).Y = 235
ShapeV(46).X = 214: ShapeV(46).Y = 191
ShapeV(47).X = 166: ShapeV(47).Y = 191
ShapeV(48).X = 4: ShapeV(48).Y = 51
ShapeV(49).X = 150: ShapeV(49).Y = 49
ShapeV(50).X = 4: ShapeV(50).Y = 51
ShapeV(51).X = 4: ShapeV(51).Y = 51
ShapeV(52).X = 145: ShapeV(52).Y = 177
ShapeV(53).X = 147: ShapeV(53).Y = 195
ShapeV(54).X = 146: ShapeV(54).Y = 251
ShapeV(55).X = 146: ShapeV(55).Y = 262
ShapeV(56).X = 165: ShapeV(56).Y = 260
ShapeV(57).X = 165: ShapeV(57).Y = 249
ShapeV(58).X = 214: ShapeV(58).Y = 247
ShapeV(59).X = 214: ShapeV(59).Y = 262
ShapeV(60).X = 233: ShapeV(60).Y = 262
ShapeV(61).X = 233: ShapeV(61).Y = 256
ShapeV(62).X = 232: ShapeV(62).Y = 250
ShapeV(63).X = 233: ShapeV(63).Y = 186
ShapeV(64).X = 234: ShapeV(64).Y = 185
ShapeV(65).X = 234: ShapeV(65).Y = 177
ShapeV(66).X = 145: ShapeV(66).Y = 177
ShapeV(67).X = 4: ShapeV(67).Y = 51
ShapeV(68).X = 150: ShapeV(68).Y = 49
ShapeV(69).X = 142: ShapeV(69).Y = 74
ShapeV(70).X = 136: ShapeV(70).Y = 90
ShapeV(71).X = 127: ShapeV(71).Y = 107
ShapeV(72).X = 140: ShapeV(72).Y = 119
ShapeV(73).X = 155: ShapeV(73).Y = 95
ShapeV(74).X = 157: ShapeV(74).Y = 93
ShapeV(75).X = 181: ShapeV(75).Y = 92
ShapeV(76).X = 182: ShapeV(76).Y = 135
ShapeV(77).X = 127: ShapeV(77).Y = 134
ShapeV(78).X = 127: ShapeV(78).Y = 149
ShapeV(79).X = 249: ShapeV(79).Y = 150
ShapeV(80).X = 249: ShapeV(80).Y = 132
ShapeV(81).X = 200: ShapeV(81).Y = 134
ShapeV(82).X = 199: ShapeV(82).Y = 92
ShapeV(83).X = 238: ShapeV(83).Y = 91
ShapeV(84).X = 238: ShapeV(84).Y = 78
ShapeV(85).X = 199: ShapeV(85).Y = 78
ShapeV(86).X = 200: ShapeV(86).Y = 35
ShapeV(87).X = 180: ShapeV(87).Y = 35
ShapeV(88).X = 182: ShapeV(88).Y = 78
ShapeV(89).X = 161: ShapeV(89).Y = 78
ShapeV(90).X = 170: ShapeV(90).Y = 58
ShapeV(91).X = 150: ShapeV(91).Y = 49
ShapeV(92).X = 150: ShapeV(92).Y = 49
ShapeV(93).X = 4: ShapeV(93).Y = 51
ShapeV(94).X = 87: ShapeV(94).Y = 113
ShapeV(95).X = 101: ShapeV(95).Y = 113
ShapeV(96).X = 102: ShapeV(96).Y = 171
ShapeV(97).X = 94: ShapeV(97).Y = 169
ShapeV(98).X = 90: ShapeV(98).Y = 165
ShapeV(99).X = 87: ShapeV(99).Y = 160
ShapeV(100).X = 86: ShapeV(100).Y = 152
ShapeV(101).X = 87: ShapeV(101).Y = 113
ShapeV(102).X = 87: ShapeV(102).Y = 113
ShapeV(103).X = 4: ShapeV(103).Y = 51
ShapeV(104).X = 26: ShapeV(104).Y = 113
ShapeV(105).X = 26: ShapeV(105).Y = 206
ShapeV(106).X = 101: ShapeV(106).Y = 206
ShapeV(107).X = 101: ShapeV(107).Y = 187
ShapeV(108).X = 85: ShapeV(108).Y = 187
ShapeV(109).X = 79: ShapeV(109).Y = 183
ShapeV(110).X = 73: ShapeV(110).Y = 176
ShapeV(111).X = 71: ShapeV(111).Y = 169
ShapeV(112).X = 70: ShapeV(112).Y = 150
ShapeV(113).X = 70: ShapeV(113).Y = 113
ShapeV(114).X = 55: ShapeV(114).Y = 113
ShapeV(115).X = 55: ShapeV(115).Y = 141
ShapeV(116).X = 53: ShapeV(116).Y = 156
ShapeV(117).X = 51: ShapeV(117).Y = 165
ShapeV(118).X = 45: ShapeV(118).Y = 191 ShapeV(119).X = 44: ShapeV(119).Y = 191
ShapeV(120).X = 32: ShapeV(120).Y = 186
ShapeV(121).X = 32: ShapeV(121).Y = 182
ShapeV(122).X = 38: ShapeV(122).Y = 157
ShapeV(123).X = 41: ShapeV(123).Y = 130
ShapeV(124).X = 41: ShapeV(124).Y = 114
ShapeV(125).X = 26: ShapeV(125).Y = 113
ShapeV(126).X = 26: ShapeV(126).Y = 113
ShapeV(127).X = 4: ShapeV(127).Y = 51
Me.Width = 3915
Me.Height = 3915
Me.BackColor = vbBlue
er = SetWindowRgn(Me.hwnd, CreatePolygonRgn(ShapeV(0), 128, 1), True)
Me.Show
End Sub
按F5运行看看