飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 3453|回复: 2

[求助]有关SetWindowPos函数

[复制链接]
  • TA的每日心情
    开心
    2025-1-14 20:20
  • 签到天数: 1246 天

    [LV.10]以坛为家III

    发表于 2008-4-14 15:36:53 | 显示全部楼层 |阅读模式
    下面一段代码是用复选框使窗口置顶的。有些问题想问问大家。
    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又代表了什么?
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2008-4-14 19:43:29 | 显示全部楼层
    第2个参数hWndInsertAfter在MSDN里面是这样说的.
    1. hWndInsertAfter
    2.         [in] 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.
    3.                 HWND_BOTTOM
    4.                         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.
    5.                 HWND_NOTOPMOST
    6.                         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.
    7.                 HWND_TOP
    8.                         Places the window at the top of the Z order.
    9.                 HWND_TOPMOST
    10.                         Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.
    复制代码
    在winuser.h里这些常量定义如下:
    1. #define HWND_TOP        ((HWND)0)
    2. #define HWND_BOTTOM     ((HWND)1)
    3. #define HWND_TOPMOST    ((HWND)-1)
    4. #define HWND_NOTOPMOST  ((HWND)-2)
    复制代码
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2025-1-14 20:20
  • 签到天数: 1246 天

    [LV.10]以坛为家III

     楼主| 发表于 2008-4-15 13:32:58 | 显示全部楼层
    #define HWND_TOP        ((HWND)0)
    #define HWND_BOTTOM     ((HWND)1)
    #define HWND_TOPMOST    ((HWND)-1)
    #define HWND_NOTOPMOST  ((HWND)-2)

    原来如此,这是已经定义好的。
    谢谢朋友/:08
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表