Results 1 to 6 of 6

Thread: API Help: GetWindowPlacement

  1. #1
    trajik
    Guest

    Question

    I am new to Win32 API programming in Visual Basic and I need help with a specific call. This is the GetWindowPlacement call:

    Declare Function GetWindowPlacement Lib "user32" Alias "GetWindowPlacement" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

    I already understand that I must place in the first argument (target window's handle), but I have no idea what I must put in the second argument. I do know that I must define the WINDOWPLACEMENT type, but I am not sure at all as what to place in the 2nd argument field when calling. Please respond and enlighten me as to what to do. HELP!

  2. #2
    trajik
    Guest

    Talking Thanks!

    Thanks Parksie!

  3. #3
    New Member
    Join Date
    Apr 2006
    Posts
    8

    Re: API Help: GetWindowPlacement

    I am having the very same problem and would like to see the answer too. I can not find a VB.Net GetWindowPlacement method or example. I have looked everwhere and here lies a resolved answer to the same question that is, well, not answered....

    Could someone make this VB.Net friendly or give a .net method that will find the windowstate of a known window? (not my VB.Net application)
    I would like to be able to determine windowstate for a different application.

    ____________________
    Public Declare Function GetWindowPlacement Lib "user32.dll" ( ByVal hwnd As IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Integer

    It is the WINDOWPLACEMENT that VB.Net does not like ....I am not sure why or how to make the type...
    _________________________________

    If there is a different way that would be great too.
    I do not want to actually deal with size(width/hight position etc) just the window state(maximized/minimized/normal) as clean as possible.


    Thank You.

  4. #4
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: API Help: GetWindowPlacement

    Create a structure called WINDOWPLACEMENT:

    VB Code:
    1. 'for vb6
    2. Private Type POINTAPI
    3.         x As Long
    4.         y As Long
    5. End Type
    6.  
    7. Private Type RECT
    8.         Left As Long
    9.         Top As Long
    10.         Right As Long
    11.         Bottom As Long
    12. End Type
    13.  
    14.  
    15. Private Type WINDOWPLACEMENT
    16.         Length As Long
    17.         flags As Long
    18.         showCmd As Long
    19.         ptMinPosition As POINTAPI
    20.         ptMaxPosition As POINTAPI
    21.         rcNormalPosition As RECT
    22. End Type
    23.  
    24. Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
    25.  
    26.  
    27. Private Sub Command1_Click()
    28.     Dim wp As WINDOWPLACEMENT
    29.     wp.Length = Len(wp)
    30.     GetWindowPlacement targetHandle, wp
    31. End Sub

  5. #5
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: API Help: GetWindowPlacement

    for .NET
    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3.     Private Structure POINTAPI
    4.         Public x As Integer
    5.         Public y As Integer
    6.     End Structure
    7.  
    8.     Private Structure RECT
    9.         Public Left As Integer
    10.         Public Top As Integer
    11.         Public Right As Integer
    12.         Public Bottom As Integer
    13.     End Structure
    14.  
    15.  
    16.     Private Structure WINDOWPLACEMENT
    17.         Public Length As Integer
    18.         Public flags As Integer
    19.         Public showCmd As Integer
    20.         Public ptMinPosition As POINTAPI
    21.         Public ptMaxPosition As POINTAPI
    22.         Public rcNormalPosition As RECT
    23.     End Structure
    24.  
    25.     Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
    26.  
    27.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    28.         Dim wp As WINDOWPLACEMENT
    29.         wp.Length = Marshal.SizeOf(wp)
    30.         Dim x As Integer
    31.         x = GetWindowPlacement(&H1075C, wp)
    32.     End Sub
    the window state should be in wp.showCmd

  6. #6
    New Member
    Join Date
    Apr 2006
    Posts
    8

    Re: API Help: GetWindowPlacement

    Excellent. Thank you.
    I am sur this will come in handy for others...

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