|
-
Sep 5th, 2001, 04:34 AM
#1
Thread Starter
Junior Member
how do you store a window region in memory for later use?
Hi,
I am using 2 functions to make forms of irregular shapes which I would like to animate(sort of MS Office Assistant). I got it working in two ways with code I found in vbforums. The problem is that they are too slow and the animation is not in "real time". I was wondering if there is a way to store "Window Regions" in memory so they all get made in advance behind a splash screen at the begining and then I can just display them when I need them.
this function uses draw.dll 's BitmaptoRegion which many of you might be familiar with
Private Sub Make_Transparent(frm As Form, pic As Picture)
'BitmapToRegion
'hBmp -> bitmap to convert to region
'cTransparentColor -> Transparent color
'cTolerance -> Tolerance
'This function returns a region
Dim mRGN As Long
If bRegion = False Then
mRGN = BitmapToRegion(frm.Picture, RGB(192, 192, 192), 0)
'OffsetRgn mRGN, 0, 0 'used for the border
Else
mRGN = CreateRectRgn(0, 0, pic.Width, pic.Height)
End If
frm.Picture = pic
SetWindowRgn frm.hwnd, mRGN, True
DeleteObject mRGN
bRegion = Not (bRegion)
End Sub
This is another different function that has the same effect and it uses a few api calls
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y 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
Declare Sub ReleaseCapture Lib "user32" ()
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Function AutoFormShape(bg As Form, transColor)
Dim X, Y As Integer
CurRgn = CreateRectRgn(0, 0, bg.ScaleWidth, bg.ScaleHeight) ' Create base region which is the current whole window
While Y <= bg.ScaleHeight ' Go through each column of pixels on form
While X <= bg.ScaleWidth ' Go through each line of pixels on form
If GetPixel(bg.hdc, X, Y) = transColor Then ' If the pixels color is the transparency color (bright purple is a good one to use)
TempRgn = CreateRectRgn(X, Y, X + 1, Y + 1) ' Create a temporary pixel region for this pixel
success = CombineRgn(CurRgn, CurRgn, TempRgn, RGN_DIFF) ' Combine temp pixel region with base region using RGN_DIFF to extract the pixel and make it transparent
DeleteObject (TempRgn) ' Delete the temporary pixel region and clear up very important resources
End If
X = X + 1
Wend
Y = Y + 1
X = 0
Wend
success = SetWindowRgn(bg.hwnd, CurRgn, True) ' Finally set the windows region to the final product
DeleteObject (CurRgn) ' Delete the now un-needed base region and free resources
End Function
I am sorry if this is an obvious question but I am new to VB and Windows programming.
Thank you
Why did I ever start learning VB?! I should have been happy with Java. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|