0

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

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
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by JohnTheGrateful
0

Here is some code I use for dual monitors. This may help but is really intended for a user to be able to set their default screen (1 or 2) in a setting and have the form open to the center of the preferred screen.

Dim myScreens() As Screen = Screen.AllScreens

    If (myScreens.Length > 1) Then 'More than one screen        
        Dim PREF_SCREEN As Integer = My.Settings.SCREEN_PREF

        PREF_SCREEN = PREF_SCREEN - 1
        Dim SWIDTH As Integer = myScreens(PREF_SCREEN).WorkingArea.Width
        Dim SHEIGHT As Integer = myScreens(PREF_SCREEN).WorkingArea.Height

        Me.Left = myScreens(PREF_SCREEN).WorkingArea.Left + ((SWIDTH / 2) - Me.Width / 2)
        Me.Top = myScreens(PREF_SCREEN).WorkingArea.Top + ((SHEIGHT / 2) - Me.Height / 2)
    End If

Edited by JohnTheGrateful: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.