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?
Printable View
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?
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 :)
So near, yet so far :)
Nice piece of code SLH...
Thanks guys! :D
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
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 :D) and it worked great, but, I didn't maximize the form when I was running it.Quote:
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
This does work better in Form_Resize!
Thanks McCain. :)
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.
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?
I think the form's resize event gets called WHILE you are resizing it, so it would get called a lot.
SLH is correct.
And by the way, I made a typo in my previous post. The function name is DeleteObject, not DestroyObject.
How do we make the controls on the form visible even when a hole is punched in the form.
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.
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...
That is pretty interesting but how do we actually do it?Quote:
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.
AttnSue: If I can ask, why you want a form with a hole in it?
Thanks.