PDA

Click to See Complete Forum and Search --> : A good code Just not work[solved]


WindowsNuclear
Oct 12th, 2002, 04:49 AM
'This methode Can use a backgroud picture, to form the from
'as the picture's figure.
'Just assigned a color from all colors of the picture as the "transparence" color,just as 'gif dose.

'Declaration
Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Public Const RGN_OR = 2
Public 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

Dim bmbyte() As Byte

Public Sub SetAutoRgn(hfrom As Form, Optional TransColor As Byte = vbNull)
Dim x As Long, y As Long
Dim rgn1 As Long, rgn2 As Long
Dim spos As Long, epos As Long
Dim bm As BITMAP
Dim hbm As Long
Dim wid As Long, hgt As Long

'get the size of the backgroud picture
hbm = hform.Picture
GetObject hbm, Len(bm), bm
wid = bm.bmWidth
hgt = bm.bmHeight

hform.Height = hgt * Screen.TwipsPerPixelY
hform.Width = wid * Screen.TwipsPerPixelX

ReDim bmbyte(1 To wid, 1 To hgt)
'get arrays of picture's pelses
GetBitmapBits hbm, wid * hgt, bmbyte(1, 1)
If TransColor = vbNull Then TransColor = bmbyte(1, 1)
rgn1 = CreateRectRgn(0, 0, 0, 0)

For y = 1 To hgt
x = 0
Do
x = x + 1

While (bmbyte(x, y) = TransColor) And (x < wid)
x = x + 1
Wend
spos = x


While (bmbyte(x, y) <> TransColor) And (x < wid)
x = x + 1
Wend
epos = x - 1

If spos <= epos Then
rgn2 = CreateRectRgn(spos - 1, y - 1, epos, y)
CombineRgn rgn1, rgn1, rgn2, RGN_OR
DeleteObject rgn2
End If
Loop Until x >= wid
Next y


SetWindowRgn hform.hWnd, rgn1, True
DeleteObject rgn1

End Sub


' The code's author is the host of WWW.ARCHTIDE.COM, but this
'function cause error in my
'Program.Can anybody know what's wrong with it?THS

Machaira
Oct 12th, 2002, 09:45 AM
Maybe if you told us what the error is and where it occurs, we'll be better able to help you.

WindowsNuclear
Oct 12th, 2002, 11:43 PM
The error occurs when I use the SetAutoRgn(),It simplely say Just not support the form variable.
I didn't know What's wrong with it.
So, I give up the function,Use the Part as a nomal code,It just can't recongnize the Byte Type.
I was confused with it.

Can anybody Knows what's wrong with it?Thanks.

mlewis
Oct 14th, 2002, 07:50 AM
Try replacing Byte with Integer first. If that doesn't work, try using the code from here instead:

http://www.piqsoftware.com/projects/apochfaq/VBfaq/coolfx.htm#shapes


This will take a bitmap and use yellow (which can be changed) as the transparency color. You can use it on anything with an hWnd.


Hope that works better for you :)

Peter1
Oct 14th, 2002, 01:31 PM
This project does the same thing. Uses the first pixel of the pic as the transparency colour.

Pete

WindowsNuclear
Oct 16th, 2002, 11:04 PM
:)Thanks for help.

It's lucky I got to the right place.

WindowsNuclear
Oct 29th, 2002, 03:48 AM
HaHa, a success!