Results 1 to 3 of 3

Thread: Capture Screen behind a form (Resolved)

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Capture Screen behind a form (Resolved)

    I'm trying to capture as piece of the screen behind my form.
    Then the captured pic is placed on my form so that it looks 'see through'.

    I don't mind moving or hiding the form, but it's not working right.

    Steps:
    1. capturer a piece of screen to picBack.
    2. Copy it to picText then print text over it.
    3. Alpha Blend the two pics to picBlend.
    4. Copy the blended pic to the form.

    All picture boxes and the form are set to AutoRedraw.

    The code is called from a loop so that the background gets updated.

    My code sort of works.
    If I F8(one-step) until the form is hidden or moved, it works fine.
    Here's a pic of how it should go.

    Good capture pic:

    Notice that picBack only shows the screen behind the top left corner of the form.


    But when I let the program run at full speed it starts capturing an image of that section of my form.
    Bad capture pic.


    Here's some of my code.
    The commented lines are some of the things I've tried, like moving my form or setting a delay to let the form hide before the capture is made.

    VB Code:
    1. Me.Visible = False
    2. Stop 'it works in the IDE if I leave this 'Stop' and use F8
    3.      'It fails it I remove the 'Stop'
    4.      
    5. '    Do While Me.Visible
    6. '        Sleep (10)
    7. '    Loop
    8.     Me.Move m_tTruePos.Y, m_tTruePos.X 'The postion seen in the screen shots
    9.  
    10. ' Here I tried temp moving the form out of the way
    11. '    lTop = Me.Top
    12. '    lLeft = Me.Left
    13. '    Me.Move g_tScreenSize.Y, g_tScreenSize.X 'move the form off screen
    14. ''    Me.Refresh
    15. '    Sleep 500 ' give a little time for the screen to clear
    16.     ScreenCapture picBack, Me.Top / 15, Me.Left / 15, picText.Height, picText.Width
    17. '    ScreenCapture picBack, lTop / 15, lLeft / 15, picText.Height, picText.Width
    18. '    Me.Move m_tTruePos.Y, m_tTruePos.X
    19. Me.Visible = True
    20.     Me.Picture = picBack.Picture
    21.     picText.Picture = picBack.Image
    22.     '......
    23.  
    24.  
    25.  
    26.  
    27. Public Sub ScreenCapture(PicObj As Object, lTop As Long, lLeft As Long, lHeight As Long, lWidth As Long)
    28. 'Captures part of desktop
    29. '   PicObj: Any object type that has a DC and can hold a picture
    30.     Dim lDeskhWnd As Long
    31.     Dim lDeskDC As Long
    32.     Dim lForeHwnd As Long
    33.    
    34.     'These didn't help
    35.     'lForeHwnd = GetForegroundWindow
    36.     'SysSetFocus (lForeHwnd)
    37.    
    38.     lDeskhWnd = GetDesktopWindow()
    39.     lDeskDC = GetDC(lDeskhWnd&)
    40.     PicObj.Cls
    41.     PicObj.Picture = Nothing
    42.     PicObj.Width = lWidth
    43.     PicObj.Height = lHeight
    44.    
    45.     BitBlt PicObj.hdc, 0&, 0&, lWidth, lHeight, lDeskDC, lLeft, lTop, SRCCOPY
    46.     ReleaseDC lDeskhWnd, lDeskDC
    47.     PicObj.Picture = PicObj.Image
    48. End Sub
    Attached Images Attached Images   
    Last edited by longwolf; May 12th, 2005 at 05:09 PM. Reason: Resolved

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Capture Screen behind a form

    Simply try and replace your Stop call with a DoEvents call.

  3. #3

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Capture Screen behind a form

    Dugh!
    I'm not sure if I should feel stupid or relieved

    It's working
    Thx Joacim

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