当前位置:首页 » 程序代码 » 正文

VB编程:设置窗体置顶 和 取消窗体置顶

VB窗体置顶,这个功能当然还是要靠万能的API来帮忙,先在窗体模块输入以下代码:
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
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 Command1_Click()
    SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE     '设置窗口置顶
End Sub

Private Sub Command2_Click()
    SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE    '取消窗口置顶
End Sub

打赏 支付宝打赏 微信打赏

来源:济亨网

本文链接:https://wb98.com/post/24.html

VB代码  API  
    << 上一篇 下一篇 >>

    湘公网安备 43011102000514号 - 湘ICP备08100508号