Results 1 to 5 of 5

Thread: using MoveWindow() just hides window comlpetely

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    18

    Exclamation using MoveWindow() just hides window comlpetely

    Hi

    Im trying to position a window with MoveWindow() API but it just keeps hiding the window and it has to be maximised to be able to see it.

    The code im using is

    Code:
    Public Declare Function MoveWindow Lib "user32" _
            (ByVal hwnd As Long, _
            ByVal x As Long, _
            ByVal y As Long, _
            ByVal nWidth As Long, _
            ByVal nHeight As Long, _
            ByVal bRepaint As Long) _
            As Long
    
    
    
            Dim p As System.Diagnostics.Process
    
            For Each p In System.Diagnostics.Process.GetProcesses()
    
                If p.MainWindowTitle = "MyProcess" Then
                      GetWindowRect(p.MainWindowHandle, r)
                    MsgBox("Left" & r.Left & vbNewLine & _
                     "Top" & r.Top & vbNewLine & _
                     "Bottom" & r.Bottom & vbNewLine & _
                     "Right" & r.Right)
    
                    Call MoveWindow(p.MainWindowHandle, 110, 59, 1270, 957,False)
    
                   Close()
                End If
    
    
    
            Next

    i have tried with all different co-orindates and sixes and its always the same.

    any help is appreciated

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: using MoveWindow() just hides window comlpetely

    try this instead:

    vb Code:
    1. Const SWP_NOSIZE As Integer = &H1
    2. Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As IntPtr, _
    3. ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal _
    4. cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    vb Code:
    1. Dim xPosition As Integer = 50
    2. Dim yPosition As Integer = 50
    3. SetWindowPos(Me.Handle, -1, xPosition, yPosition, 0, 0, SWP_NOSIZE)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: using MoveWindow() just hides window comlpetely

    or if you want to use movewindow, this is the vb.net declaration:

    vb Code:
    1. Public Declare Function MoveWindow Lib "user32" _
    2.         (ByVal hwnd As intptr, _
    3.         ByVal x As integer, _
    4.         ByVal y As integer, _
    5.         ByVal nWidth As integer, _
    6.         ByVal nHeight As integer, _
    7.         ByVal bRepaint As integer) _
    8.         As integer

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    18

    Re: using MoveWindow() just hides window comlpetely

    Quote Originally Posted by .paul. View Post
    try this instead:

    vb Code:
    1. Const SWP_NOSIZE As Integer = &H1
    2. Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As IntPtr, _
    3. ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal _
    4. cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    vb Code:
    1. Dim xPosition As Integer = 50
    2. Dim yPosition As Integer = 50
    3. SetWindowPos(Me.Handle, -1, xPosition, yPosition, 0, 0, SWP_NOSIZE)
    Thanks Paul,

    That sorted it. Ideal

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: using MoveWindow() just hides window comlpetely

    Don't forget to mark your thread!

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