'这个函数能为窗口指定一个新位置和状态。它也可改变窗口在内部窗口列表中的位置
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
Public Function SetWindowPos(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
SetWindowPos = wmAPI.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, wFlags)
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 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 Long
Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, ScaleX(Me.Left, vbTwips, vbPixels), ScaleY(Me.Top, vbTwips, vbPixels), _
ScaleX(Me.Width, vbTwips, vbPixels), ScaleY(Me.Height, vbTwips, vbPixels), &H10 Or &H40
End Sub
调用Windows API,代码如下:
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 Long
Public Sub SetWindowTopMost(ByRef frm As Form, Optional ByVal blnTopMost As Boolean = True)
' PURPOSE: Set Window to be Topmost or not topmost
' INPUT:
' frm - a form to be set to (non)topmost
' blnTopMost - TRUE if set to topmost
' NOTE: This function calls an API "SetWindowPos"
'
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const HWND_NOTOPMOST = -2
Const HWND_TOPMOST = -1
Dim lInsertAfter As Long
lInsertAfter = IIf(blnTopMost, HWND_TOPMOST, HWND_NOTOPMOST)
SetWindowPos frm.hWnd, lInsertAfter, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
End Sub
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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