This application in VB lets you open, move, resize and focus an application using ::answers(application programming interface,API):: calls. The open is through a Shell call, everything else is in API. As usual, comments form the documentation.
[ASP]
Dim Note As Long
Dim X As Long, Y As Long
Dim intWidth As Long, intHeight As Long
‘Set size
intWidth = 600
intHeight = 400
‘Position Top-Right
X = CInt(Screen.Width / Screen.TwipsPerPixelX – intWidth)
Y = 0
‘For Bottom-Right -> Y = CInt(Screen.Height / Screen.TwipsPerPixelY – intHeight)
‘Get the window
Note = FindWindow(“Notepad”, NOTE_TITLE)
‘If window doesn’t exist, create one
If Note = 0 Then
Shell “Notepad “”C:\odbcconf.log”"”, vbNormalFocus
Note = FindWindow(“Notepad”, NOTE_TITLE)
End If
‘Bring it to top and move/resize as desired
BringWindowToTop Note
MoveWindow Note, X, Y, intWidth, intHeight, 1
[/ASP]
And the declares…
[ASP]
Public Declare Function FindWindow Lib “user32″ Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function BringWindowToTop Lib “user32″ (ByVal hwnd As Long) As Long
Public Declare Function SendMessage Lib “user32″ Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
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
Public Const WM_CLOSE = &H10
Public Const WM_SIZE = &H5
Public Const NOTE_TITLE = “odbcconf.log – Notepad”
[/ASP]
This program has used
MoveWindow
BringWindowToTop
FindWindow
usually, SendMessage also is useful in window manipulation.
