Results 1 to 5 of 5

Thread: Moving windows

  1. #1

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'specify the screen position of a window
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    Private Type WINDOWPLACEMENT
            Length As Long
            flags As Long
            showCmd As Long
            ptMinPosition As POINTAPI
            ptMaxPosition As POINTAPI
            rcNormalPosition As RECT
    End Type
    
    Private Declare Function SetWindowPlacement _
    Lib "user32" (ByVal hwnd As Long, _
    lpwndpl As WINDOWPLACEMENT) As Long
    
    Private Declare Function GetWindowPlacement _
    Lib "user32" (ByVal hwnd As Long, lpwndpl As _
    WINDOWPLACEMENT) As Long
    
    Private Declare Function FindWindow Lib _
    "user32" Alias "FindWindowA" (ByVal lpClassName _
    As String, ByVal lpWindowName As String) As Long
    
    Private Declare Function SetRect Lib "user32" _
    (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, _
    ByVal X2 As Long, ByVal Y2 As Long) As Long
    
    '==========================================
    
    Private Sub Command1_Click()
       Dim WndPlace As WINDOWPLACEMENT
       Dim h As Long
        Dim RetVal
        RetVal = Shell("C:\WINDOWS\notepad.exe C:\A VB Tips\alpha only.txt", 1)
        'Shell "Notepad", vbHide
        h = FindWindow("Notepad", vbNullString)
        If h <> 0 Then
            WndPlace.Length = Len(WndPlace)
            Call GetWindowPlacement(h, WndPlace)
            Call SetRect(WndPlace.rcNormalPosition, 0, 3700, WndPlace.rcNormalPosition.Right, 4000)
            Call SetWindowPlacement(h, WndPlace)
        End If
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  2. #2
    New Member
    Join Date
    Feb 2000
    Location
    Canterbury,Kent,UK
    Posts
    8

    Thumbs up just one last thing...

    Cool, works great but....

    I need to centre the window and the maxpos and minpos are set to -1 and the numbers don't relate to screen res co-ordinates (not that i can remember how to find the screen res now) so how can i centre the window? I'd need a window height & width as well as max co-ordinates for the posititioning, ie x = (max.x/2)-(width/2) etc.

    cheers

    Ralph

  3. #3

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Form_Activate()
    'center a screen by code
    'later versions of VB use this
        'Form1.StartUpPosition = 2
        
        Form1.Top = (Screen.Height / 2) - (Form1.Height / 2)
        Form1.Left = (Screen.Width / 2) - (Form1.Width / 2)
    
    End Sub
    "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
    New Member
    Join Date
    May 2000
    Posts
    13

    Wink I think it's easy!

    You can use MoveWindow or SetWindowPos API to make it.
    And you can found some examples in <a href=http://vbapi.com/ref/>vbapi</a>
    I expect it will help you!
    Very glad to see you !
    I'm a very begginer!

  5. #5
    New Member
    Join Date
    Feb 2000
    Location
    Canterbury,Kent,UK
    Posts
    8

    Thumbs down

    No... make the notepad (or whatever) window center... centring a form's no problem... I'm not that bad!

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