分享
 
 
 

很酷的透明窗体

王朝厨房·作者佚名  2007-01-04
窄屏简体版  字體: |||超大  

一个Form1,图片框一个PicShape,在图片框内放置任何图片时,系统将使用图片框中的图片为窗体,并且屏蔽图片中白色部分,从而建立特效的变形窗体。

Option Explicit

Dim MoveTrue As Boolean, OldX As Long, OldY As Long

Private Type BITMAP

bmType As Long

bmWidth As Long

bmHeight As Long

bmWidthBytes As Long

bmPlanes As Integer

bmBitsPixel As Integer

bmBits As Long

End Type

Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Sub FitToPicture()

Const RGN_OR = 2

Dim border_width As Single

Dim title_height As Single

Dim bm As BITMAP

Dim bytes() As Byte

Dim ints() As Integer

Dim longs() As Long

Dim R As Integer

Dim C As Integer

Dim start_c As Integer

Dim stop_c As Integer

Dim x0 As Long

Dim y0 As Long

Dim combined_rgn As Long

Dim new_rgn As Long

Dim offset As Integer

Dim colourDepth As Integer

ScaleMode = vbPixels

picShape.ScaleMode = vbPixels

picShape.AutoRedraw = True

picShape.Picture = picShape.Image

注释: 获取窗体的边框大小

border_width = (ScaleX(Width, vbTwips, vbPixels) - ScaleWidth) / 2

title_height = ScaleX(Height, vbTwips, vbPixels) - border_width - ScaleHeight

注释: 获取图片大小

x0 = picShape.Left + border_width

y0 = picShape.Top + title_height

注释:给出图片信息

GetObject picShape.Image, Len(bm), bm

Select Case bm.bmBitsPixel

Case 15, 16:

注释:MsgBox _

"图片框中图片的颜色大高。",vbExclamation + vbOKOnly

colourDepth = 2

注释: 分配空格给图片.

ReDim ints(0 To bm.bmWidthBytes \ 2 - 1, 0 To bm.bmHeight - 1)

注释: 给出图片表面数据

GetBitmapBits picShape.Image, bm.bmHeight * bm.bmWidthBytes, ints(0, 0)

注释: 建立表单区域

For R = 0 To bm.bmHeight - 2

C = 0

Do While C < bm.bmWidth

start_c = 0

stop_c = 0

注释: 查找白色区域,屏蔽

Do While C < bm.bmWidth

If (ints(C, R) And &H7FFF) <> &H7FFF Then Exit Do

C = C + 1

Loop

start_c = C

Do While C < bm.bmWidth

If (ints(C, R) And &H7FFF) = &H7FFF Then Exit Do

C = C + 1

Loop

stop_c = C

If start_c < bm.bmWidth Then

If stop_c >= bm.bmWidth Then stop_c = bm.bmWidth - 1

new_rgn = CreateRectRgn(start_c + x0, R + y0, stop_c + x0, R + y0 + 1)

If combined_rgn = 0 Then

combined_rgn = new_rgn

Else

CombineRgn combined_rgn, combined_rgn, new_rgn, RGN_OR

DeleteObject new_rgn

End If

End If

Loop

Next R

Case 24:

colourDepth = 3

ReDim bytes(0 To bm.bmWidthBytes - 1, 0 To bm.bmHeight - 1)

GetBitmapBits picShape.Image, bm.bmHeight * bm.bmWidthBytes, bytes(0, 0)

For R = 0 To bm.bmHeight - 2

注释: Create a region for this row.

C = 0

Do While C < bm.bmWidth

start_c = 0

stop_c = 0

offset = C * colourDepth

Do While C < bm.bmWidth

If bytes(offset, R) <> 255 Or _

bytes(offset + 1, R) <> 255 Or _

bytes(offset + 2, R) <> 255 Then Exit Do

C = C + 1

offset = offset + colourDepth

Loop

start_c = C

Do While C < bm.bmWidth

If bytes(offset, R) = 255 And _

bytes(offset + 1, R) = 255 And _

bytes(offset + 2, R) = 255 _

Then Exit Do

C = C + 1

offset = offset + colourDepth

Loop

stop_c = C

If start_c < bm.bmWidth Then

If stop_c >= bm.bmWidth Then stop_c = bm.bmWidth - 1

注释: 建立区域

new_rgn = CreateRectRgn(start_c + x0, R + y0, stop_c + x0, R + y0 + 1)

If combined_rgn = 0 Then

combined_rgn = new_rgn

Else

CombineRgn combined_rgn, combined_rgn, new_rgn, RGN_OR

DeleteObject new_rgn

End If

End If

Loop

Next R

Case 32:

colourDepth = 4

ReDim longs(0 To bm.bmWidthBytes \ 4 - 1, 0 To bm.bmHeight - 1)

GetBitmapBits picShape.Image, bm.bmHeight * bm.bmWidthBytes, longs(0, 0)

For R = 0 To bm.bmHeight - 2

C = 0

Do While C < bm.bmWidth

start_c = 0

stop_c = 0

Do While C < bm.bmWidth

If (longs(C, R) And &HFFFFFF) <> &HFFFFFF Then Exit Do

C = C + 1

Loop

start_c = C

Do While C < bm.bmWidth

If (longs(C, R) And &HFFFFFF) = &HFFFFFF Then Exit Do

C = C + 1

Loop

stop_c = C

If start_c < bm.bmWidth Then

If stop_c >= bm.bmWidth Then stop_c = bm.bmWidth - 1

new_rgn = CreateRectRgn(start_c + x0, R + y0, stop_c + x0, R + y0 + 1)

If combined_rgn = 0 Then

combined_rgn = new_rgn

Else

CombineRgn combined_rgn, combined_rgn, new_rgn, RGN_OR

DeleteObject new_rgn

End If

End If

Loop

Next R

Case Else

MsgBox "对不起,程序必须在 16位, 24-位 或 32-位 颜色下。", _

vbExclamation + vbOKOnly

Exit Sub

End Select

注释: 设置表单外观为建立区域

SetWindowRgn hWnd, combined_rgn, True

DeleteObject combined_rgn

End Sub

Private Sub picShape_Click()

End Sub

Private Sub Form_Load()

Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2

FitToPicture

End Sub

Private Sub picShape_DblClick()

Unload Me

End Sub

Private Sub picshape_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

MoveTrue = True

OldX = x: OldY = y

End Sub

Private Sub picshape_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

If MoveTrue = True Then

Form1.Left = Form1.Left + x - OldX

Form1.Top = Form1.Top + y - OldY

End If

End Sub

Private Sub picshape_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

MoveTrue = False

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有