Results 1 to 6 of 6

Thread: [Resolved]Getting the active window Co-ords

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    [Resolved]Getting the active window Co-ords

    Thanks for those who help with the key-press before!

    I've come to another problem in creating that screen shot application.

    I have an option that either takes a picture of the entire screen, or of the focused window.

    Now, this wouldn't be a problem if i got the screen shot from using the kb_event API call. But i need the Clipboard to stay intact and unchanged, so i use a different way of getting the screen shot:

    VB Code:
    1. Public xpos As Long
    2. Public ypos As Long
    3. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    4. Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    5.  
    6. Private Sub Command1_Click()
    7. Dim wScreen As Long
    8. Dim hScreen As Long
    9. Dim w As Long
    10. Dim h As Long
    11. Picture1.Cls
    12. wScreen = Screen.Width \ Screen.TwipsPerPixelX
    13. hScreen = Screen.Height \ Screen.TwipsPerPixelY
    14. Picture1.ScaleMode = vbPixels
    15. 'w = Picture1.ScaleWidth
    16. 'h = Picture1.ScaleHeight
    17. w = Screen.Width / Screen.TwipsPerPixelX
    18. h = Screen.Height / Screen.TwipsPerPixelY
    19. hdcScreen = GetDC(0)
    20. r = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)
    21. End Sub

    I know about using the StretchBlt API call to manipulate the picture box.
    The part that i'm missing is how to get the active window's top, left, width and height to set the picture. So in other words, it takes the entire screen & cuts off the bit that doesn't belong to the focused window. Is there any way to do this?
    Last edited by Slyke; Aug 16th, 2006 at 12:35 PM.

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