Results 1 to 19 of 19

Thread: Form With A Hole In It

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Connecticut, USA
    Posts
    308

    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?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

  3. #3
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    From www.vbcode.com

    VB Code:
    1. '1, Declararion
    2. 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
    3. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    4. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    5. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    6. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
    7.  
    8. '2  The Function
    9.  
    10.  
    11. Private Function fMakeATranspArea(AreaType As String, pCordinate() As Long) As Boolean
    12.  
    13. 'Name: fMakeATranpArea
    14. 'Author: Dalin Nie
    15. 'Date:   5/18/98
    16. 'Purpose: Create a Transprarent Area in a form so that you can see through
    17. 'Input:  Areatype : a String indicate what kind of hole shape it would like to make
    18. '        PCordinate : the cordinate area needed for create the shape:
    19. '         Example: X1,  Y1, X2, Y2 for Rectangle
    20.  
    21.  
    22. 'OutPut: A boolean
    23.  
    24. Const RGN_DIFF = 4
    25.  
    26. Dim lOriginalForm As Long
    27. Dim ltheHole As Long
    28. Dim lNewForm As Long
    29. Dim lFwidth As Single
    30. Dim lFHeight As Single
    31. Dim lborder_width As Single
    32. Dim ltitle_height As Single
    33.  
    34.  
    35.  On Error GoTo Trap
    36.     lFwidth = ScaleX(Width, vbTwips, vbPixels)
    37.     lFHeight = ScaleY(Height, vbTwips, vbPixels)
    38.     lOriginalForm = CreateRectRgn(0, 0, lFwidth, lFHeight)
    39.    
    40.     lborder_width = (lFHeight - ScaleWidth) / 2
    41.     ltitle_height = lFHeight - lborder_width - ScaleHeight
    42.  
    43. Select Case AreaType
    44.  
    45.     Case "Elliptic"
    46.  
    47.             ltheHole = CreateEllipticRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4))
    48.  
    49.     Case "RectAngle"
    50.    
    51.             ltheHole = CreateRectRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4))
    52.  
    53.      
    54.     Case "RoundRect"
    55.              
    56.                ltheHole = CreateRoundRectRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4), pCordinate(5), pCordinate(6))
    57.  
    58.     Case "Circle"
    59.                ltheHole = CreateRoundRectRgn(pCordinate(1), pCordinate(2), pCordinate(3), pCordinate(4), pCordinate(3), pCordinate(4))
    60.    
    61.     Case Else
    62.            MsgBox "Unknown Shape!!"
    63.            Exit Function
    64.  
    65.        End Select
    66.  
    67.     lNewForm = CreateRectRgn(0, 0, 0, 0)
    68.     CombineRgn lNewForm, lOriginalForm, _
    69.         ltheHole, RGN_DIFF
    70.    
    71.     SetWindowRgn hWnd, lNewForm, True
    72.     Me.Refresh
    73.     fMakeATranspArea = True
    74. Exit Function
    75.  
    76. Trap:
    77.      MsgBox "error Occurred. Error # " & Err.Number & ", " & Err.Description
    78.  
    79.  
    80. End Function
    81.  
    82. ' 3'To Call
    83. Dim lParam(1 To 6) As Long
    84.  
    85. lParam(1) = 100
    86. lParam(2) = 100
    87. lParam(3) = 250
    88. lParam(4) = 250
    89. lParam(5) = 50
    90. lParam(6) = 50
    91.  
    92. 'Call fMakeATranspArea("RoundRect", lParam())
    93. 'Call fMakeATranspArea("RectAngle", lParam())
    94. Call fMakeATranspArea("Circle", lParam())
    95. '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.


  4. #4
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    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.


  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Thumbs up

    Nice piece of code SLH...

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Connecticut, USA
    Posts
    308

    Thumbs up

    Thanks guys!

  7. #7
    Megatron
    Guest
    Here's another piece of code that does it.
    VB Code:
    1. Private Declare Function GetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long) As Long
    2. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    3. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    4. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    5. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    6. Private Const RGN_XOR = 3
    7.  
    8. Private Sub Form_Load()
    9.    
    10.     Dim hCurRgn As Long
    11.     Dim hHoleRgn As Long
    12.     Dim hNewRgn As Long
    13.     Dim nWidth As Long, nHeight As Long
    14.     Dim nSize As Long
    15.  
    16.     nWidth = Me.Width / Screen.TwipsPerPixelX
    17.     nHeight = Me.Height / Screen.TwipsPerPixelY
    18.  
    19.     hNewRgn = CreateRectRgn(0, 0, nWidth, nHeight)
    20.     hHoleRgn = CreateEllipticRgn(100, 100, 250, 250)
    21.     CombineRgn hNewRgn, hNewRgn, hHoleRgn, RGN_XOR
    22.     SetWindowRgn hWnd, hNewRgn, True
    23.    
    24. End Sub

  8. #8
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    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

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  10. #10
    Megatron
    Guest
    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.

  11. #11
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    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

  12. #12
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    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.


  13. #13
    Megatron
    Guest
    SLH is correct.

    And by the way, I made a typo in my previous post. The function name is DeleteObject, not DestroyObject.

  14. #14
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185
    How do we make the controls on the form visible even when a hole is punched in the form.
    Cute Member

  15. #15
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  16. #16
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    I put this code in just to see how many times form_resize actualy gets called...
    VB Code:
    1. Dim intSize As Integer
    2.  
    3. Private Sub Form_Resize()
    4.     intSize = intSize + 1
    5.     Me.Caption = intSize
    6. 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

  17. #17
    Addicted Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    134
    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?
    Pavan Kumar

  18. #18
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    AttnSue: If I can ask, why you want a form with a hole in it?
    Catholics Do It With Beads

  19. #19
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width