Results 1 to 9 of 9

Thread: Get Height of a window

  1. #1

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Get Height of a window

    Friends,

    I just need to print screen the full height of a window that has scroll bar.
    normally getWindowRect only returns the visible portion of the window. not the hidden part. i just want to print screen the full height .

    any advise

  2. #2

  3. #3

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Get Height of a window

    Quote Originally Posted by RhinoBull View Post
    Is it your window or third party?
    RhinoBull, 3rd Party. but it can be any window out there opened in a windows session with a scroll bar. ex. part of windows explore, browser window etc.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Get Height of a window

    Well, you can try doing something as simple as this:
    Code:
    Option Explicit
    
    Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_SHOWWINDOW = &H40
    
    Private Declare Sub SetWindowPos Lib "User32" _
        (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
        ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
    
    Private Sub Command1_Click()
    Dim ret As Long
    Dim wnd As Long
    
        wnd = FindWindow(vbNullString, "My Documents") '<<< I had Windows Explorer sized down
        
        'get actual window size here using GetWindowRect
        'and use values after you're done to restore it original size
        
        SetWindowPos wnd, HWND_NOTOPMOST, 0, 0, _
                     Screen.Width * Screen.TwipsPerPixelX, Screen.Height * Screen.TwipsPerPixelY, _
                     SWP_NOACTIVATE Or SWP_SHOWWINDOW
        
        'do whatever
        
        'restore window to its original size here
    
    End Sub
    However, you may as well want to explore some other api functions like GetWindowPlacement and SetWindowPlacement.

  5. #5

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Get Height of a window

    RhinoBulls

    I am confused with your code



    scren.height and screen.width i dont thik will work in most situation. coz if you take a webpage, that is heigher than the screen

    How to get the full height of this winodw including the hidden part top and bottom?
    coz i want to get a snap shot of the full list.

    BTW, I think if i can get the Scroll height of the window, then also ok. how to do that?
    Last edited by Fazi; Mar 21st, 2009 at 07:52 AM.

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Get Height of a window

    Quote Originally Posted by Fazi View Post
    i dont thik will work in most situation. coz if you take a webpage, that is heigher than the screen

    Actually you can take a snap shot of a web page that is taller then the height of your screen using the webbrowser control..

    http://www.vbforums.com/showpost.php...3&postcount=32
    http://www.vbforums.com/showpost.php...4&postcount=29

    Now if you can do the same with an external app that's something I'd like to see, I have no clue how you'd go about doing that.

  7. #7

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Get Height of a window

    Quote Originally Posted by Edgemeal View Post
    Actually you can take a snap shot of a web page that is taller then the height of your screen using the webbrowser control..

    http://www.vbforums.com/showpost.php...3&postcount=32
    http://www.vbforums.com/showpost.php...4&postcount=29

    Now if you can do the same with an external app that's something I'd like to see, I have no clue how you'd go about doing that.
    yes, already i saw those great codes. but unfortunetly, i need it for what ever the window in what ever the program that have scrollbar

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Get Height of a window

    Fazi, I doubt seriously you will be able to do what you want without manipulating the other window. Using listings for example, many list windows don't try to cache the entire "list" to a DC, because if the list had 1,000s of items in it the bitmap in that DC would be massive in size and probably errors if tried to be created. Most will simply redraw only the items that can be shown on the visible dc.

    So, I think the answer would be to literally scroll the window remotely. Scroll it to the top, take snap shot, scroll it a page, take another snap shot, etc. And after you are done, it would be probably a good idea to set the window back to the original scroll position. I think you'd be able to use SendMessage and fire off some WM_VScroll/WM_HScroll messages. Or maybe use the Get/SetScrollPos APIs?

    Another option, which probably wouldn't please anyone, would be to SetParent the target window (if possible) to the desktop, maximize it, then send scroll messages as mentioned above. The idea, if it works, would be far less screenshots, but obviously much larger screenshots. Of course, you'd have to put it back (SetParent) and resize it to original size once done. Just thinking off the top of my head.
    Last edited by LaVolpe; Mar 21st, 2009 at 04:09 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Get Height of a window

    Quote Originally Posted by LaVolpe View Post
    Fazi, I doubt seriously you will be able to do what you want without manipulating the other window. Using listings for example, many list windows don't try to cache the entire "list" to a DC, because if the list had 1,000s of items in it the bitmap in that DC would be massive in size and probably errors if tried to be created. Most will simply redraw only the items that can be shown on the visible dc.

    So, I think the answer would be to literally scroll the window remotely. Scroll it to the top, take snap shot, scroll it a page, take another snap shot, etc. And after you are done, it would be probably a good idea to set the window back to the original scroll position. I think you'd be able to use SendMessage and fire off some WM_VScroll/WM_HScroll messages. Or maybe use the Get/SetScrollPos APIs?

    Another option, which probably wouldn't please anyone, would be to SetParent the target window (if possible) to the desktop, maximize it, then send scroll messages as mentioned above. The idea, if it works, would be far less screenshots, but obviously much larger screenshots. Of course, you'd have to put it back (SetParent) and resize it to original size once done. Just thinking off the top of my head.

    Thank you

    The first solution is what really in my mind. but i am not sure how decided the amount of scroll on each snap. i think for this we need the total scroll height + top & bottom arrow button height is it? if so , how to get that?

    2nd solution. yah i think this is the solution rino bull also gave it seems.
    first ill try this solution and see how it work

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