|
-
Apr 29th, 2002, 12:27 PM
#1
Thread Starter
Hyperactive Member
Form With A Hole In It
Over the weekend, I saw this VB program in which one of the forms had a "hole" in it. I mean you could actually see the desktop through this "hole" in the form.
Anyone know how to do that?
-
Apr 29th, 2002, 12:35 PM
#2
-
Apr 29th, 2002, 12:36 PM
#3
Not NoteMe
From www.vbcode.com
VB Code:
'1, Declararion
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) 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 CreateEllipticRgn 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
'2 The Function
Private Function fMakeATranspArea(AreaType As String, pCordinate() As Long) As Boolean
'Name: fMakeATranpArea
'Author: Dalin Nie
'Date: 5/18/98
'Purpose: Create a Transprarent Area in a form so that you can see through
'Input: Areatype : a String indicate what kind of hole shape it would like to make
' PCordinate : the cordinate area needed for create the shape:
' Example: X1, Y1, X2, Y2 for Rectangle
'OutPut: A boolean
Const RGN_DIFF = 4
Dim lOriginalForm As Long
Dim ltheHole As Long
Dim lNewForm As Long
Dim lFwidth As Single
Dim lFHeight As Single
Dim lborder_width As Single
Dim ltitle_height As Single
On Error GoTo Trap
lFwidth = ScaleX(Width, vbTwips, vbPixels)
lFHeight = ScaleY(Height, vbTwips, vbPixels)
lOriginalForm = CreateRectRgn(0, 0, lFwidth, lFHeight)
lborder_width = (lFHeight - ScaleWidth) / 2
ltitle_height = lFHeight - lborder_width - ScaleHeight
Select Case AreaType
Case "Elliptic"
ltheHole = CreateEllipticRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4))
Case "RectAngle"
ltheHole = CreateRectRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4))
Case "RoundRect"
ltheHole = CreateRoundRectRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4), pCordinate(5), pCordinate(6))
Case "Circle"
ltheHole = CreateRoundRectRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4), pCordinate(3), pCordinate(4))
Case Else
MsgBox "Unknown Shape!!"
Exit Function
End Select
lNewForm = CreateRectRgn(0, 0, 0, 0)
CombineRgn lNewForm, lOriginalForm, _
ltheHole, RGN_DIFF
SetWindowRgn hWnd, lNewForm, True
Me.Refresh
fMakeATranspArea = True
Exit Function
Trap:
MsgBox "error Occurred. Error # " & Err.Number & ", " & Err.Description
End Function
' 3'To Call
Dim lParam(1 To 6) As Long
lParam(1) = 100
lParam(2) = 100
lParam(3) = 250
lParam(4) = 250
lParam(5) = 50
lParam(6) = 50
'Call fMakeATranspArea("RoundRect", lParam())
'Call fMakeATranspArea("RectAngle", lParam())
Call fMakeATranspArea("Circle", lParam())
'Call fMakeATranspArea("Elliptic", lParam())
P.S. Looks like you've got an interesting interface in the making, judging by your previous post
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 29th, 2002, 12:37 PM
#4
Not NoteMe
So near, yet so far
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 29th, 2002, 02:21 PM
#5
Nice piece of code SLH...
-
Apr 29th, 2002, 02:29 PM
#6
Thread Starter
Hyperactive Member
Thanks guys!
-
Apr 29th, 2002, 02:51 PM
#7
Here's another piece of code that does it.
VB Code:
Private Declare Function GetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) 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 SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) 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 Const RGN_XOR = 3
Private Sub Form_Load()
Dim hCurRgn As Long
Dim hHoleRgn As Long
Dim hNewRgn As Long
Dim nWidth As Long, nHeight As Long
Dim nSize As Long
nWidth = Me.Width / Screen.TwipsPerPixelX
nHeight = Me.Height / Screen.TwipsPerPixelY
hNewRgn = CreateRectRgn(0, 0, nWidth, nHeight)
hHoleRgn = CreateEllipticRgn(100, 100, 250, 250)
CombineRgn hNewRgn, hNewRgn, hHoleRgn, RGN_XOR
SetWindowRgn hWnd, hNewRgn, True
End Sub
-
Apr 29th, 2002, 06:57 PM
#8
Fanatic Member
Nice code Megatron. But you shouldn't put the code to make the hole in Form_Load, try maximize the form and you'll see what I mean...
Put the code you have in Form_Load in Form_Resize instead and it'll work much better
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Apr 30th, 2002, 09:18 AM
#9
Originally posted by McCain
Nice code Megatron. But you shouldn't put the code to make the hole in Form_Load, try maximize the form and you'll see what I mean...
Put the code you have in Form_Load in Form_Resize instead and it'll work much better
Very good point. I tried Megatron's code yesterday when he posted it (and I like it very much. Much better than the code on the link I posted ) and it worked great, but, I didn't maximize the form when I was running it.
This does work better in Form_Resize!
Thanks McCain.
-
Apr 30th, 2002, 03:13 PM
#10
Oops. Didn't see that.
Although the only problem with putting it in the resize event is that these regions will constantly be created every time the form is resized thereby using up resources.
A couple DestryObjects in there should do the trick though.
-
Apr 30th, 2002, 09:05 PM
#11
Fanatic Member
But how often does the form resize? If it's only when you actually change the size of the form it shouldn't be that bad, should it?
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
May 1st, 2002, 01:36 AM
#12
Not NoteMe
I think the form's resize event gets called WHILE you are resizing it, so it would get called a lot.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 1st, 2002, 03:14 PM
#13
SLH is correct.
And by the way, I made a typo in my previous post. The function name is DeleteObject, not DestroyObject.
-
May 2nd, 2002, 05:36 AM
#14
Addicted Member
How do we make the controls on the form visible even when a hole is punched in the form.
Cute Member 
-
May 2nd, 2002, 07:25 AM
#15
Good Ol' Platypus
Just make sure they are out of the way of the hole (in the region specified). If you want them to be in the middle of the hole, make a rectangular region where you want it to be and OR it with the existing region.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
May 2nd, 2002, 09:18 PM
#16
Fanatic Member
I put this code in just to see how many times form_resize actualy gets called...
VB Code:
Dim intSize As Integer
Private Sub Form_Resize()
intSize = intSize + 1
Me.Caption = intSize
End Sub
If you maximize the form it only gets called once but if you resize it using the mouse it can get called 100+ times... So I guess we do need the DeleteObject...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
May 3rd, 2002, 02:11 AM
#17
Addicted Member
Originally posted by Sastraxi
Just make sure they are out of the way of the hole (in the region specified). If you want them to be in the middle of the hole, make a rectangular region where you want it to be and OR it with the existing region.
That is pretty interesting but how do we actually do it?
-
May 6th, 2002, 11:12 AM
#18
Addicted Member
AttnSue: If I can ask, why you want a form with a hole in it?
Catholics Do It With Beads
-
May 21st, 2002, 08:24 AM
#19
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
|