Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Option ExplicitPrivate Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongConst HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Const SWP_NOACTIVATE = &H10 Const SWP_SHOWWINDOW = &H40Private Sub Form_Load() Dim hWnd As Long hWnd = FindWindow(vbNullString, "计算器") SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Option ExplicitPrivate Declare Function MoveWindow Lib "user32.dll" (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 Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As LongPrivate Type RECT Left As Long Top As Long Right As Long Bottom As Long End TypePrivate Sub Command1_Click() Dim h As Long, rt As RECT, ret As Long, calcWidth As Long, calcHeight As Long Shell "calc.exe" h = FindWindow("SciCalc", vbNullString) ret = GetWindowRect(h, rt) calcWidth = rt.Right - rt.Left calcHeight = rt.Bottom - rt.Top ret = MoveWindow(h, (Screen.Width / Screen.TwipsPerPixelX - calcWidth) / 2, (Screen.Height / Screen.TwipsPerPixelY - calcHeight) / 2, calcWidth, calcHeight, True)End Sub
Private Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongConst HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40Private Sub Form_Load()
Dim hWnd As Long
hWnd = FindWindow(vbNullString, "计算器")
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As LongPrivate Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Sub Command1_Click()
Dim h As Long, rt As RECT, ret As Long, calcWidth As Long, calcHeight As Long Shell "calc.exe"
h = FindWindow("SciCalc", vbNullString)
ret = GetWindowRect(h, rt)
calcWidth = rt.Right - rt.Left
calcHeight = rt.Bottom - rt.Top
ret = MoveWindow(h, (Screen.Width / Screen.TwipsPerPixelX - calcWidth) / 2, (Screen.Height / Screen.TwipsPerPixelY - calcHeight) / 2, calcWidth, calcHeight, True)End Sub