Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GetWindowSize() (VB.NET API 2003)

    I'm having trouble using this function. I'm sure the hWnd is being passed correctly and other User32 functions appear to work OK.

    Declaration:<code>
    <DllImport("user32.dll", EntryPoint:="GetWindowSize")> _
    Public Shared Function GetWindowSize(ByVal hWnd As IntPtr) As System.Drawing.Size
    End Function
    </code>
    Function call:<code>
    Dim clsSize As System.Drawing.Size = GetWindowSize(WindowHandle)
    MsgBox("Height is " & Convert.ToString(clsSize.Height())) ' never reaches this point?
    </code>
    Has anybody had success (or trouble) using this API function?

    Alan

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: GetWindowSize() (VB.NET API 2003)

    What are you trying to do, Alan? You can get the form's size directly from the height and width of the form. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Charlotte

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetWindowSize() (VB.NET API 2003)

    It's actually not for a Form belonging to the parent progam - it's for a window owned by another application. Beyond this point, I do need the Height & Width properties for the following function call:
    Dim ptrRet As IntPtr = CreateCompatibleBitmap(hdcFrom, clsSize.Width, clsSize.Height)

    I just can't get it to fire. I suspect it's hanging there, but any other API calls I make using the same hWnd will function OK. I can't seem to find much reference to it at all. I may have to try the old GetWindowRect() Win32 method, returning coordinates to a RECT structure. This VB.NET is more like C++ than it is VB!

    Alan

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: GetWindowSize() (VB.NET API 2003)

    Yes, in many ways it is. Lots more fun than VB too! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: GetWindowSize() (VB.NET API 2003)

    Here's a few we use:

    <code>Private Declare Function GetDesktopWindow Lib "user32.dll" () As IntPtr
    Private Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
    Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Int32</code>

    Called thusly:

    <code> Dim hWndWindowToCapture As IntPtr
    hWndWindowToCapture = GetDesktopWindow()</code>

    There's lots of stuff on the internet for the .Net application of these API calls if you search on the function names
    Charlotte

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetWindowSize() (VB.NET API 2003)

    OK, problem solved using ol' faithful GetWindowRect(). I reckon I was given a bum steer with that GetWindowSize() function. I don't believe it's a legitimate API call - probably some custom function someone confused with the former. Thanks for your help.

    Alan

Posting Permissions

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