Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSet another application's size and position in Visual Basic 2008
DescriptionThis example shows how to set another application's size and position in Visual Basic 2008. This example uses FindWindow to find the other application's handle and then uses SetWindowPos to size and position the application.
KeywordsSetWindowPos, FindWindow, set application size, set application position, VB.NET
CategoriesAPI, Software Engineering
 
(While writing books, there is a maximum size that an image should be. I wrote this program to make it easy to set an example program to exactly that size.)

The program uses FindWindow to find the target application's handle. Unfortunately this means that you must type the target application's form caption exactly.

After finding the target's handle, the program passes it to the SetWindowPos API function to set the target's size and position.

 
Imports System.Runtime.InteropServices

Public Class Form1
    Public Const SWP_NOSIZE As Int32 = &H1
    Public Const SWP_NOMOVE As Int32 = &H2

    Public Declare Function SetWindowPos Lib "user32.dll" _
        (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As _
        IntPtr, ByVal X As Int32, ByVal Y As Int32, ByVal _
        cx As Int32, ByVal cy As Int32, ByVal uFlags As _
        Int32) As Boolean
    Private Declare Auto Function FindWindow Lib "user32" _
        (ByVal lpClassName As String, ByVal lpWindowName As _
        String) As IntPtr

    Private Sub btnGo_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnGo.Click
        Dim target_hwnd As Long = FindWindow(vbNullString, _
            txtAppName.Text)
        Dim x As Int32 = Val(txtXmin.Text)
        Dim y As Int32 = Val(txtYmin.Text)
        Dim cx As Int32 = Val(txtWidth.Text)
        Dim cy As Int32 = Val(txtHeight.Text)
        SetWindowPos(target_hwnd, 0, x, y, cx, cy, 0)
    End Sub
End Class
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated