Results 1 to 10 of 10

Thread: How do I get the size of a Window?

  1. #1
    Guest

    Smile

    Does anyone know how I can get the width and height of a form without using.

    form1.width & form1.height

    The reason I ask is that form1.width and form1.height dont actually include the border of the window and the title bar.

    What I need is the size of the window including title bars and borders. I suspect I will need to use API.

    Any expects?

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Try it by using the GetWindowRect API function.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    ...good site for API Functions
    http://www.vbapi.com/ref/funca.html
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    just another idea , but I dont have code for it

    take a screen shot of the form and get the
    Height and width . Im sure theres an easier way though .

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Originally posted by PRIVATE1
    just another idea , but I dont have code for it

    take a screen shot of the form and get the
    Height and width . Im sure theres an easier way though .
    That doesn't helps, because your program isn't resolution independent that way and the user can also change the size of the titlebar.

  6. #6
    Guest
    Try this:
    Code:
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    Private Sub Command1_Click()
    
        Dim rRect As RECT
        GetWindowRect hwnd, rRect
        
        Print rRect.Right - rRect.Left  'Width
        Print rRect.Bottom - rRect.Top  'Height
        
    End Sub

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Megatron
    what is the rec width and height expressed as compared to
    the form.width and form.height.
    Rec vs Form
    320 vs 4800
    240 vs 3600

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    Guest
    Pixels.

  9. #9
    Guest
    If you checked the example and the numbers did not match (even when you set the ScaleMode to pixels) it's because VB's ScaleMode property displays the dimensions of the client area. You can get these numbers too by using the GetClientRect API.
    Code:
    Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    Private Sub Command1_Click()
    
        Dim rRect As RECT
        GetClientRect hwnd, rRect
        
        Print rRect.Right - rRect.Left  'Width
        Print rRect.Bottom - rRect.Top  'Height
        
    End Sub

  10. #10
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    Question

    Is there an API to get the thickness of the borders in Pixels?

    Or do you just have to do it the long way by taking the results of GetWindowRect and subtract GetClientRect?
    Chemically Formulated As:
    Dr. Nitro

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