[求助]有关SetWindowPos函数
下面一段代码是用复选框使窗口置顶的。有些问题想问问大家。Const HWND_TOPMOST = -1
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 Check1_Click()
Dim lngWindowFront As Long
If Check1.Value = 1 Then '窗口置前
lngWindowFront = SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, 3)
If lngWindowFront = 0 Then
MsgBox "设置失败!", vbInformation, "友情提示"
Else
MsgBox "设置成功!", vbInformation, "友情提示"
End If
Else
lngWindowFront = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
If lngWindowFront = 0 Then
MsgBox "设置失败!", vbInformation, "友情提示"
Else
MsgBox "设置成功!", vbInformation, "友情提示"
End If
End If
End Sub
Const HWND_TOPMOST = -1
为什么要在这里声明常量HWND_TOPMOST = -1呢?
它不是hWndInsertAfter中的值吗?
lngWindowFront = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
而这个-2又代表了什么? 第2个参数hWndInsertAfter在MSDN里面是这样说的.hWndInsertAfter
A handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values.
HWND_BOTTOM
Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows.
HWND_NOTOPMOST
Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window.
HWND_TOP
Places the window at the top of the Z order.
HWND_TOPMOST
Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.在winuser.h里这些常量定义如下:#define HWND_TOP ((HWND)0)
#define HWND_BOTTOM ((HWND)1)
#define HWND_TOPMOST ((HWND)-1)
#define HWND_NOTOPMOST((HWND)-2) #define HWND_TOP ((HWND)0)
#define HWND_BOTTOM ((HWND)1)
#define HWND_TOPMOST ((HWND)-1)
#define HWND_NOTOPMOST((HWND)-2)
原来如此,这是已经定义好的。
谢谢朋友/:08
页:
[1]