SetWindowPosDeclare 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 LongConst HWND_TOPMOST = -1 Const SWP_NOMOVE = &H2 Const SWP_NOSIZE = &H1SetWindowPos Me.Hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
调用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 LongPublic 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
Option ExplicitPrivate 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 LongPrivate 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
Option ExplicitPrivate 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 Longsetwindowpos .cwnd,-1,0,0,0,0,3 最好买本书,学习要系统!
'这个函数能为窗口指定一个新位置和状态。它也可改变窗口在内部窗口列表中的位置 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)
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1SetWindowPos Me.Hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
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 LongPublic 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
回复人: Kyle_Chen() ( ) 信誉:100 2003-08-24 22:55:00 得分:0 ※时间竟然一模一样。
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
最好买本书,学习要系统!
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)
End Function