-
<?>
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
-
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
-
<?>
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
-
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!
-
No... make the notepad (or whatever) window center... centring a form's no problem... I'm not that bad! :)